diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index aa49349e..ddeac811 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -301,6 +301,20 @@ ServerLobbyThread::ClearBanPlayerList() m_banPlayerNameMap.clear(); } +string +ServerLobbyThread::GetPlayerIPAddress(const std::string &playerName) const +{ + string ipAddress; + SessionWrapper session = m_sessionManager.GetSessionByPlayerName(playerName); + if (!session.sessionData.get()) + session = m_gameSessionManager.GetSessionByPlayerName(playerName); + + if (session.sessionData.get() && session.playerData.get()) + ipAddress = session.sessionData->GetClientAddr(); + + return ipAddress; +} + void ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode) { diff --git a/src/net/common/servermanager.cpp b/src/net/common/servermanager.cpp index 6a029a5a..2901e9a4 100644 --- a/src/net/common/servermanager.cpp +++ b/src/net/common/servermanager.cpp @@ -112,6 +112,20 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string & m_ircThread->SendChatMessage(nickName + ": Player \"" + playerName + "\" was not found on the server."); } } + else if (command == "showip") + { + while (msgStream.peek() == ' ') + msgStream.get(); + string playerName(msgStream.str().substr(msgStream.tellg())); + if (!playerName.empty()) + { + string ipAddress(GetLobbyThread().GetPlayerIPAddress(playerName)); + if (!ipAddress.empty()) + m_ircThread->SendChatMessage(nickName + ": The IP address of player \"" + playerName + "\" is: " + ipAddress); + else + m_ircThread->SendChatMessage(nickName + ": The IP address of player \"" + playerName + "\" is unknown."); + } + } else if (command == "nickban") { while (msgStream.peek() == ' ') @@ -123,7 +137,7 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string & m_ircThread->SendChatMessage(nickName + ": The regex \"" + playerRegex + "\" was added to the player ban list."); } } - else if (command == "listnickban") + else if (command == "listban") { list banList; GetLobbyThread().GetBanPlayerList(banList); @@ -136,10 +150,10 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string & } ostringstream banListStream; banListStream - << nickName << ": Total count of banned nicks: " << banList.size(); + << nickName << ": Total count of bans: " << banList.size(); m_ircThread->SendChatMessage(banListStream.str()); } - else if (command == "removenickban") + else if (command == "removeban") { unsigned banId = 0; msgStream >> banId; @@ -148,10 +162,10 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string & else m_ircThread->SendChatMessage(nickName + ": This nick ban does not exist."); } - else if (command == "clearnickban") + else if (command == "clearban") { GetLobbyThread().ClearBanPlayerList(); - m_ircThread->SendChatMessage(nickName + ": The player ban list was cleared."); + m_ircThread->SendChatMessage(nickName + ": All ban lists were cleared."); } else if (command == "stat") { diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index 8c9df591..30126730 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -73,6 +73,7 @@ public: bool UnBanPlayerRegex(unsigned banId); void GetBanPlayerList(std::list &list) const; void ClearBanPlayerList(); + std::string GetPlayerIPAddress(const std::string &playerName) const; void RemovePlayer(unsigned playerId, unsigned errorCode); void SendGlobalChat(const std::string &message);