89 lines
2.3 KiB
C++
89 lines
2.3 KiB
C++
#include "stdafx.h"
|
|
|
|
#include <AgentServer.h>
|
|
#include <ServerSessions/GameServerSession.h>
|
|
#include <ServerSessions/ServerSessionManager.h>
|
|
#include <PacketHandler/PacketHandler.h>
|
|
|
|
#include <UserSessions/UserManager.h>
|
|
|
|
GameServerSession::GameServerSession()
|
|
{
|
|
}
|
|
|
|
GameServerSession::~GameServerSession()
|
|
{
|
|
}
|
|
|
|
VOID GameServerSession::Init()
|
|
{
|
|
ServerSessionEx::Init();
|
|
}
|
|
|
|
VOID GameServerSession::Release()
|
|
{
|
|
// 有必要清除相关玩家的悬垂.
|
|
}
|
|
|
|
//VOID GameServerSession::OnRecv( BYTE *pMsg, WORD wSize )
|
|
//{
|
|
//}
|
|
//
|
|
|
|
VOID GameServerSession::OnDisconnect()
|
|
{
|
|
RemoveRelatedUsers();
|
|
ServerSessionManager::Instance()->RemoveServer( this );
|
|
ServerSessionEx::OnDisconnect();
|
|
}
|
|
|
|
//==================================================================================================
|
|
namespace ns_functor {
|
|
;
|
|
|
|
class DisconnectRelatededUsers : public ns_functor::IUserForeachFunctor
|
|
{
|
|
public:
|
|
DisconnectRelatededUsers(DWORD session_index)
|
|
: server_session_index_(session_index) {}
|
|
~DisconnectRelatededUsers() {}
|
|
|
|
virtual bool operator()(User* const user);
|
|
//
|
|
private:
|
|
const DWORD server_session_index_;
|
|
//
|
|
__DISABLE_COPY(DisconnectRelatededUsers);
|
|
};
|
|
|
|
}; //end of namespace
|
|
//==================================================================================================
|
|
|
|
bool ns_functor::DisconnectRelatededUsers::operator()(User* const user)
|
|
{
|
|
const DWORD user_linked_index = user->GetServerSessionIndex();
|
|
//< 连接场景或战区服务器的用户
|
|
if (user_linked_index && (user_linked_index == server_session_index_))
|
|
{
|
|
user->SetDisconnectCode(RC::RC_DISCONNECT_SERVER_ERROR);
|
|
// pUser->UnlinkServer(); 当GameServer中AgentSession断开时,用DBP发送Serialize包.
|
|
user->DisconnectLinkedServerUser();
|
|
|
|
SUNLOG(eFULL_LOG, _T("[DisconnectRelatededUsers][U:%d]:强制删除用户"), user->GetUserKey());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
VOID GameServerSession::RemoveRelatedUsers()
|
|
{
|
|
SUNLOG( eCRITICAL_LOG, _T("[RemoveRelatedUsers] [%s解除连接] : 强制删除相关玩家"),
|
|
GetServerType2String( GetServerType() )/*, UserManager::Instance()->GetNumberOfUsers()*/ );
|
|
// 注释理由ServerFrame在DoRelease之后将自己的Release.
|
|
ns_functor::DisconnectRelatededUsers disconnector(GetSessionIndex());
|
|
UserManager::Instance()->Foreach(&disconnector);
|
|
}
|
|
|