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
+47
View File
@@ -300,6 +300,53 @@ ClientThread::SendPacketLoop()
}
}
PlayerInfo
ClientThread::GetCachedPlayerInfo(unsigned id) const
{
PlayerInfoMap::const_iterator pos = m_playerInfoMap.find(id);
if (pos == m_playerInfoMap.end())
throw NetException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
return pos->second;
}
void
ClientThread::RequestPlayerInfo(unsigned id, const PlayerInfo &tempInfo)
{
boost::shared_ptr<NetPacket> req(new NetPacketRetrievePlayerInfo);
NetPacketRetrievePlayerInfo::Data reqData;
reqData.playerId = id;
static_cast<NetPacketRetrievePlayerInfo *>(req.get())->SetData(reqData);
GetSender().Send(GetContext().GetSocket(), req);
m_playerInfoMap[id] = tempInfo;
}
void
ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info)
{
PlayerInfoMap::iterator pos = m_playerInfoMap.find(id);
// Update info cache.
if (pos != m_playerInfoMap.end())
{
GetCallback().SignalNetClientPlayerChanged(pos->second.playerName, info.playerName);
pos->second = info;
}
else
{
m_playerInfoMap.insert(PlayerInfoMap::value_type(id, info));
}
// Update player data for current game.
boost::shared_ptr<PlayerData> playerData = GetPlayerDataByUniqueId(id);
if (playerData.get())
{
playerData->SetName(info.playerName);
playerData->SetType(info.ptype);
}
}
const ClientContext &
ClientThread::GetContext() const
{