📄 usermanager.cpp
字号:
#include "StdAfx.h"
#include ".\usermanager.h"
#include "User.h"
#include "GuidUserList.h"
#include "CharNameUserList.h"
#include <string>
#include <assert.h>
// 模备 困秦
#include <struct.h>
UserManager::UserManager(void)
{
m_pGuidUserList = new GuidUserList;
m_pCharGuidList = new GuidUserList;
m_pCharNameUserList = new CharNameUserList;
m_mapUserFriend.clear();
}
UserManager::~UserManager(void)
{
SAFE_DELETE( m_pGuidUserList );
SAFE_DELETE( m_pCharGuidList );
SAFE_DELETE( m_pCharNameUserList );
FRIEND_USER_MAP_ITER iter;
while( !m_mapUserFriend.empty() )
{
iter = m_mapUserFriend.begin();
(*iter).second.clear();
m_mapUserFriend.erase(iter);
}
m_mapUserFriend.clear();
}
VOID UserManager::Init()
{
m_pGuidUserList->Init();
m_pCharGuidList->Init();
m_pCharNameUserList->Init();
m_mapUserFriend.clear();
}
VOID UserManager::Release()
{
m_pGuidUserList->Release();
m_pCharGuidList->Release();
m_pCharNameUserList->Release();
FRIEND_USER_MAP_ITER iter;
while( !m_mapUserFriend.empty() )
{
iter = m_mapUserFriend.begin();
(*iter).second.clear();
m_mapUserFriend.erase(iter);
}
m_mapUserFriend.clear();
}
// FriendCharGuid甫 模备肺 瘤沥茄 pUser 沥焊 眠啊
BOOL UserManager::AddNewFriend( DWORD FriendCharGuid, User* pUser )
{
// 捞 荤侩磊狼 模备甸 格废 眠啊
FRIEND_USER_MAP_ITER iter;
FRIEND_ATOM_MAP mapFriendAtom;
// 模备啊 甸绢坷搁 官肺 单捞磐 掘阑 荐 乐档废 郴 模备 沥焊甫 殿废茄促
iter = m_mapUserFriend.find( FriendCharGuid );
if( iter != m_mapUserFriend.end() )
{
// 单捞磐 乐栏搁 弊 第俊 眠啊
(*iter).second.insert( FRIEND_ATOM_MAP_PAIR( pUser->GetCharGuid(), pUser ) );
}
else
{
// 单捞磐 绝栏搁 货肺 父甸绢 持绰促
mapFriendAtom.insert( FRIEND_ATOM_MAP_PAIR( pUser->GetCharGuid(), pUser ) );
m_mapUserFriend.insert( FRIEND_USER_MAP_PAIR( FriendCharGuid, mapFriendAtom ) );
}
// 捞 模备啊 柯扼牢捞扼搁 模备 牢胶畔胶俊 '郴啊 呈甫 模备 冈菌促!'绊 历厘矫挪促
// 捞饶 pFriend啊 肺弊酒眶窍搁 pUser啊 舅 荐 乐促
User* pFriend = FindUserByCharGuid( FriendCharGuid );
if( pFriend )
{
// 捞 模备啊 唱甫 瞒窜沁促搁 舅妨林瘤 臼绰促
if( !pFriend->FindBlock( pUser->GetCharGuid() ) )
{
pFriend->AddOnlineFriend( pUser );
}
}
// MessageOut( eFULL_LOG, "[%s] AddNewFriend(%u)", pUser->GetCharName().c_str(), FriendCharGuid );
return TRUE;
}
BOOL UserManager::AddFriend( User* pUser )
{
// 捞 荤侩磊狼 模备甸 格废 眠啊
STRUCT_FRIEND_INFO* pFriend = pUser->GetFirstFriend();
FRIEND_USER_MAP_ITER iter;
FRIEND_ATOM_MAP mapFriendAtom;
// 模备啊 甸绢坷搁 官肺 单捞磐 掘阑 荐 乐档废 郴 模备 沥焊甫 殿废茄促
if( pFriend )
{
do
{
iter = m_mapUserFriend.find( pFriend->dwFriendGuid );
if( iter != m_mapUserFriend.end() )
{
// 单捞磐 乐栏搁 弊 第俊 眠啊
(*iter).second.insert( FRIEND_ATOM_MAP_PAIR( pUser->GetCharGuid(), pUser ) );
}
else
{
// 单捞磐 绝栏搁 货肺 父甸绢 持绰促
mapFriendAtom.insert( FRIEND_ATOM_MAP_PAIR( pUser->GetCharGuid(), pUser ) );
m_mapUserFriend.insert( FRIEND_USER_MAP_PAIR( pFriend->dwFriendGuid, mapFriendAtom ) );
}
}while( pFriend = pUser->GetNextFriend() );
}
// 捞固 殿废等 沥焊甸 吝俊 唱甫 殿废茄 沥焊啊 乐栏搁 持绢霖促
iter = m_mapUserFriend.find( pUser->GetCharGuid() );
if( iter != m_mapUserFriend.end() )
{
// 乐栏搁 捞吧 蜡历俊霸 殿废
FRIEND_ATOM_MAP_ITER iterAtom;
if( !(*iter).second.empty() )
{
for( iterAtom = (*iter).second.begin(); iterAtom != (*iter).second.end(); iterAtom++ )
{
// 郴啊 捞 蜡历甫 瞒窜沁促搁 舅妨林瘤 臼绰促
if( !pUser->FindBlock( (*iterAtom).second->GetCharGuid() ) )
{
pUser->AddOnlineFriend( (*iterAtom).second );
}
}
}
}
// MessageOut( eFULL_LOG, "[%s] AddFriend Complete", pUser->GetCharName().c_str() );
return TRUE;
}
VOID UserManager::RemoveNewFriend( DWORD FriendCharGuid, User *pUser )
{
FRIEND_USER_MAP_ITER iter;
FRIEND_ATOM_MAP_ITER iterAtom;
// 模备 格废 单捞磐俊辑 捞 荤侩磊狼 模备甸阑 茫绰促
iter = m_mapUserFriend.find( FriendCharGuid );
if( iter != m_mapUserFriend.end() )
{
// 单捞磐 乐栏搁
iterAtom = (*iter).second.find( pUser->GetCharGuid() );
if( iterAtom != (*iter).second.end() )
{
// 捞仇阑 模备 伙篮 唱狼 单捞磐档 乐栏搁 瘤况霖促!
(*iter).second.erase( iterAtom );
// 瘤快绊 车歹聪 甘捞 厚菌栏搁 甘档 瘤况霖促!
if( (*iter).second.empty() )
{
m_mapUserFriend.erase( iter );
}
}
else
{
// 单捞磐 绝栏搁 滚弊
MessageOut( eCRITICAL_LOG, "[%s] RemoveNewFriend Error - No Data[CharGuid:%u]", pUser->GetCharName().c_str(), FriendCharGuid );
return;
}
}
else
{
// 单捞磐 绝栏搁 滚弊
MessageOut( eCRITICAL_LOG, "[%s] RemoveNewFriend Error - No Data[CharGuid:%u]", pUser->GetCharName().c_str(), FriendCharGuid );
return;
}
// 捞 模备啊 柯扼牢捞扼搁 捞率俊辑档 单捞磐 瘤况 拎具 茄促
User* pFriend = FindUserByCharGuid( FriendCharGuid );
if( pFriend )
{
pFriend->RemoveOnlineFriend( pUser );
}
// MessageOut( eFULL_LOG, "[%s] RemoveNewFriend(%u)", pUser->GetCharName().c_str(), FriendCharGuid );
}
// 模备 格废 诀单捞飘 - 模备 力芭!!
VOID UserManager::RemoveFriend( User *pUser )
{
// 捞 荤侩磊狼 模备甸 沥焊甫 力芭茄促
STRUCT_FRIEND_INFO* pFriend = pUser->GetFirstFriend();
FRIEND_USER_MAP_ITER iter;
FRIEND_ATOM_MAP_ITER iterAtom;
// 模备 格废 单捞磐俊辑 捞 荤侩磊狼 模备甸阑 茫绰促
if( pFriend )
{
do
{
// 模备 沥焊 乐衬?
iter = m_mapUserFriend.find( pFriend->dwFriendGuid );
if( iter != m_mapUserFriend.end() )
{
// 单捞磐 乐栏搁
iterAtom = (*iter).second.find( pUser->GetCharGuid() );
if( iterAtom != (*iter).second.end() )
{
// 捞仇阑 模备 伙篮 唱狼 单捞磐档 乐栏搁 瘤况霖促!
(*iter).second.erase( iterAtom );
// 瘤快绊 车歹聪 甘捞 厚菌栏搁 甘档 瘤况霖促!
if( (*iter).second.empty() )
{
m_mapUserFriend.erase( iter );
}
}
else
{
// 单捞磐 绝栏搁 滚弊
MessageOut( eCRITICAL_LOG, "[%s] RemoveFriend Error - No %s FriendAtomTable", pUser->GetCharName().c_str(), pFriend->sPacketInfo.ptszFriendName );
}
}
else
{
// 单捞磐 绝栏搁 滚弊
MessageOut( eCRITICAL_LOG, "[%s] RemoveFriend Error - No %s FriendTable", pUser->GetCharName().c_str(), pFriend->sPacketInfo.ptszFriendName );
continue;
}
}while( pFriend = pUser->GetNextFriend() );
}
// User啊 昏力登搁辑 OnlineFriend 沥焊档 鞍捞 昏力登骨肺 被捞 捞 User 努贰胶俊 乐绰 m_mapOnlineFriend甫 昏力且 鞘夸绰 绝促
// MessageOut( eFULL_LOG, "[%s] RemoveFriend Complete", pUser->GetCharName().c_str() );
}
VOID UserManager::AddUser( DWORD dwGuid, User *pUser )
{
m_pGuidUserList->Add( dwGuid, pUser );
// 某腐磐 捞抚捞 乐栏搁 CharNameUserList俊档 眠啊
if( !pUser->GetCharName().empty() )
{
m_pCharNameUserList->Add( pUser->GetCharName(), pUser );
}
// 某腐磐 guid 乐栏搁 咯扁档 眠啊
if( pUser->GetCharGuid() )
{
m_pCharGuidList->Add( pUser->GetCharGuid(), pUser );
}
}
VOID UserManager::RemoveUser( DWORD dwGuid )
{
User *pUser = m_pGuidUserList->Find( dwGuid );
if( pUser )
{
m_pGuidUserList->Remove( dwGuid );
// 某腐磐 捞抚捞 乐栏搁 CharNameUserList俊辑档 昏力
if( !pUser->GetCharName().empty() )
{
m_pCharNameUserList->Remove( pUser->GetCharName() );
}
if( pUser->GetCharGuid() )
{
m_pCharGuidList->Remove( pUser->GetCharGuid() );
}
}
}
BOOL UserManager::SetUserCharGuid( DWORD dwGuid, DWORD dwCharGuid )
{
User *pUser = m_pGuidUserList->Find( dwGuid );
if( !pUser )
return FALSE;
// 捞固 CharGuid府胶飘俊 乐绰 版快 昏力
if( m_pCharGuidList->Find( pUser->GetCharGuid() ) )
{
m_pCharGuidList->Remove( pUser->GetCharGuid() );
MessageOut( eFULL_LOG, "捞傈 某腐磐(%u) ", pUser->GetCharGuid() );
}
// 货 某腐磐 捞抚 悸泼
pUser->SetCharGuid( dwCharGuid );
// CharGuid 府胶飘俊 眠啊
m_pCharGuidList->Add( dwCharGuid, pUser );
MessageOut( eFULL_LOG, "CharGuid(%u)", dwCharGuid );
return TRUE;
}
BOOL UserManager::SetUserCharName( DWORD dwGuid, std::string strCharName )
{
User *pUser = m_pGuidUserList->Find( dwGuid );
if( !pUser ) return FALSE;
MessageOut( eCRITICAL_LOG, "Guid(%u)CharGuid(%u)Name(%s)", dwGuid, pUser->GetCharGuid(), pUser->GetCharName().c_str() );
// 捞固 CharName府胶飘俊 乐绰 版快 昏力
if( m_pCharNameUserList->Find( pUser->GetCharName() ) )
{
m_pCharNameUserList->Remove( pUser->GetCharName() );
MessageOut( eFULL_LOG, "捞傈 某腐磐(%s) ", pUser->GetCharName().c_str() );
}
// 货 某腐磐 捞抚 悸泼
pUser->SetCharName( strCharName );
// CharName 府胶飘俊 眠啊
m_pCharNameUserList->Add( strCharName, pUser );
MessageOut(eFULL_LOG, "某腐磐 急琶(%s)", strCharName.c_str() );
return TRUE;
}
BOOL UserManager::UnSetCharGuid( DWORD dwGuid )
{
User *pUser = m_pCharGuidList->Find( dwGuid );
if( !pUser ) return FALSE;
// CharGuid 府胶飘俊辑 昏力
m_pCharGuidList->Remove( pUser->GetCharGuid() );
return TRUE;
}
BOOL UserManager::UnsetUserCharName( DWORD dwGuid )
{
User *pUser = m_pGuidUserList->Find( dwGuid );
if( !pUser ) return FALSE;
// CharName 府胶飘俊辑 昏力
m_pCharNameUserList->Remove( pUser->GetCharName() );
return TRUE;
}
User* UserManager::FindUser( DWORD dwGuid )
{
return m_pGuidUserList->Find( dwGuid );
}
User* UserManager::FindUserByCharGuid( DWORD CharGuid )
{
return m_pCharGuidList->Find( CharGuid );
}
User* UserManager::FindUser( std::string strCharName )
{
return m_pCharNameUserList->Find( strCharName );
}
VOID UserManager::SendToAll( BYTE *pMsg, WORD wSize )
{
m_pGuidUserList->SendToAll( pMsg, wSize );
}
DWORD UserManager::GetNumberOfGuidUsers()
{
return m_pGuidUserList->GetNumberOfUsers();
}
DWORD UserManager::GetNumberOfCharNameUsers()
{
return m_pCharNameUserList->GetNumberOfUsers();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -