Deny ask kick if the player is not/no longer present.
This commit is contained in:
@@ -125,6 +125,7 @@ using namespace std;
|
||||
#define NET_ASK_KICK_DENIED_TOO_FEW_PLAYERS 0x0001
|
||||
#define NET_ASK_KICK_DENIED_TEMPORARY 0x0002
|
||||
#define NET_ASK_KICK_DENIED_OTHER_IN_PROGRESS 0x0003
|
||||
#define NET_ASK_KICK_DENIED_INVALID_PLAYER_ID 0x0004
|
||||
#define NET_ASK_KICK_DENIED_OTHER_REASON 0xFFFF
|
||||
|
||||
// Vote types
|
||||
@@ -4526,6 +4527,9 @@ NetPacketAskKickPlayerDenied::SetData(const NetPacketAskKickPlayerDenied::Data &
|
||||
case KICK_DENIED_OTHER_IN_PROGRESS:
|
||||
tmpData->denyReason = htons(NET_ASK_KICK_DENIED_OTHER_IN_PROGRESS);
|
||||
break;
|
||||
case KICK_DENIED_INVALID_PLAYER_ID:
|
||||
tmpData->denyReason = htons(NET_ASK_KICK_DENIED_INVALID_PLAYER_ID);
|
||||
break;
|
||||
default:
|
||||
tmpData->denyReason = htons(NET_ASK_KICK_DENIED_OTHER_REASON);
|
||||
break;
|
||||
@@ -4555,6 +4559,9 @@ NetPacketAskKickPlayerDenied::GetData(NetPacketAskKickPlayerDenied::Data &outDat
|
||||
case NET_ASK_KICK_DENIED_OTHER_IN_PROGRESS:
|
||||
outData.denyReason = KICK_DENIED_OTHER_IN_PROGRESS;
|
||||
break;
|
||||
case NET_ASK_KICK_DENIED_INVALID_PLAYER_ID:
|
||||
outData.denyReason = KICK_DENIED_INVALID_PLAYER_ID;
|
||||
break;
|
||||
default:
|
||||
outData.denyReason = KICK_DENIED_OTHER_REASON;
|
||||
break;
|
||||
|
||||
@@ -220,7 +220,7 @@ ServerGameThread::VoteKickAction()
|
||||
abortPetition = true;
|
||||
}
|
||||
// 3. The kick has become invalid because the player to be kicked left.
|
||||
else if (find(playerIds.begin(), playerIds.end(), m_voteKickData->kickPlayerId) == playerIds.end())
|
||||
else if (!IsValidPlayer(m_voteKickData->kickPlayerId))
|
||||
{
|
||||
reason = PETITION_END_PLAYER_LEFT;
|
||||
abortPetition = true;
|
||||
@@ -327,34 +327,40 @@ ServerGameThread::InternalAskVoteKick(SessionWrapper byWhom, unsigned playerIdWh
|
||||
size_t numPlayers = GetSessionManager().GetPlayerIdList().size();
|
||||
if (numPlayers > 2)
|
||||
{
|
||||
// Lock the vote kick data.
|
||||
boost::mutex::scoped_lock lock(m_voteKickDataMutex);
|
||||
if (!m_voteKickData)
|
||||
// Check whether the player to be kicked exists.
|
||||
if (IsValidPlayer(playerIdWho))
|
||||
{
|
||||
// Initiate a vote kick.
|
||||
unsigned playerIdByWhom = byWhom.playerData->GetUniqueId();
|
||||
m_voteKickData.reset(new VoteKickData);
|
||||
m_voteKickData->petitionId = m_curPetitionId++;
|
||||
m_voteKickData->kickPlayerId = playerIdWho;
|
||||
m_voteKickData->numVotesToKick = static_cast<int>(ceil(numPlayers / 3. * 2.));
|
||||
m_voteKickData->timeLimitSec = timeoutSec + SERVER_KICK_TIMEOUT_ADD_DELAY_SEC;
|
||||
// Consider first vote.
|
||||
m_voteKickData->numVotesInFavourOfKicking = 1;
|
||||
m_voteKickData->votedPlayerIds.push_back(playerIdByWhom);
|
||||
// Lock the vote kick data.
|
||||
boost::mutex::scoped_lock lock(m_voteKickDataMutex);
|
||||
if (!m_voteKickData)
|
||||
{
|
||||
// Initiate a vote kick.
|
||||
unsigned playerIdByWhom = byWhom.playerData->GetUniqueId();
|
||||
m_voteKickData.reset(new VoteKickData);
|
||||
m_voteKickData->petitionId = m_curPetitionId++;
|
||||
m_voteKickData->kickPlayerId = playerIdWho;
|
||||
m_voteKickData->numVotesToKick = static_cast<int>(ceil(numPlayers / 3. * 2.));
|
||||
m_voteKickData->timeLimitSec = timeoutSec + SERVER_KICK_TIMEOUT_ADD_DELAY_SEC;
|
||||
// Consider first vote.
|
||||
m_voteKickData->numVotesInFavourOfKicking = 1;
|
||||
m_voteKickData->votedPlayerIds.push_back(playerIdByWhom);
|
||||
|
||||
boost::shared_ptr<NetPacket> startPetition(new NetPacketStartKickPlayerPetition);
|
||||
NetPacketStartKickPlayerPetition::Data startPetitionData;
|
||||
startPetitionData.petitionId = m_voteKickData->petitionId;
|
||||
startPetitionData.proposingPlayerId = playerIdByWhom;
|
||||
startPetitionData.kickPlayerId = m_voteKickData->kickPlayerId;
|
||||
startPetitionData.kickTimeoutSec = timeoutSec;
|
||||
startPetitionData.numVotesNeededToKick = m_voteKickData->numVotesToKick;
|
||||
boost::shared_ptr<NetPacket> startPetition(new NetPacketStartKickPlayerPetition);
|
||||
NetPacketStartKickPlayerPetition::Data startPetitionData;
|
||||
startPetitionData.petitionId = m_voteKickData->petitionId;
|
||||
startPetitionData.proposingPlayerId = playerIdByWhom;
|
||||
startPetitionData.kickPlayerId = m_voteKickData->kickPlayerId;
|
||||
startPetitionData.kickTimeoutSec = timeoutSec;
|
||||
startPetitionData.numVotesNeededToKick = m_voteKickData->numVotesToKick;
|
||||
|
||||
static_cast<NetPacketStartKickPlayerPetition *>(startPetition.get())->SetData(startPetitionData);
|
||||
SendToAllPlayers(startPetition, SessionData::Game);
|
||||
static_cast<NetPacketStartKickPlayerPetition *>(startPetition.get())->SetData(startPetitionData);
|
||||
SendToAllPlayers(startPetition, SessionData::Game);
|
||||
}
|
||||
else
|
||||
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_OTHER_IN_PROGRESS);
|
||||
}
|
||||
else
|
||||
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_OTHER_IN_PROGRESS);
|
||||
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_INVALID_PLAYER_ID);
|
||||
}
|
||||
else
|
||||
InternalDenyAskVoteKick(byWhom, playerIdWho, KICK_DENIED_TOO_FEW_PLAYERS);
|
||||
@@ -693,6 +699,16 @@ ServerGameThread::AssignPlayerNumbers()
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ServerGameThread::IsValidPlayer(unsigned playerId) const
|
||||
{
|
||||
bool retVal = false;
|
||||
const PlayerIdList list(GetPlayerIdList());
|
||||
if (find(list.begin(), list.end(), playerId) != list.end())
|
||||
retVal = true;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
SessionManager &
|
||||
ServerGameThread::GetSessionManager()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user