diff --git a/src/db/serverdbcallback.h b/src/db/serverdbcallback.h index 954ba4c5..a8484234 100644 --- a/src/db/serverdbcallback.h +++ b/src/db/serverdbcallback.h @@ -35,6 +35,8 @@ #include #include +#include +#include // Callback operations are posted using the io service, // and will therefore be executed in the io service thread. @@ -44,11 +46,11 @@ public: virtual ~ServerDBCallback(); virtual void ConnectSuccess() = 0; - virtual void ConnectFailed(const std::string &error) = 0; + virtual void ConnectFailed(std::string error) = 0; - virtual void QueryError(const std::string &error) = 0; + virtual void QueryError(std::string error) = 0; - virtual void PlayerLoginSuccess(unsigned requestId, const DBPlayerData &dbPlayerData) = 0; + virtual void PlayerLoginSuccess(unsigned requestId, boost::shared_ptr dbPlayerData) = 0; virtual void PlayerLoginFailed(unsigned requestId) = 0; virtual void PlayerLoginBlocked(unsigned requestId) = 0; @@ -63,6 +65,8 @@ public: virtual void ReportGameSuccess(unsigned requestId, unsigned replyId) = 0; virtual void ReportGameFailed(unsigned requestId, unsigned replyId) = 0; + + virtual void PlayerAdminList(unsigned requestId, std::list adminList) = 0; }; #endif diff --git a/src/db/serverdbgeneric.h b/src/db/serverdbgeneric.h index 3365ac58..15547dd8 100644 --- a/src/db/serverdbgeneric.h +++ b/src/db/serverdbgeneric.h @@ -62,6 +62,9 @@ public: virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId); virtual void AsyncReportGame(unsigned requestId, unsigned replyId, DB_id *creatorPlayerId, unsigned gameId, const std::string &gameName, DB_id *byPlayerId); + virtual void AsyncQueryAdminPlayers(unsigned requestId); + virtual void AsyncBlockPlayer(unsigned requestId, DB_id playerId, int valid, int active); + private: boost::shared_ptr m_ioService; ServerDBCallback &m_callback; diff --git a/src/db/serverdbinterface.h b/src/db/serverdbinterface.h index baceec0e..00d0237f 100644 --- a/src/db/serverdbinterface.h +++ b/src/db/serverdbinterface.h @@ -61,6 +61,9 @@ public: virtual void AsyncReportAvatar(unsigned requestId, unsigned replyId, DB_id reportedPlayerId, const std::string &avatarHash, const std::string &avatarType, DB_id *byPlayerId) = 0; virtual void AsyncReportGame(unsigned requestId, unsigned replyId, DB_id *creatorPlayerId, unsigned gameId, const std::string &gameName, DB_id *byPlayerId) = 0; + + virtual void AsyncQueryAdminPlayers(unsigned requestId) = 0; + virtual void AsyncBlockPlayer(unsigned requestId, DB_id playerId, int valid, int active) = 0; }; #endif diff --git a/src/db/serverdbnoaction.h b/src/db/serverdbnoaction.h index 0563132f..59392f64 100644 --- a/src/db/serverdbnoaction.h +++ b/src/db/serverdbnoaction.h @@ -59,6 +59,9 @@ public: virtual void AsyncReportAvatar(unsigned /*requestId*/, unsigned /*replyId*/, DB_id /*reportedPlayerId*/, const std::string &/*avatarHash*/, const std::string &/*avatarType*/, DB_id * /*byPlayerId*/) {} virtual void AsyncReportGame(unsigned /*requestId*/, unsigned /*replyId*/, DB_id * /*creatorPlayerId*/, unsigned /*gameId*/, const std::string &/*gameName*/, DB_id * /*byPlayerId*/) {} + + virtual void AsyncQueryAdminPlayers(unsigned /*requestId*/) {} + virtual void AsyncBlockPlayer(unsigned /*requestId*/, DB_id /*playerId*/, int /*valid*/, int /*active*/) {} }; #endif // _SERVERDBNOACTION_H_ diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp index cc0e0c9b..a7afee99 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp @@ -2179,7 +2179,7 @@ void gameLobbyDialogImpl::reportBadGameName() { assert(mySession); if (myGameListSelectionModel->hasSelection()) { - unsigned gameId = selection->selectedRows().first().data(Qt::UserRole).toUInt(); + unsigned gameId = myGameListSelectionModel->selectedRows().first().data(Qt::UserRole).toUInt(); GameInfo info(mySession->getClientGameInfo(gameId)); int ret = MyMessageBox::question(this, tr("PokerTH - Question"), @@ -2196,14 +2196,14 @@ void gameLobbyDialogImpl::adminActionCloseGame() { assert(mySession); if (myGameListSelectionModel->hasSelection()) { - unsigned gameId = selection->selectedRows().first().data(Qt::UserRole).toUInt(); + unsigned gameId = myGameListSelectionModel->selectedRows().first().data(Qt::UserRole).toUInt(); GameInfo info(mySession->getClientGameInfo(gameId)); int ret = MyMessageBox::question(this, tr("PokerTH - Question"), tr("Are you sure you want to close the game:\n\"%1\"?").arg(QString::fromUtf8(info.name.c_str())), QMessageBox::Yes | QMessageBox::No); if(ret == QMessageBox::Yes) { - mySession->adminActionCloseGame(gameId); + //TODO mySession->adminActionCloseGame(gameId); } } } @@ -2212,14 +2212,14 @@ void gameLobbyDialogImpl::adminActionTotalKickBan() { assert(mySession); if (myNickListSelectionModel->hasSelection()) { - unsigned playerId = selection->selectedRows().first().data(Qt::UserRole).toUInt(); + unsigned playerId = myGameListSelectionModel->selectedRows().first().data(Qt::UserRole).toUInt(); PlayerInfo info(mySession->getClientPlayerInfo(playerId)); int ret = MyMessageBox::question(this, tr("PokerTH - Question"), tr("Are you sure you want to total kickban the player: \"%1\"?").arg(QString::fromUtf8(info.playerName.c_str())), QMessageBox::Yes | QMessageBox::No); if(ret == QMessageBox::Yes) { - mySession->adminActionTotalKickBan(playerId); + // TODO mySession->adminActionTotalKickBan(playerId); } } } diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index e18f7900..46cbd49b 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -549,6 +549,7 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr 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(); } diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index 43333cc3..1385724e 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -52,7 +52,7 @@ NetPacket::~NetPacket() } boost::shared_ptr -NetPacket::Create(char *data, size_t dataSize) +NetPacket::Create(const char *data, size_t dataSize) { boost::shared_ptr tmpPacket; diff --git a/src/net/common/serverbanmanager.cpp b/src/net/common/serverbanmanager.cpp index 8e511b2c..c3890317 100644 --- a/src/net/common/serverbanmanager.cpp +++ b/src/net/common/serverbanmanager.cpp @@ -30,6 +30,7 @@ *****************************************************************************/ #include +#include using namespace std; @@ -43,6 +44,15 @@ ServerBanManager::~ServerBanManager() { } +void +ServerBanManager::SetAdminPlayerIds(const std::list 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 { diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index cb65adf8..ddcc9ea0 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -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) { + 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 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 tmpPlayerData = session->GetPlayerData(); + if (GetBanManager().IsAdminPlayer(tmpPlayerData->GetDBId())) { + session->GetPlayerData()->SetRights(PLAYER_RIGHTS_ADMIN); + } CheckAvatarBlacklist(session); } else SessionError(session, ERR_NET_INVALID_PASSWORD); diff --git a/src/net/netpacket.h b/src/net/netpacket.h index 5095cab1..3a3ea994 100644 --- a/src/net/netpacket.h +++ b/src/net/netpacket.h @@ -63,7 +63,7 @@ public: NetPacket(PokerTHMessage *msg); ~NetPacket(); - static boost::shared_ptr Create(char *data, size_t dataSize); + static boost::shared_ptr Create(const char *data, size_t dataSize); const PokerTHMessage *GetMsg() const { return m_msg; diff --git a/src/net/serverbanmanager.h b/src/net/serverbanmanager.h index a733774e..5a9d7fce 100644 --- a/src/net/serverbanmanager.h +++ b/src/net/serverbanmanager.h @@ -33,6 +33,7 @@ #ifndef _SERVERBANMANAGER_H_ #define _SERVERBANMANAGER_H_ +#include #include #include #include @@ -47,6 +48,8 @@ public: ServerBanManager(boost::shared_ptr ioService); virtual ~ServerBanManager(); + void SetAdminPlayerIds(const std::list adminList); + void BanPlayerName(const std::string &playerName, unsigned durationHours = 0); void BanPlayerRegex(const std::string &playerRegex, unsigned durationHours = 0); void BanIPAddress(const std::string &ipAddress, unsigned durationHours); @@ -54,6 +57,7 @@ public: void GetBanList(std::list &list) const; void ClearBanList(); + bool IsAdminPlayer(DB_id playerId) const; bool IsPlayerBanned(const std::string &name) const; bool IsIPAddressBanned(const std::string &ipAddress) const; @@ -75,6 +79,7 @@ protected: typedef std::map RegexMap; typedef std::map IPAddressMap; typedef std::list RegexList; + typedef std::vector DBPlayerIdList; boost::shared_ptr InternalRegisterTimedBan(unsigned timerId, unsigned durationHours); void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer); @@ -87,6 +92,7 @@ private: RegexMap m_banPlayerNameMap; RegexList m_gameNameBadWordFilter; IPAddressMap m_banIPAddressMap; + DBPlayerIdList m_adminPlayers; unsigned m_curBanId; mutable boost::mutex m_banMutex; }; diff --git a/src/playerdata.cpp b/src/playerdata.cpp index 7a6a9e4a..8cd5cedf 100644 --- a/src/playerdata.cpp +++ b/src/playerdata.cpp @@ -137,6 +137,13 @@ PlayerData::GetRights() const return m_rights; } +void +PlayerData::SetRights(PlayerRights rights) +{ + boost::mutex::scoped_lock lock(m_dataMutex); + m_rights = rights; +} + bool PlayerData::IsGameAdmin() const { diff --git a/src/playerdata.h b/src/playerdata.h index 0a8b4273..6a0ed8d3 100644 --- a/src/playerdata.h +++ b/src/playerdata.h @@ -70,10 +70,11 @@ struct AvatarFile { }; struct PlayerInfo { - PlayerInfo() : ptype(PLAYER_TYPE_HUMAN), isGuest(false), hasAvatar(false), avatarType(AVATAR_FILE_TYPE_UNKNOWN) {} + PlayerInfo() : ptype(PLAYER_TYPE_HUMAN), isGuest(false), isAdmin(false), hasAvatar(false), avatarType(AVATAR_FILE_TYPE_UNKNOWN) {} std::string playerName; PlayerType ptype; bool isGuest; + bool isAdmin; std::string countryCode; bool hasAvatar; MD5Buf avatar; @@ -100,6 +101,7 @@ public: PlayerType GetType() const; void SetType(PlayerType type); PlayerRights GetRights() const; + void SetRights(PlayerRights rights); bool IsGameAdmin() const; void SetGameAdmin(bool isAdmin); unsigned GetUniqueId() const;