Multiple player info requests can be placed in one packet.
This commit is contained in:
@@ -139,6 +139,7 @@ protected:
|
||||
|
||||
bool GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const;
|
||||
void RequestPlayerInfo(unsigned id, bool requestAvatar = false);
|
||||
void RequestPlayerInfo(const std::list<unsigned> &idList, bool requestAvatar = false);
|
||||
void SetPlayerInfo(unsigned id, const PlayerInfo &info);
|
||||
void SetUnknownPlayer(unsigned id);
|
||||
void SetNewGameAdmin(unsigned id);
|
||||
|
||||
@@ -677,15 +677,18 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
|
||||
unsigned numPlayers = netListNew.playerids_size();
|
||||
// Request player info for players if needed.
|
||||
GameInfo tmpInfo;
|
||||
list<unsigned> requestList;
|
||||
for (unsigned i = 0; i < numPlayers; i++) {
|
||||
PlayerInfo info;
|
||||
unsigned playerId = netListNew.playerids(i);
|
||||
if (!client->GetCachedPlayerInfo(playerId, info)) {
|
||||
// Request player info.
|
||||
client->RequestPlayerInfo(playerId);
|
||||
requestList.push_back(playerId);
|
||||
}
|
||||
tmpInfo.players.push_back(playerId);
|
||||
}
|
||||
// Send request for multiple players (will only act if list is non-empty).
|
||||
client->RequestPlayerInfo(requestList);
|
||||
|
||||
tmpInfo.adminPlayerId = netListNew.adminplayerid();
|
||||
tmpInfo.isPasswordProtected = netListNew.isprivate();
|
||||
tmpInfo.mode = static_cast<GameMode>(netListNew.gamemode());
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <qttoolsinterface.h>
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
@@ -644,19 +645,29 @@ ClientThread::GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const
|
||||
void
|
||||
ClientThread::RequestPlayerInfo(unsigned id, bool requestAvatar)
|
||||
{
|
||||
if (find(m_playerInfoRequestList.begin(), m_playerInfoRequestList.end(), id) == m_playerInfoRequestList.end()) {
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
||||
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayerInfoRequestMessage);
|
||||
PlayerInfoRequestMessage *netPlayerInfo = packet->GetMsg()->mutable_playerinforequestmessage();
|
||||
netPlayerInfo->set_playerid(id);
|
||||
GetSender().Send(GetContext().GetSessionData(), packet);
|
||||
|
||||
m_playerInfoRequestList.push_back(id);
|
||||
list<unsigned> idList;
|
||||
idList.push_back(id);
|
||||
RequestPlayerInfo(idList, requestAvatar);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RequestPlayerInfo(const list<unsigned> &idList, bool requestAvatar)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
||||
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayerInfoRequestMessage);
|
||||
PlayerInfoRequestMessage *netPlayerInfo = packet->GetMsg()->mutable_playerinforequestmessage();
|
||||
BOOST_FOREACH(unsigned playerId, idList) {
|
||||
if (find(m_playerInfoRequestList.begin(), m_playerInfoRequestList.end(), playerId) == m_playerInfoRequestList.end()) {
|
||||
netPlayerInfo->add_playerid(playerId);
|
||||
m_playerInfoRequestList.push_back(playerId);
|
||||
}
|
||||
// Remember that we have to request an avatar.
|
||||
if (requestAvatar) {
|
||||
m_avatarShouldRequestList.push_back(playerId);
|
||||
}
|
||||
}
|
||||
// Remember that we have to request an avatar.
|
||||
if (requestAvatar) {
|
||||
m_avatarShouldRequestList.push_back(id);
|
||||
if (netPlayerInfo->playerid_size() > 0) {
|
||||
GetSender().Send(GetContext().GetSessionData(), packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1144,47 +1144,49 @@ ServerLobbyThread::HandleNetPacketAvatarEnd(boost::shared_ptr<SessionData> sessi
|
||||
void
|
||||
ServerLobbyThread::HandleNetPacketRetrievePlayerInfo(boost::shared_ptr<SessionData> session, const PlayerInfoRequestMessage &playerInfoRequest)
|
||||
{
|
||||
// Find player in lobby or in a game.
|
||||
boost::shared_ptr<SessionData> tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerInfoRequest.playerid());
|
||||
if (!tmpSession) {
|
||||
tmpSession = m_gameSessionManager.GetSessionByUniquePlayerId(playerInfoRequest.playerid());
|
||||
}
|
||||
boost::shared_ptr<PlayerData> tmpPlayer;
|
||||
if (tmpSession) {
|
||||
tmpPlayer = tmpSession->GetPlayerData();
|
||||
}
|
||||
|
||||
if (!tmpPlayer) {
|
||||
boost::mutex::scoped_lock lock(m_computerPlayersMutex);
|
||||
PlayerDataMap::const_iterator pos = m_computerPlayers.find(playerInfoRequest.playerid());
|
||||
if (pos != m_computerPlayers.end())
|
||||
tmpPlayer = pos->second;
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
||||
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayerInfoReplyMessage);
|
||||
PlayerInfoReplyMessage *netPlayerInfoReply = packet->GetMsg()->mutable_playerinforeplymessage();
|
||||
netPlayerInfoReply->set_playerid(playerInfoRequest.playerid());
|
||||
|
||||
if (tmpPlayer) {
|
||||
// Send player info to client.
|
||||
PlayerInfoReplyMessage::PlayerInfoData *data = netPlayerInfoReply->mutable_playerinfodata();
|
||||
|
||||
data->set_playername(tmpPlayer->GetName());
|
||||
data->set_ishuman(tmpPlayer->GetType() == PLAYER_TYPE_HUMAN);
|
||||
data->set_playerrights(static_cast<NetPlayerInfoRights>(tmpPlayer->GetRights()));
|
||||
if (!tmpPlayer->GetCountry().empty()) {
|
||||
data->set_countrycode(tmpPlayer->GetCountry());
|
||||
BOOST_FOREACH(unsigned playerId, playerInfoRequest.playerid()) {
|
||||
// Find player in lobby or in a game.
|
||||
boost::shared_ptr<SessionData> tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId);
|
||||
if (!tmpSession) {
|
||||
tmpSession = m_gameSessionManager.GetSessionByUniquePlayerId(playerId);
|
||||
}
|
||||
if (!tmpPlayer->GetAvatarMD5().IsZero()) {
|
||||
PlayerInfoReplyMessage::PlayerInfoData::AvatarData *avatarData = data->mutable_avatardata();
|
||||
avatarData->set_avatartype(static_cast<NetAvatarType>(AvatarManager::GetAvatarFileType(tmpPlayer->GetAvatarFile())));
|
||||
avatarData->set_avatarhash(tmpPlayer->GetAvatarMD5().GetData(), MD5_DATA_SIZE);
|
||||
boost::shared_ptr<PlayerData> tmpPlayer;
|
||||
if (tmpSession) {
|
||||
tmpPlayer = tmpSession->GetPlayerData();
|
||||
}
|
||||
} else {
|
||||
// Unknown player id - do not set any data.
|
||||
|
||||
if (!tmpPlayer) {
|
||||
boost::mutex::scoped_lock lock(m_computerPlayersMutex);
|
||||
PlayerDataMap::const_iterator pos = m_computerPlayers.find(playerId);
|
||||
if (pos != m_computerPlayers.end())
|
||||
tmpPlayer = pos->second;
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket);
|
||||
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_PlayerInfoReplyMessage);
|
||||
PlayerInfoReplyMessage *netPlayerInfoReply = packet->GetMsg()->mutable_playerinforeplymessage();
|
||||
netPlayerInfoReply->set_playerid(playerId);
|
||||
|
||||
if (tmpPlayer) {
|
||||
// Send player info to client.
|
||||
PlayerInfoReplyMessage::PlayerInfoData *data = netPlayerInfoReply->mutable_playerinfodata();
|
||||
|
||||
data->set_playername(tmpPlayer->GetName());
|
||||
data->set_ishuman(tmpPlayer->GetType() == PLAYER_TYPE_HUMAN);
|
||||
data->set_playerrights(static_cast<NetPlayerInfoRights>(tmpPlayer->GetRights()));
|
||||
if (!tmpPlayer->GetCountry().empty()) {
|
||||
data->set_countrycode(tmpPlayer->GetCountry());
|
||||
}
|
||||
if (!tmpPlayer->GetAvatarMD5().IsZero()) {
|
||||
PlayerInfoReplyMessage::PlayerInfoData::AvatarData *avatarData = data->mutable_avatardata();
|
||||
avatarData->set_avatartype(static_cast<NetAvatarType>(AvatarManager::GetAvatarFileType(tmpPlayer->GetAvatarFile())));
|
||||
avatarData->set_avatarhash(tmpPlayer->GetAvatarMD5().GetData(), MD5_DATA_SIZE);
|
||||
}
|
||||
} else {
|
||||
// Unknown player id - do not set any data.
|
||||
}
|
||||
GetSender().Send(session, packet);
|
||||
}
|
||||
GetSender().Send(session, packet);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user