Don't request own avatar from the server. Only request avatars of other players after joining a game.
This commit is contained in:
@@ -45,6 +45,8 @@ public:
|
||||
|
||||
bool Init(const std::string &dataDir, const std::string &cacheDir);
|
||||
|
||||
void AddSingleAvatar(const std::string &fileName);
|
||||
|
||||
boost::shared_ptr<AvatarFileState> OpenAvatarFileForChunkRead(const std::string &fileName, unsigned &outFileSize, AvatarFileType &outFileType);
|
||||
unsigned ChunkReadAvatarFile(boost::shared_ptr<AvatarFileState> fileState, unsigned char *data, unsigned chunkSize);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "avatarmanager.h"
|
||||
#include <net/socket_msg.h>
|
||||
#include <core/loghelper.h>
|
||||
#include <core/crypthelper.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
@@ -93,6 +94,33 @@ AvatarManager::Init(const std::string &dataDir, const std::string &cacheDir)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void
|
||||
AvatarManager::AddSingleAvatar(const std::string &fileName)
|
||||
{
|
||||
path filePath(fileName);
|
||||
string tmpFileName(filePath.file_string());
|
||||
|
||||
if (!fileName.empty() && !tmpFileName.empty())
|
||||
{
|
||||
unsigned outFileSize;
|
||||
AvatarFileType outFileType;
|
||||
boost::shared_ptr<AvatarFileState> tmpFileState = OpenAvatarFileForChunkRead(tmpFileName, outFileSize, outFileType);
|
||||
|
||||
// Check whether the avatar file is valid.
|
||||
if (tmpFileState.get())
|
||||
{
|
||||
tmpFileState.reset();
|
||||
|
||||
MD5Buf md5buf;
|
||||
if (CryptHelper::MD5Sum(tmpFileName, md5buf))
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_avatarsMutex);
|
||||
m_avatars.insert(AvatarMap::value_type(md5buf, tmpFileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::shared_ptr<AvatarFileState>
|
||||
AvatarManager::OpenAvatarFileForChunkRead(const std::string &fileName, unsigned &outFileSize, AvatarFileType &outFileType)
|
||||
{
|
||||
|
||||
@@ -88,10 +88,11 @@ protected:
|
||||
void SendPacketLoop();
|
||||
|
||||
bool GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const;
|
||||
void RequestPlayerInfo(unsigned id);
|
||||
void SetPlayerInfo(unsigned id, const PlayerInfo &info, bool retrieveAvatar = true);
|
||||
void RequestPlayerInfo(unsigned id, bool requestAvatar = false);
|
||||
void SetPlayerInfo(unsigned id, const PlayerInfo &info);
|
||||
void SetUnknownPlayer(unsigned id);
|
||||
void SetNewGameAdmin(unsigned id);
|
||||
void RetrieveAvatarIfNeeded(unsigned id, const PlayerInfo &info);
|
||||
|
||||
void AddTempAvatarData(unsigned playerId, unsigned avatarSize, AvatarFileType type);
|
||||
void StoreInTempAvatarData(unsigned playerId, const std::vector<unsigned char> &data);
|
||||
@@ -171,6 +172,8 @@ private:
|
||||
PlayerInfoMap m_playerInfoMap;
|
||||
mutable boost::mutex m_playerInfoMapMutex;
|
||||
PlayerIdList m_playerInfoRequestList;
|
||||
PlayerIdList m_avatarShouldRequestList;
|
||||
PlayerIdList m_avatarHasRequestedList;
|
||||
|
||||
unsigned m_curGameId;
|
||||
mutable boost::mutex m_curGameIdMutex;
|
||||
|
||||
@@ -696,6 +696,8 @@ ClientStateWaitGame::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
||||
string avatarFile;
|
||||
if (client.GetAvatarManager().GetAvatarFileName(info.avatar, avatarFile))
|
||||
playerData->SetAvatarFile(avatarFile);
|
||||
else
|
||||
client.RetrieveAvatarIfNeeded(netPlayerData.playerId, info);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -704,7 +706,7 @@ ClientStateWaitGame::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
||||
name << "#" << netPlayerData.playerId;
|
||||
|
||||
// Request player info.
|
||||
client.RequestPlayerInfo(netPlayerData.playerId);
|
||||
client.RequestPlayerInfo(netPlayerData.playerId, true);
|
||||
// Use temporary data until the PlayerInfo request is completed.
|
||||
playerData.reset(
|
||||
new PlayerData(netPlayerData.playerId, 0, PLAYER_TYPE_HUMAN, netPlayerData.prights));
|
||||
|
||||
@@ -391,7 +391,7 @@ ClientThread::GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RequestPlayerInfo(unsigned id)
|
||||
ClientThread::RequestPlayerInfo(unsigned id, bool requestAvatar)
|
||||
{
|
||||
if (find(m_playerInfoRequestList.begin(), m_playerInfoRequestList.end(), id) == m_playerInfoRequestList.end())
|
||||
{
|
||||
@@ -402,11 +402,17 @@ ClientThread::RequestPlayerInfo(unsigned id)
|
||||
GetSender().Send(GetContext().GetSessionData(), req);
|
||||
|
||||
m_playerInfoRequestList.push_back(id);
|
||||
|
||||
}
|
||||
// Remember that we have to request an avatar.
|
||||
if (requestAvatar)
|
||||
{
|
||||
m_avatarShouldRequestList.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info, bool retrieveAvatar)
|
||||
ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
|
||||
@@ -429,15 +435,11 @@ ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info, bool retrieveAv
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve avatar if needed.
|
||||
if (retrieveAvatar && info.hasAvatar && !GetAvatarManager().HasAvatar(info.avatar))
|
||||
if (find(m_avatarShouldRequestList.begin(), m_avatarShouldRequestList.end(), id) != m_avatarShouldRequestList.end())
|
||||
{
|
||||
boost::shared_ptr<NetPacket> retrieveAvatar(new NetPacketRetrieveAvatar);
|
||||
NetPacketRetrieveAvatar::Data retrieveAvatarData;
|
||||
retrieveAvatarData.requestId = id;
|
||||
retrieveAvatarData.avatar = info.avatar;
|
||||
static_cast<NetPacketRetrieveAvatar *>(retrieveAvatar.get())->SetData(retrieveAvatarData);
|
||||
GetSender().Send(GetContext().GetSessionData(), retrieveAvatar);
|
||||
m_avatarShouldRequestList.remove(id);
|
||||
// Retrieve avatar if needed.
|
||||
RetrieveAvatarIfNeeded(id, info);
|
||||
}
|
||||
|
||||
// Remove it from the request list.
|
||||
@@ -453,6 +455,7 @@ ClientThread::SetUnknownPlayer(unsigned id)
|
||||
{
|
||||
// Just remove it from the request list.
|
||||
m_playerInfoRequestList.remove(id);
|
||||
m_avatarShouldRequestList.remove(id);
|
||||
LOG_ERROR("Server reported unknown player id: " << id);
|
||||
}
|
||||
|
||||
@@ -468,6 +471,24 @@ ClientThread::SetNewGameAdmin(unsigned id)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RetrieveAvatarIfNeeded(unsigned id, const PlayerInfo &info)
|
||||
{
|
||||
if (find(m_avatarHasRequestedList.begin(), m_avatarHasRequestedList.end(), id) == m_avatarHasRequestedList.end())
|
||||
{
|
||||
if (info.hasAvatar && !info.avatar.IsZero() && !GetAvatarManager().HasAvatar(info.avatar))
|
||||
{
|
||||
m_avatarHasRequestedList.push_back(id); // Never remove from this list. Only request once.
|
||||
boost::shared_ptr<NetPacket> retrieveAvatar(new NetPacketRetrieveAvatar);
|
||||
NetPacketRetrieveAvatar::Data retrieveAvatarData;
|
||||
retrieveAvatarData.requestId = id;
|
||||
retrieveAvatarData.avatar = info.avatar;
|
||||
static_cast<NetPacketRetrieveAvatar *>(retrieveAvatar.get())->SetData(retrieveAvatarData);
|
||||
GetSender().Send(GetContext().GetSessionData(), retrieveAvatar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::AddTempAvatarData(unsigned playerId, unsigned avatarSize, AvatarFileType type)
|
||||
{
|
||||
@@ -495,7 +516,6 @@ ClientThread::CompleteTempAvatarData(unsigned playerId)
|
||||
AvatarDataMap::iterator pos = m_tempAvatarMap.find(playerId);
|
||||
if (pos == m_tempAvatarMap.end())
|
||||
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_REQUEST_ID, 0);
|
||||
|
||||
boost::shared_ptr<AvatarData> tmpAvatar = pos->second;
|
||||
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
|
||||
if (avatarSize != tmpAvatar->reportedSize)
|
||||
@@ -511,7 +531,7 @@ ClientThread::CompleteTempAvatarData(unsigned playerId)
|
||||
LOG_ERROR("Failed to store avatar in cache directory.");
|
||||
|
||||
// Update player info, but never re-request avatar.
|
||||
SetPlayerInfo(playerId, tmpPlayerInfo, false);
|
||||
SetPlayerInfo(playerId, tmpPlayerInfo);
|
||||
|
||||
string fileName;
|
||||
if (GetAvatarManager().GetAvatarFileName(tmpPlayerInfo.avatar, fileName))
|
||||
|
||||
@@ -57,6 +57,9 @@ bool Session::init()
|
||||
{
|
||||
myAvatarManager.reset(new AvatarManager);
|
||||
bool retVal = myAvatarManager->Init(myConfig->readConfigString("AppDataDir"), myConfig->readConfigString("CacheDir"));
|
||||
#ifndef POKERTH_DEDICATED_SERVER
|
||||
myAvatarManager->AddSingleAvatar(myConfig->readConfigString("MyAvatar"));
|
||||
#endif
|
||||
myAvatarManager->RemoveOldAvatarCacheEntries();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
#include "game_defs.h"
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <core/crypthelper.h>
|
||||
#include <core/crypthelper.h>
|
||||
|
||||
class GuiInterface;
|
||||
class Game;
|
||||
|
||||
Reference in New Issue
Block a user