Major redesign: The game can not be left without disconnecting from the server. This happens if a player is kicked, if he wishes to leave, or for other reasons. Error packets from the server will always cause a disconnect, however.

If joining a game fails, there is a proper failure packet now.
This commit is contained in:
lotodore
2007-09-06 19:09:05 +00:00
parent 040aadda3c
commit 9d0edc5eee
24 changed files with 694 additions and 140 deletions
+12 -23
View File
@@ -185,7 +185,7 @@ void
ServerGameThread::InternalKickPlayer(unsigned playerId)
{
SessionWrapper tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId);
SessionError(tmpSession, ERR_NET_PLAYER_KICKED);
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_KICKED);
}
PlayerDataList
@@ -262,18 +262,9 @@ ServerGameThread::ResetComputerPlayerList()
}
void
ServerGameThread::SessionError(SessionWrapper session, int errorCode)
{
if (session.sessionData.get())
{
SendError(session.sessionData->GetSocket(), errorCode);
CloseSessionDelayed(session);
}
}
void
ServerGameThread::CloseSessionDelayed(SessionWrapper session)
ServerGameThread::RemoveSession(SessionWrapper session)
{
assert(session.sessionData.get());
GetSessionManager().RemoveSession(session.sessionData->GetSocket());
boost::shared_ptr<PlayerData> tmpPlayerData = session.playerData;
@@ -285,26 +276,24 @@ ServerGameThread::CloseSessionDelayed(SessionWrapper session)
thisPlayerLeftData.playerId = tmpPlayerData->GetUniqueId();
static_cast<NetPacketPlayerLeft *>(thisPlayerLeft.get())->SetData(thisPlayerLeftData);
GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game);
GetLobbyThread().NotifyPlayerLeftGame(GetId(), session.playerData->GetUniqueId());
}
GetLobbyThread().CloseSessionDelayed(session);
GetLobbyThread().NotifyPlayerLeftGame(GetId(), session.playerData->GetUniqueId());
}
void
ServerGameThread::SendError(SOCKET s, int errorCode)
ServerGameThread::SessionError(SessionWrapper session, int errorCode)
{
boost::shared_ptr<NetPacket> packet(new NetPacketError);
NetPacketError::Data errorData;
errorData.errorCode = errorCode;
static_cast<NetPacketError *>(packet.get())->SetData(errorData);
GetSender().Send(s, packet);
assert(session.sessionData.get());
RemoveSession(session);
GetLobbyThread().SessionError(session, errorCode);
}
void
ServerGameThread::RejectSession(SessionWrapper session)
ServerGameThread::MoveSessionToLobby(SessionWrapper session, int reason)
{
// TODO
RemoveSession(session);
GetLobbyThread().ReAddSession(session, reason);
}
void