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);
|
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);
|
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);
|
unsigned ChunkReadAvatarFile(boost::shared_ptr<AvatarFileState> fileState, unsigned char *data, unsigned chunkSize);
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "avatarmanager.h"
|
#include "avatarmanager.h"
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
#include <core/loghelper.h>
|
#include <core/loghelper.h>
|
||||||
|
#include <core/crypthelper.h>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/lambda/lambda.hpp>
|
#include <boost/lambda/lambda.hpp>
|
||||||
@@ -93,6 +94,33 @@ AvatarManager::Init(const std::string &dataDir, const std::string &cacheDir)
|
|||||||
return retVal;
|
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>
|
boost::shared_ptr<AvatarFileState>
|
||||||
AvatarManager::OpenAvatarFileForChunkRead(const std::string &fileName, unsigned &outFileSize, AvatarFileType &outFileType)
|
AvatarManager::OpenAvatarFileForChunkRead(const std::string &fileName, unsigned &outFileSize, AvatarFileType &outFileType)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,10 +88,11 @@ protected:
|
|||||||
void SendPacketLoop();
|
void SendPacketLoop();
|
||||||
|
|
||||||
bool GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const;
|
bool GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const;
|
||||||
void RequestPlayerInfo(unsigned id);
|
void RequestPlayerInfo(unsigned id, bool requestAvatar = false);
|
||||||
void SetPlayerInfo(unsigned id, const PlayerInfo &info, bool retrieveAvatar = true);
|
void SetPlayerInfo(unsigned id, const PlayerInfo &info);
|
||||||
void SetUnknownPlayer(unsigned id);
|
void SetUnknownPlayer(unsigned id);
|
||||||
void SetNewGameAdmin(unsigned id);
|
void SetNewGameAdmin(unsigned id);
|
||||||
|
void RetrieveAvatarIfNeeded(unsigned id, const PlayerInfo &info);
|
||||||
|
|
||||||
void AddTempAvatarData(unsigned playerId, unsigned avatarSize, AvatarFileType type);
|
void AddTempAvatarData(unsigned playerId, unsigned avatarSize, AvatarFileType type);
|
||||||
void StoreInTempAvatarData(unsigned playerId, const std::vector<unsigned char> &data);
|
void StoreInTempAvatarData(unsigned playerId, const std::vector<unsigned char> &data);
|
||||||
@@ -171,6 +172,8 @@ private:
|
|||||||
PlayerInfoMap m_playerInfoMap;
|
PlayerInfoMap m_playerInfoMap;
|
||||||
mutable boost::mutex m_playerInfoMapMutex;
|
mutable boost::mutex m_playerInfoMapMutex;
|
||||||
PlayerIdList m_playerInfoRequestList;
|
PlayerIdList m_playerInfoRequestList;
|
||||||
|
PlayerIdList m_avatarShouldRequestList;
|
||||||
|
PlayerIdList m_avatarHasRequestedList;
|
||||||
|
|
||||||
unsigned m_curGameId;
|
unsigned m_curGameId;
|
||||||
mutable boost::mutex m_curGameIdMutex;
|
mutable boost::mutex m_curGameIdMutex;
|
||||||
|
|||||||
@@ -696,6 +696,8 @@ ClientStateWaitGame::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
|||||||
string avatarFile;
|
string avatarFile;
|
||||||
if (client.GetAvatarManager().GetAvatarFileName(info.avatar, avatarFile))
|
if (client.GetAvatarManager().GetAvatarFileName(info.avatar, avatarFile))
|
||||||
playerData->SetAvatarFile(avatarFile);
|
playerData->SetAvatarFile(avatarFile);
|
||||||
|
else
|
||||||
|
client.RetrieveAvatarIfNeeded(netPlayerData.playerId, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -704,7 +706,7 @@ ClientStateWaitGame::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
|||||||
name << "#" << netPlayerData.playerId;
|
name << "#" << netPlayerData.playerId;
|
||||||
|
|
||||||
// Request player info.
|
// Request player info.
|
||||||
client.RequestPlayerInfo(netPlayerData.playerId);
|
client.RequestPlayerInfo(netPlayerData.playerId, true);
|
||||||
// Use temporary data until the PlayerInfo request is completed.
|
// Use temporary data until the PlayerInfo request is completed.
|
||||||
playerData.reset(
|
playerData.reset(
|
||||||
new PlayerData(netPlayerData.playerId, 0, PLAYER_TYPE_HUMAN, netPlayerData.prights));
|
new PlayerData(netPlayerData.playerId, 0, PLAYER_TYPE_HUMAN, netPlayerData.prights));
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ ClientThread::GetCachedPlayerInfo(unsigned id, PlayerInfo &info) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClientThread::RequestPlayerInfo(unsigned id)
|
ClientThread::RequestPlayerInfo(unsigned id, bool requestAvatar)
|
||||||
{
|
{
|
||||||
if (find(m_playerInfoRequestList.begin(), m_playerInfoRequestList.end(), id) == m_playerInfoRequestList.end())
|
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);
|
GetSender().Send(GetContext().GetSessionData(), req);
|
||||||
|
|
||||||
m_playerInfoRequestList.push_back(id);
|
m_playerInfoRequestList.push_back(id);
|
||||||
|
|
||||||
|
}
|
||||||
|
// Remember that we have to request an avatar.
|
||||||
|
if (requestAvatar)
|
||||||
|
{
|
||||||
|
m_avatarShouldRequestList.push_back(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info, bool retrieveAvatar)
|
ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
|
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 (find(m_avatarShouldRequestList.begin(), m_avatarShouldRequestList.end(), id) != m_avatarShouldRequestList.end())
|
||||||
if (retrieveAvatar && info.hasAvatar && !GetAvatarManager().HasAvatar(info.avatar))
|
|
||||||
{
|
{
|
||||||
boost::shared_ptr<NetPacket> retrieveAvatar(new NetPacketRetrieveAvatar);
|
m_avatarShouldRequestList.remove(id);
|
||||||
NetPacketRetrieveAvatar::Data retrieveAvatarData;
|
// Retrieve avatar if needed.
|
||||||
retrieveAvatarData.requestId = id;
|
RetrieveAvatarIfNeeded(id, info);
|
||||||
retrieveAvatarData.avatar = info.avatar;
|
|
||||||
static_cast<NetPacketRetrieveAvatar *>(retrieveAvatar.get())->SetData(retrieveAvatarData);
|
|
||||||
GetSender().Send(GetContext().GetSessionData(), retrieveAvatar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove it from the request list.
|
// Remove it from the request list.
|
||||||
@@ -453,6 +455,7 @@ ClientThread::SetUnknownPlayer(unsigned id)
|
|||||||
{
|
{
|
||||||
// Just remove it from the request list.
|
// Just remove it from the request list.
|
||||||
m_playerInfoRequestList.remove(id);
|
m_playerInfoRequestList.remove(id);
|
||||||
|
m_avatarShouldRequestList.remove(id);
|
||||||
LOG_ERROR("Server reported unknown player id: " << 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
|
void
|
||||||
ClientThread::AddTempAvatarData(unsigned playerId, unsigned avatarSize, AvatarFileType type)
|
ClientThread::AddTempAvatarData(unsigned playerId, unsigned avatarSize, AvatarFileType type)
|
||||||
{
|
{
|
||||||
@@ -495,7 +516,6 @@ ClientThread::CompleteTempAvatarData(unsigned playerId)
|
|||||||
AvatarDataMap::iterator pos = m_tempAvatarMap.find(playerId);
|
AvatarDataMap::iterator pos = m_tempAvatarMap.find(playerId);
|
||||||
if (pos == m_tempAvatarMap.end())
|
if (pos == m_tempAvatarMap.end())
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_REQUEST_ID, 0);
|
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_REQUEST_ID, 0);
|
||||||
|
|
||||||
boost::shared_ptr<AvatarData> tmpAvatar = pos->second;
|
boost::shared_ptr<AvatarData> tmpAvatar = pos->second;
|
||||||
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
|
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
|
||||||
if (avatarSize != tmpAvatar->reportedSize)
|
if (avatarSize != tmpAvatar->reportedSize)
|
||||||
@@ -511,7 +531,7 @@ ClientThread::CompleteTempAvatarData(unsigned playerId)
|
|||||||
LOG_ERROR("Failed to store avatar in cache directory.");
|
LOG_ERROR("Failed to store avatar in cache directory.");
|
||||||
|
|
||||||
// Update player info, but never re-request avatar.
|
// Update player info, but never re-request avatar.
|
||||||
SetPlayerInfo(playerId, tmpPlayerInfo, false);
|
SetPlayerInfo(playerId, tmpPlayerInfo);
|
||||||
|
|
||||||
string fileName;
|
string fileName;
|
||||||
if (GetAvatarManager().GetAvatarFileName(tmpPlayerInfo.avatar, fileName))
|
if (GetAvatarManager().GetAvatarFileName(tmpPlayerInfo.avatar, fileName))
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ bool Session::init()
|
|||||||
{
|
{
|
||||||
myAvatarManager.reset(new AvatarManager);
|
myAvatarManager.reset(new AvatarManager);
|
||||||
bool retVal = myAvatarManager->Init(myConfig->readConfigString("AppDataDir"), myConfig->readConfigString("CacheDir"));
|
bool retVal = myAvatarManager->Init(myConfig->readConfigString("AppDataDir"), myConfig->readConfigString("CacheDir"));
|
||||||
|
#ifndef POKERTH_DEDICATED_SERVER
|
||||||
|
myAvatarManager->AddSingleAvatar(myConfig->readConfigString("MyAvatar"));
|
||||||
|
#endif
|
||||||
myAvatarManager->RemoveOldAvatarCacheEntries();
|
myAvatarManager->RemoveOldAvatarCacheEntries();
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user