Added kick function with player name.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user