Finally: User supplied avatars are transfered! They are stored on the server and clients request them if needed. Make sure the server has write access to the cache dir to make it work.

This commit is contained in:
lotodore
2007-10-07 18:46:40 +00:00
parent 639df29bdc
commit d16312111f
7 changed files with 123 additions and 1 deletions
+51
View File
@@ -387,6 +387,7 @@ ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info)
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
m_playerInfoMap[id] = info;
}
// Update player data for current game.
boost::shared_ptr<PlayerData> playerData = GetPlayerDataByUniqueId(id);
if (playerData.get())
@@ -397,11 +398,15 @@ ClientThread::SetPlayerInfo(unsigned id, const PlayerInfo &info)
{
string avatarFile;
if (GetAvatarManager().GetAvatarFileName(info.avatar, avatarFile))
{
playerData->SetAvatarFile(avatarFile);
}
}
}
// Notify GUI
GetCallback().SignalNetClientPlayerChanged(id, info.playerName);
}
void
@@ -416,6 +421,52 @@ ClientThread::SetNewGameAdmin(unsigned id)
}
}
void
ClientThread::AddTempAvatarData(unsigned playerId, unsigned avatarSize, AvatarFileType type)
{
boost::shared_ptr<AvatarData> tmpAvatar(new AvatarData);
tmpAvatar->fileData.reserve(avatarSize);
tmpAvatar->fileType = type;
tmpAvatar->reportedSize = avatarSize;
m_tempAvatarMap[playerId] = tmpAvatar;
}
void
ClientThread::StoreInTempAvatarData(unsigned playerId, const vector<unsigned char> &data)
{
AvatarDataMap::iterator pos = m_tempAvatarMap.find(playerId);
if (pos == m_tempAvatarMap.end())
throw NetException(ERR_NET_INVALID_REQUEST_ID, 0);
// We trust the server (concerning size of the data).
std::copy(data.begin(), data.end(), back_inserter(pos->second->fileData));
}
void
ClientThread::CompleteTempAvatarData(unsigned playerId)
{
AvatarDataMap::iterator pos = m_tempAvatarMap.find(playerId);
if (pos == m_tempAvatarMap.end())
throw NetException(ERR_NET_INVALID_REQUEST_ID, 0);
boost::shared_ptr<AvatarData> tmpAvatar = pos->second;
unsigned avatarSize = (unsigned)tmpAvatar->fileData.size();
if (avatarSize != tmpAvatar->reportedSize)
throw NetException(ERR_NET_WRONG_AVATAR_SIZE, 0);
PlayerInfo tmpPlayerInfo;
if (!GetCachedPlayerInfo(playerId, tmpPlayerInfo))
throw NetException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
GetAvatarManager().StoreAvatarInCache(tmpPlayerInfo.avatar, tmpAvatar->fileType, &tmpAvatar->fileData[0], avatarSize);
// TODO log error
// Free memory.
m_tempAvatarMap.erase(pos);
// Update player info, but never re-request avatar.
SetPlayerInfo(playerId, tmpPlayerInfo);
}
const ClientContext &
ClientThread::GetContext() const
{