Remove players from game (without possibility to rejoin) if they did not act within a certain time. Feature is still broken, because the timer is canceled on disconnect.

This commit is contained in:
lotodore
2011-12-11 19:37:51 +00:00
parent 7bb9841f83
commit 1bf12328ee
10 changed files with 72 additions and 44 deletions
+27 -18
View File
@@ -97,15 +97,37 @@ ServerGame::AddSession(boost::shared_ptr<SessionData> session)
void
ServerGame::RemovePlayer(unsigned playerId, unsigned errorCode)
{
if (errorCode == ERR_NET_PLAYER_KICKED) {
MarkPlayerAsKicked(playerId);
}
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId);
// Only kick if the player was found.
if (tmpSession)
SessionError(tmpSession, errorCode);
}
void
ServerGame::MarkPlayerAsInactive(unsigned playerId)
{
if (m_game) {
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
if (tmpPlayer) {
tmpPlayer->setIsSessionActive(false);
}
}
}
void
ServerGame::MarkPlayerAsKicked(unsigned playerId)
{
// Mark the player as kicked in the engine.
if (m_game) {
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
if (tmpPlayer) {
// Player was kicked, so he is not allowed to rejoin.
tmpPlayer->setIsKicked(true);
tmpPlayer->setMyGuid("");
}
}
}
void
ServerGame::HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
{
@@ -375,20 +397,6 @@ ServerGame::InternalEndGame()
m_game.reset();
}
void
ServerGame::MarkPlayerAsKicked(unsigned playerId)
{
// Mark the player as kicked in the engine.
if (m_game) {
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
if (tmpPlayer) {
// Player was kicked, so he is not allowed to rejoin.
tmpPlayer->setIsKicked(true);
tmpPlayer->setMyGuid("");
}
}
}
void
ServerGame::InternalKickPlayer(unsigned playerId)
{
@@ -828,8 +836,9 @@ ServerGame::RemoveDisconnectedPlayers()
// The player should only be deactivated if rejoin is not possible.
if (tmpPlayer->isKicked() || tmpPlayer->getMyGuid().empty()) {
tmpPlayer->setMyCash(0);
tmpPlayer->setMyGuid("");
}
tmpPlayer->setIsConnected(false);
tmpPlayer->setIsSessionActive(false);
}
++i;
}