Allow kicking of computer players.
This commit is contained in:
@@ -310,6 +310,12 @@ ServerGameThread::InternalKickPlayer(unsigned playerId)
|
|||||||
// Only kick if the player was found.
|
// Only kick if the player was found.
|
||||||
if (tmpSession.sessionData.get())
|
if (tmpSession.sessionData.get())
|
||||||
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_KICKED);
|
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_KICKED);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boost::shared_ptr<PlayerData> tmpData(RemoveComputerPlayer(playerId));
|
||||||
|
if (tmpData)
|
||||||
|
RemovePlayerData(tmpData, NTF_NET_REMOVED_KICKED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -507,6 +513,45 @@ ServerGameThread::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
|
|||||||
GetLobbyThread().AddComputerPlayer(player);
|
GetLobbyThread().AddComputerPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<PlayerData>
|
||||||
|
ServerGameThread::RemoveComputerPlayer(unsigned playerId)
|
||||||
|
{
|
||||||
|
boost::shared_ptr<PlayerData> tmpPlayer;
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
||||||
|
PlayerDataList::iterator i = m_computerPlayerList.begin();
|
||||||
|
PlayerDataList::iterator end = m_computerPlayerList.end();
|
||||||
|
while (i != end)
|
||||||
|
{
|
||||||
|
if ((*i)->GetUniqueId() == playerId)
|
||||||
|
{
|
||||||
|
tmpPlayer = *i;
|
||||||
|
m_computerPlayerList.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GetLobbyThread().RemoveComputerPlayer(tmpPlayer);
|
||||||
|
return tmpPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ServerGameThread::IsComputerPlayerActive(unsigned playerId) const
|
||||||
|
{
|
||||||
|
bool retVal = false;
|
||||||
|
boost::mutex::scoped_lock lock(m_computerPlayerListMutex);
|
||||||
|
PlayerDataList::const_iterator i = m_computerPlayerList.begin();
|
||||||
|
PlayerDataList::const_iterator end = m_computerPlayerList.end();
|
||||||
|
while (i != end)
|
||||||
|
{
|
||||||
|
if ((*i)->GetUniqueId() == playerId)
|
||||||
|
retVal = true;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerGameThread::ResetComputerPlayerList()
|
ServerGameThread::ResetComputerPlayerList()
|
||||||
{
|
{
|
||||||
@@ -613,7 +658,8 @@ ServerGameThread::RemoveDisconnectedPlayers()
|
|||||||
while (i != end)
|
while (i != end)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
||||||
if (!GetSessionManager().IsPlayerConnected(tmpPlayer->getMyUniqueID()) && tmpPlayer->getMyType() == PLAYER_TYPE_HUMAN)
|
if ((tmpPlayer->getMyType() == PLAYER_TYPE_HUMAN && !GetSessionManager().IsPlayerConnected(tmpPlayer->getMyUniqueID()))
|
||||||
|
|| (tmpPlayer->getMyType() == PLAYER_TYPE_COMPUTER && !IsComputerPlayerActive(tmpPlayer->getMyUniqueID())))
|
||||||
{
|
{
|
||||||
// Setting player cash to 0 will deactivate the player.
|
// Setting player cash to 0 will deactivate the player.
|
||||||
tmpPlayer->setMyCash(0);
|
tmpPlayer->setMyCash(0);
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ protected:
|
|||||||
PlayerDataList GetFullPlayerDataList() const;
|
PlayerDataList GetFullPlayerDataList() const;
|
||||||
|
|
||||||
void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
|
void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
|
||||||
|
boost::shared_ptr<PlayerData> RemoveComputerPlayer(unsigned playerId);
|
||||||
|
bool IsComputerPlayerActive(unsigned playerId) const;
|
||||||
void ResetComputerPlayerList();
|
void ResetComputerPlayerList();
|
||||||
|
|
||||||
void GracefulRemoveSession(SessionWrapper session, int reason);
|
void GracefulRemoveSession(SessionWrapper session, int reason);
|
||||||
|
|||||||
Reference in New Issue
Block a user