Added kick function with player name.

This commit is contained in:
lotodore
2007-10-27 18:51:53 +00:00
parent 0d0104107b
commit 8f1e5132d6
4 changed files with 33 additions and 0 deletions
+1
View File
@@ -67,6 +67,7 @@ public:
GameInfo GetGameInfo(unsigned playerId) const;
PlayerInfo GetPlayerInfo(unsigned playerId) const;
bool GetPlayerIdFromName(const std::string &playerName, unsigned &playerId) const;
ServerStats GetStatData() const;
ClientCallback &GetCallback();
+22
View File
@@ -264,6 +264,28 @@ ClientThread::GetPlayerInfo(unsigned playerId) const
return info;
}
bool
ClientThread::GetPlayerIdFromName(const string &playerName, unsigned &playerId) const
{
bool retVal = false;
boost::mutex::scoped_lock lock(m_playerInfoMapMutex);
PlayerInfoMap::const_iterator i = m_playerInfoMap.begin();
PlayerInfoMap::const_iterator end = m_playerInfoMap.end();
while (i != end)
{
if (i->second.playerName == playerName)
{
playerId = i->first;
retVal = true;
break;
}
++i;
}
return retVal;
}
ClientCallback &
ClientThread::GetCallback()
{
+9
View File
@@ -335,6 +335,15 @@ void Session::kickPlayer(unsigned playerId)
myNetClient->SendKickPlayer(playerId);
}
void Session::kickPlayer(const string &playerName)
{
if (!myNetClient)
return; // only act if client is running.
unsigned playerId;
if (myNetClient->GetPlayerIdFromName(playerName, playerId))
kickPlayer(playerId);
}
bool Session::isNetworkClientRunning() const
{
// This, and every place which calls this, is a HACK.
+1
View File
@@ -77,6 +77,7 @@ public:
void sendChatMessage(const std::string &message);
void kickPlayer(unsigned playerId);
void kickPlayer(const std::string &playerName);
bool isNetworkClientRunning() const; // TODO hack
bool isNetworkServerRunning() const; // TODO hack