Major design change in network protocol: Player information is now requested by clients whenever it is needed. The server only sends player ids. The client has a cache with player information.

This commit is contained in:
lotodore
2007-08-26 22:41:37 +00:00
parent ba17f1d08e
commit 56b24e09eb
19 changed files with 755 additions and 104 deletions
+39 -1
View File
@@ -190,7 +190,9 @@ ServerLobbyThread::ProcessLoop()
SessionError(session, ERR_SOCK_INVALID_STATE);
else
{
if (packet->ToNetPacketCreateGame())
if (packet->ToNetPacketRetrievePlayerInfo())
HandleNetPacketRetrievePlayerInfo(session, *packet->ToNetPacketRetrievePlayerInfo());
else if (packet->ToNetPacketCreateGame())
HandleNetPacketCreateGame(session, *packet->ToNetPacketCreateGame());
else if (packet->ToNetPacketJoinGame())
HandleNetPacketJoinGame(session, *packet->ToNetPacketJoinGame());
@@ -266,6 +268,41 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const NetPacketIn
session.sessionData->SetState(SessionData::Established);
}
void
ServerLobbyThread::HandleNetPacketRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket)
{
NetPacketRetrievePlayerInfo::Data request;
tmpPacket.GetData(request);
// Find player in lobby or in a game.
SessionWrapper tmpSession = m_sessionManager.GetSessionByUniquePlayerId(request.playerId);
if (!tmpSession.sessionData.get() || !tmpSession.playerData.get())
{
GameMap::const_iterator game_i = m_gameMap.begin();
GameMap::const_iterator game_end = m_gameMap.end();
while (game_i != game_end)
{
tmpSession = game_i->second->GetSessionManager().GetSessionByUniquePlayerId(request.playerId);
if (tmpSession.sessionData.get() && tmpSession.playerData.get())
break;
++game_i;
}
}
if (tmpSession.sessionData.get() && tmpSession.playerData.get())
{
// Send player info to client.
boost::shared_ptr<NetPacket> info(new NetPacketPlayerInfo);
NetPacketPlayerInfo::Data infoData;
infoData.playerId = tmpSession.playerData->GetUniqueId();
infoData.playerInfo.ptype = tmpSession.playerData->GetType();
infoData.playerInfo.playerName = tmpSession.playerData->GetName();
static_cast<NetPacketPlayerInfo *>(info.get())->SetData(infoData);
GetSender().Send(session.sessionData->GetSocket(), info);
}
// TODO: handle error
}
void
ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const NetPacketCreateGame &tmpPacket)
{
@@ -517,6 +554,7 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
packetData.gameId = game.GetId();
packetData.gameMode = GAME_MODE_CREATED;
packetData.gameName = game.GetName();
packetData.gameData = game.GetGameData();
static_cast<NetPacketGameListNew *>(packet.get())->SetData(packetData);
return packet;
}