Preparing admin functions in PokerTH client.

This commit is contained in:
lotodore
2013-02-24 16:22:51 +01:00
parent 6d85adf7e2
commit 883ccdcf44
13 changed files with 77 additions and 15 deletions
+1
View File
@@ -549,6 +549,7 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
tmpInfo.playerName = netInfo.playername();
tmpInfo.ptype = netInfo.ishuman() ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER;
tmpInfo.isGuest = netInfo.playerrights() == netPlayerRightsGuest;
tmpInfo.isAdmin = netInfo.playerrights() == netPlayerRightsAdmin;
if (netInfo.has_countrycode()) {
tmpInfo.countryCode = netInfo.countrycode();
}
+1 -1
View File
@@ -52,7 +52,7 @@ NetPacket::~NetPacket()
}
boost::shared_ptr<NetPacket>
NetPacket::Create(char *data, size_t dataSize)
NetPacket::Create(const char *data, size_t dataSize)
{
boost::shared_ptr<NetPacket> tmpPacket;
+24
View File
@@ -30,6 +30,7 @@
*****************************************************************************/
#include <net/serverbanmanager.h>
#include <algorithm>
using namespace std;
@@ -43,6 +44,15 @@ ServerBanManager::~ServerBanManager()
{
}
void
ServerBanManager::SetAdminPlayerIds(const std::list<DB_id> adminList)
{
boost::mutex::scoped_lock lock(m_banMutex);
m_adminPlayers.resize(adminList.size());
copy(adminList.begin(), adminList.end(), m_adminPlayers.begin());
sort(m_adminPlayers.begin(), m_adminPlayers.end());
}
void
ServerBanManager::BanPlayerName(const std::string &playerName, unsigned durationHours)
{
@@ -140,6 +150,20 @@ ServerBanManager::ClearBanList()
m_banIPAddressMap.clear();
}
bool
ServerBanManager::IsAdminPlayer(DB_id playerId) const
{
bool retVal = false;
if (playerId != DB_ID_INVALID) {
boost::mutex::scoped_lock lock(m_banMutex);
if (binary_search(m_adminPlayers.begin(), m_adminPlayers.end(), playerId)) {
retVal = true;
}
}
return retVal;
}
bool
ServerBanManager::IsPlayerBanned(const std::string &name) const
{
+13 -4
View File
@@ -146,16 +146,16 @@ public:
LOG_MSG("Successfully connected to database.");
}
virtual void ConnectFailed(const string &error) {
virtual void ConnectFailed(string error) {
LOG_ERROR("DB connect error: " << error);
}
virtual void QueryError(const std::string &error) {
virtual void QueryError(string error) {
LOG_ERROR("DB query error: " << error);
}
virtual void PlayerLoginSuccess(unsigned requestId, const DBPlayerData &dbPlayerData) {
m_server.UserValid(requestId, dbPlayerData);
virtual void PlayerLoginSuccess(unsigned requestId, boost::shared_ptr<DBPlayerData> dbPlayerData) {
m_server.UserValid(requestId, *dbPlayerData);
}
virtual void PlayerLoginFailed(unsigned requestId) {
@@ -199,6 +199,10 @@ public:
m_server.SendReportGameResult(requestId, replyId, false);
}
virtual void PlayerAdminList(unsigned requestId, std::list<DB_id> adminList) {
m_server.GetBanManager().SetAdminPlayerIds(adminList);
}
private:
ServerLobbyThread &m_server;
};
@@ -242,6 +246,7 @@ ServerLobbyThread::Init(const string &logDir)
m_serverConfig.readConfigString("DBServerPassword"),
m_serverConfig.readConfigString("DBServerDatabaseName"),
m_serverConfig.readConfigString("DBServerEncryptionKey"));
m_database->AsyncQueryAdminPlayers(0);
GetBanManager().InitGameNameBadWordList(m_serverConfig.readConfigStringList("GameNameBadWordList"));
}
@@ -1074,6 +1079,10 @@ ServerLobbyThread::HandleNetPacketAuthClientResponse(boost::shared_ptr<SessionDa
GetSender().Send(session, packet);
// The last message is only for server verification.
// We are done now, the user has logged in.
boost::shared_ptr<PlayerData> tmpPlayerData = session->GetPlayerData();
if (GetBanManager().IsAdminPlayer(tmpPlayerData->GetDBId())) {
session->GetPlayerData()->SetRights(PLAYER_RIGHTS_ADMIN);
}
CheckAvatarBlacklist(session);
} else
SessionError(session, ERR_NET_INVALID_PASSWORD);