Adding support for an avatar blacklist in the database.

This commit is contained in:
lotodore
2011-01-09 00:22:00 +00:00
parent f84e629f17
commit a148adf237
7 changed files with 55 additions and 1 deletions
+6
View File
@@ -54,6 +54,12 @@ ServerDBGeneric::AsyncPlayerLogin(unsigned requestId, const string &/*playerName
m_ioService->post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &m_callback, requestId)); m_ioService->post(boost::bind(&ServerDBCallback::PlayerLoginFailed, &m_callback, requestId));
} }
void
ServerDBGeneric::AsyncCheckAvatarBlacklist(unsigned requestId, const std::string &/*avatarHash*/)
{
m_ioService->post(boost::bind(&ServerDBCallback::AvatarIsBlacklisted, &m_callback, requestId));
}
void void
ServerDBGeneric::PlayerPostLogin(DB_id /*playerId*/, const std::string &/*avatarHash*/, const std::string &/*avatarType*/) ServerDBGeneric::PlayerPostLogin(DB_id /*playerId*/, const std::string &/*avatarHash*/, const std::string &/*avatarType*/)
{ {
+3
View File
@@ -40,6 +40,9 @@ public:
virtual void PlayerLoginFailed(unsigned requestId) = 0; virtual void PlayerLoginFailed(unsigned requestId) = 0;
virtual void PlayerLoginBlocked(unsigned requestId) = 0; virtual void PlayerLoginBlocked(unsigned requestId) = 0;
virtual void AvatarIsBlacklisted(unsigned requestId) = 0;
virtual void AvatarIsOK(unsigned requestId) = 0;
virtual void CreateGameSuccess(unsigned requestId, DB_id gameId) = 0; virtual void CreateGameSuccess(unsigned requestId, DB_id gameId) = 0;
virtual void CreateGameFailed(unsigned requestId) = 0; virtual void CreateGameFailed(unsigned requestId) = 0;
+1
View File
@@ -39,6 +39,7 @@ public:
virtual void Stop(); virtual void Stop();
virtual void AsyncPlayerLogin(unsigned requestId, const std::string &playerName); virtual void AsyncPlayerLogin(unsigned requestId, const std::string &playerName);
virtual void AsyncCheckAvatarBlacklist(unsigned requestId, const std::string &avatarHash);
virtual void PlayerPostLogin(DB_id playerId, const std::string &avatarHash, const std::string &avatarType); virtual void PlayerPostLogin(DB_id playerId, const std::string &avatarHash, const std::string &avatarType);
virtual void PlayerLogout(DB_id playerId); virtual void PlayerLogout(DB_id playerId);
+1
View File
@@ -39,6 +39,7 @@ public:
virtual void Stop() = 0; virtual void Stop() = 0;
virtual void AsyncPlayerLogin(unsigned requestId, const std::string &playerName) = 0; virtual void AsyncPlayerLogin(unsigned requestId, const std::string &playerName) = 0;
virtual void AsyncCheckAvatarBlacklist(unsigned requestId, const std::string &avatarHash) = 0;
virtual void PlayerPostLogin(DB_id playerId, const std::string &avatarHash, const std::string &avatarType) = 0; virtual void PlayerPostLogin(DB_id playerId, const std::string &avatarHash, const std::string &avatarType) = 0;
virtual void PlayerLogout(DB_id playerId) = 0; virtual void PlayerLogout(DB_id playerId) = 0;
+1
View File
@@ -37,6 +37,7 @@ public:
virtual void Stop() {} virtual void Stop() {}
virtual void AsyncPlayerLogin(unsigned /*requestId*/, const std::string &/*playerName*/) {} virtual void AsyncPlayerLogin(unsigned /*requestId*/, const std::string &/*playerName*/) {}
virtual void AsyncCheckAvatarBlacklist(unsigned /*requestId*/, const std::string &/*avatarHash*/) {}
virtual void PlayerPostLogin(DB_id /*playerId*/, const std::string &/*avatarHash*/, const std::string &/*avatarType*/) {} virtual void PlayerPostLogin(DB_id /*playerId*/, const std::string &/*avatarHash*/, const std::string &/*avatarType*/) {}
virtual void PlayerLogout(DB_id /*playerId*/) {} virtual void PlayerLogout(DB_id /*playerId*/) {}
+38 -1
View File
@@ -147,6 +147,16 @@ public:
m_server.UserBlocked(requestId); m_server.UserBlocked(requestId);
} }
virtual void AvatarIsBlacklisted(unsigned requestId)
{
m_server.AvatarBlacklisted(requestId);
}
virtual void AvatarIsOK(unsigned requestId)
{
m_server.AvatarOK(requestId);
}
virtual void CreateGameSuccess(unsigned requestId, DB_id gameId) virtual void CreateGameSuccess(unsigned requestId, DB_id gameId)
{ {
m_server.SetGameDBId((u_int32_t)requestId, gameId); m_server.SetGameDBId((u_int32_t)requestId, gameId);
@@ -1158,7 +1168,7 @@ ServerLobbyThread::HandleNetPacketAuthClientResponse(SessionWrapper session, con
GetSender().Send(session.sessionData, packet); GetSender().Send(session.sessionData, packet);
// The last message is only for server verification. // The last message is only for server verification.
// We are done now, the user has logged in. // We are done now, the user has logged in.
InitAfterLogin(session); CheckAvatarBlacklist(session);
} }
else else
SessionError(session, ERR_NET_INVALID_PASSWORD); SessionError(session, ERR_NET_INVALID_PASSWORD);
@@ -1543,6 +1553,33 @@ ServerLobbyThread::AuthChallenge(SessionWrapper session, const string &secret)
} }
} }
void
ServerLobbyThread::CheckAvatarBlacklist(SessionWrapper session)
{
if (session.sessionData && session.playerData)
{
const MD5Buf &avatarMD5 = session.playerData->GetAvatarMD5();
if (!avatarMD5.IsZero())
m_database->AsyncCheckAvatarBlacklist(session.playerData->GetUniqueId(), avatarMD5.ToString());
else
InitAfterLogin(session);
}
}
void
ServerLobbyThread::AvatarBlacklisted(unsigned playerId)
{
// TODO use proper error code.
SessionError(m_sessionManager.GetSessionByUniquePlayerId(playerId, true), ERR_NET_AVATAR_TOO_LARGE);
}
void
ServerLobbyThread::AvatarOK(unsigned playerId)
{
SessionWrapper tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId, true);
InitAfterLogin(tmpSession);
}
void void
ServerLobbyThread::InitAfterLogin(SessionWrapper session) ServerLobbyThread::InitAfterLogin(SessionWrapper session)
{ {
+5
View File
@@ -143,13 +143,18 @@ protected:
void HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, const JoinExistingGame_t &joinGame); void HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, const JoinExistingGame_t &joinGame);
void HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest); void HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest);
void HandleNetPacketRejectGameInvitation(SessionWrapper session, const RejectGameInvitationMessage_t &reject); void HandleNetPacketRejectGameInvitation(SessionWrapper session, const RejectGameInvitationMessage_t &reject);
// TODO would be better to use state pattern here.
void AuthChallenge(SessionWrapper session, const std::string &secret); void AuthChallenge(SessionWrapper session, const std::string &secret);
void CheckAvatarBlacklist(SessionWrapper session);
void AvatarBlacklisted(unsigned playerId);
void AvatarOK(unsigned playerId);
void InitAfterLogin(SessionWrapper session); void InitAfterLogin(SessionWrapper session);
void EstablishSession(SessionWrapper session); void EstablishSession(SessionWrapper session);
void AuthenticatePlayer(SessionWrapper session); void AuthenticatePlayer(SessionWrapper session);
void UserValid(unsigned playerId, const DBPlayerData &dbPlayerData); void UserValid(unsigned playerId, const DBPlayerData &dbPlayerData);
void UserInvalid(unsigned playerId); void UserInvalid(unsigned playerId);
void UserBlocked(unsigned playerId); void UserBlocked(unsigned playerId);
void SendReportAvatarResult(unsigned byPlayerId, unsigned reportedPlayerId, bool success); void SendReportAvatarResult(unsigned byPlayerId, unsigned reportedPlayerId, bool success);
void RequestPlayerAvatar(SessionWrapper session); void RequestPlayerAvatar(SessionWrapper session);
void TimerRemoveGame(const boost::system::error_code &ec); void TimerRemoveGame(const boost::system::error_code &ec);