Implementing packet validation for new packets and client side game removal for admin players.

This commit is contained in:
lotodore
2013-02-24 23:04:02 +01:00
parent 8740c3fb7a
commit 19f27a890c
9 changed files with 54 additions and 4 deletions
@@ -2202,8 +2202,8 @@ void gameLobbyDialogImpl::adminActionCloseGame()
int ret = MyMessageBox::question(this, tr("PokerTH - Question"), 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); 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) { if (ret == QMessageBox::Yes) {
//TODO mySession->adminActionCloseGame(gameId); mySession->adminActionCloseGame(gameId);
} }
} }
} }
+1
View File
@@ -98,6 +98,7 @@ public:
void SendRejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason); void SendRejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason);
void SendReportAvatar(unsigned reportedPlayerId, const std::string &avatarHash); void SendReportAvatar(unsigned reportedPlayerId, const std::string &avatarHash);
void SendReportGameName(unsigned reportedGameId); void SendReportGameName(unsigned reportedGameId);
void SendAdminRemoveGame(unsigned removeGameId);
void StartAsyncRead(); void StartAsyncRead();
virtual void CloseSession(boost::shared_ptr<SessionData> session); virtual void CloseSession(boost::shared_ptr<SessionData> session);
+10
View File
@@ -376,6 +376,16 @@ ClientThread::SendReportGameName(unsigned reportedGameId)
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
} }
void
ClientThread::SendAdminRemoveGame(unsigned removeGameId)
{
boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_AdminRemoveGameMessage);
AdminRemoveGameMessage *netRemove = packet->GetMsg()->mutable_adminremovegamemessage();
netRemove->set_removegameid(removeGameId);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
}
void void
ClientThread::StartAsyncRead() ClientThread::StartAsyncRead()
{ {
+28
View File
@@ -128,6 +128,8 @@ NetPacketValidator::NetPacketValidator()
m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_ReportGameMessage, ValidateReportGameMessage)); m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_ReportGameMessage, ValidateReportGameMessage));
m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_ReportGameAckMessage, ValidateReportGameAckMessage)); m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_ReportGameAckMessage, ValidateReportGameAckMessage));
m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_ErrorMessage, ValidateErrorMessage)); m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_ErrorMessage, ValidateErrorMessage));
m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_AdminRemoveGameMessage, ValidateAdminRemoveGameMessage));
m_validationMap.insert(make_pair(PokerTHMessage_PokerTHMessageType_Type_AdminBanPlayerMessage, ValidateAdminBanPlayerMessage));
} }
bool bool
@@ -1145,6 +1147,32 @@ NetPacketValidator::ValidateErrorMessage(const NetPacket &packet)
return retVal; return retVal;
} }
bool
NetPacketValidator::ValidateAdminRemoveGameMessage(const NetPacket &packet)
{
bool retVal = false;
if (packet.GetMsg()->has_adminremovegamemessage()) {
const AdminRemoveGameMessage &msg = packet.GetMsg()->adminremovegamemessage();
if (msg.removegameid() != 0) {
retVal = true;
}
}
return retVal;
}
bool
NetPacketValidator::ValidateAdminBanPlayerMessage(const NetPacket &packet)
{
bool retVal = false;
if (packet.GetMsg()->has_adminbanplayermessage()) {
const AdminBanPlayerMessage &msg = packet.GetMsg()->adminbanplayermessage();
if (msg.banplayerid() != 0) {
retVal = true;
}
}
return retVal;
}
bool bool
NetPacketValidator::ValidateGameInfo(const NetGameInfo &gameInfo) NetPacketValidator::ValidateGameInfo(const NetGameInfo &gameInfo)
{ {
+1 -1
View File
@@ -45,7 +45,7 @@ ServerBanManager::~ServerBanManager()
} }
void void
ServerBanManager::SetAdminPlayerIds(const std::list<DB_id> adminList) ServerBanManager::SetAdminPlayerIds(const std::list<DB_id> &adminList)
{ {
boost::mutex::scoped_lock lock(m_banMutex); boost::mutex::scoped_lock lock(m_banMutex);
m_adminPlayers.resize(adminList.size()); m_adminPlayers.resize(adminList.size());
+2
View File
@@ -119,6 +119,8 @@ protected:
static bool ValidateReportGameMessage(const NetPacket &packet); static bool ValidateReportGameMessage(const NetPacket &packet);
static bool ValidateReportGameAckMessage(const NetPacket &packet); static bool ValidateReportGameAckMessage(const NetPacket &packet);
static bool ValidateErrorMessage(const NetPacket &packet); static bool ValidateErrorMessage(const NetPacket &packet);
static bool ValidateAdminRemoveGameMessage(const NetPacket &packet);
static bool ValidateAdminBanPlayerMessage(const NetPacket &packet);
static bool ValidateGameInfo(const NetGameInfo &gameInfo); static bool ValidateGameInfo(const NetGameInfo &gameInfo);
+1 -1
View File
@@ -48,7 +48,7 @@ public:
ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService); ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService);
virtual ~ServerBanManager(); virtual ~ServerBanManager();
void SetAdminPlayerIds(const std::list<DB_id> adminList); void SetAdminPlayerIds(const std::list<DB_id> &adminList);
void BanPlayerName(const std::string &playerName, unsigned durationHours = 0); void BanPlayerName(const std::string &playerName, unsigned durationHours = 0);
void BanPlayerRegex(const std::string &playerRegex, unsigned durationHours = 0); void BanPlayerRegex(const std::string &playerRegex, unsigned durationHours = 0);
+7
View File
@@ -420,6 +420,13 @@ void Session::resetNetworkTimeout()
myNetClient->SendResetTimeout(); myNetClient->SendResetTimeout();
} }
void Session::adminActionCloseGame(unsigned gameId)
{
if (!myNetClient)
return; // only act if client is running.
myNetClient->SendAdminRemoveGame(gameId);
}
void Session::kickPlayer(const string &playerName) void Session::kickPlayer(const string &playerName)
{ {
if (!myNetClient) if (!myNetClient)
+2
View File
@@ -116,6 +116,8 @@ public:
void resetNetworkTimeout(); void resetNetworkTimeout();
void adminActionCloseGame(unsigned gameId);
bool isNetworkClientRunning() const; // TODO hack bool isNetworkClientRunning() const; // TODO hack
bool isNetworkServerRunning() const; // TODO hack bool isNetworkServerRunning() const; // TODO hack