Vote kick kind of working. Only the forward case - no timeout, no error handling, no display update.
This commit is contained in:
+6
-1
@@ -90,9 +90,14 @@ struct StartData
|
||||
|
||||
struct VoteKickData
|
||||
{
|
||||
VoteKickData()
|
||||
: petitionId(0), kickPlayerId(0), initialNumVotesToKick(0),
|
||||
numVotesInFavourOfKicking(0), numVotesAgainstKicking(0) {}
|
||||
unsigned petitionId;
|
||||
unsigned kickPlayerId;
|
||||
unsigned numVotesToKick;
|
||||
unsigned initialNumVotesToKick;
|
||||
unsigned numVotesInFavourOfKicking;
|
||||
unsigned numVotesAgainstKicking;
|
||||
boost::timers::portable::microsec_timer voteTimer;
|
||||
std::list<unsigned> votedPlayerIds;
|
||||
};
|
||||
|
||||
@@ -2676,8 +2676,8 @@ void gameTableImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||
else { keyUpDownChatCounter = 0; }
|
||||
|
||||
//TESTING UNIT
|
||||
if (event->key() == Qt::Key_M) { startVoteOnKick(3,60, 6); }
|
||||
if (event->key() == Qt::Key_N) { endVoteOnKick(); }
|
||||
//if (event->key() == Qt::Key_M) { startVoteOnKick(3,60, 6); }
|
||||
//if (event->key() == Qt::Key_N) { endVoteOnKick(); }
|
||||
}
|
||||
|
||||
void gameTableImpl::changePlayingMode() {
|
||||
@@ -3150,10 +3150,14 @@ void gameTableImpl::endVoteOnKick()
|
||||
|
||||
void gameTableImpl::voteOnKickYes()
|
||||
{
|
||||
changeVoteOnKickButtonsState(false);
|
||||
myStartWindow->getSession()->voteKick(true);
|
||||
}
|
||||
|
||||
void gameTableImpl::voteOnKickNo()
|
||||
{
|
||||
changeVoteOnKickButtonsState(false);
|
||||
myStartWindow->getSession()->voteKick(false);
|
||||
}
|
||||
|
||||
void gameTableImpl::startVoteOnKickTimeout()
|
||||
|
||||
@@ -282,7 +282,7 @@ public slots:
|
||||
void showMaximized ();
|
||||
void closeGameTable();
|
||||
|
||||
void startVoteOnKick(unsigned int playerId, int timeoutSec, int numVotesNeededToKick);
|
||||
void startVoteOnKick(unsigned playerId, int timeoutSec, int numVotesNeededToKick);
|
||||
void changeVoteOnKickButtonsState(bool showHide);
|
||||
void endVoteOnKick();
|
||||
void voteOnKickYes();
|
||||
|
||||
@@ -106,7 +106,7 @@ void GuiWrapper::startTimeoutAnimation(int playerNum, int timeoutSec) { myW->sig
|
||||
void GuiWrapper::stopTimeoutAnimation(int playerNum) { myW->signalStopTimeoutAnimation(playerNum); }
|
||||
|
||||
void GuiWrapper::startVoteOnKick(unsigned playerId, int timeoutSec, int numVotesNeededToKick) { myW->signalStartVoteOnKick(playerId, timeoutSec, numVotesNeededToKick); }
|
||||
void GuiWrapper::changeVoteOnKickButtonsState(bool showHide) { myW->changeVoteOnKickButtonsState(showHide); }
|
||||
void GuiWrapper::changeVoteOnKickButtonsState(bool showHide) { myW->signalChangeVoteOnKickButtonsState(showHide); }
|
||||
void GuiWrapper::refreshVotesMonitor(int currentVotes, int numVotesNeededToKick) { myW->refreshVotesMonitor(currentVotes, numVotesNeededToKick); }
|
||||
void GuiWrapper::endVoteOnKick() { myW->signalEndVoteOnKick(); }
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password);
|
||||
void SendResetTimeout();
|
||||
void SendAskKickPlayer(unsigned playerId);
|
||||
void SendVoteKick(bool doKick);
|
||||
|
||||
GameInfo GetGameInfo(unsigned gameId) const;
|
||||
PlayerInfo GetPlayerInfo(unsigned playerId) const;
|
||||
@@ -149,6 +150,8 @@ protected:
|
||||
void ModifyGameInfoRemovePlayer(unsigned gameId, unsigned playerId);
|
||||
void ClearGameInfoMap();
|
||||
|
||||
void StartPetition(unsigned petitionId, unsigned proposingPlayerId, unsigned kickPlayerId, int timeoutSec, int numVotesToKick);
|
||||
|
||||
void UpdateStatData(const ServerStats &stats);
|
||||
|
||||
bool IsSessionEstablished() const;
|
||||
@@ -189,6 +192,9 @@ private:
|
||||
unsigned m_curGameId;
|
||||
mutable boost::mutex m_curGameIdMutex;
|
||||
|
||||
unsigned m_curPetitionId;
|
||||
mutable boost::mutex m_curPetitionIdMutex;
|
||||
|
||||
AvatarDataMap m_tempAvatarMap;
|
||||
|
||||
unsigned m_curGameNum;
|
||||
|
||||
@@ -773,7 +773,8 @@ AbstractClientStateReceiving::Process(ClientThread &client)
|
||||
{
|
||||
NetPacketStartKickPlayerPetition::Data petitionData;
|
||||
tmpPacket->ToNetPacketStartKickPlayerPetition()->GetData(petitionData);
|
||||
client.GetGui().startVoteOnKick(petitionData.kickPlayerId, petitionData.kickTimeoutSec, petitionData.numVotesNeededToKick);
|
||||
client.StartPetition(petitionData.petitionId, petitionData.proposingPlayerId,
|
||||
petitionData.kickPlayerId, petitionData.kickTimeoutSec, petitionData.numVotesNeededToKick);
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketAvatarHeader())
|
||||
{
|
||||
|
||||
@@ -264,6 +264,21 @@ ClientThread::SendAskKickPlayer(unsigned playerId)
|
||||
m_outPacketList.push_back(ask);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::SendVoteKick(bool doKick)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> vote(new NetPacketVoteKickPlayer);
|
||||
NetPacketVoteKickPlayer::Data voteData;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_curPetitionIdMutex);
|
||||
voteData.petitionId = m_curPetitionId;
|
||||
}
|
||||
voteData.vote = doKick ? KICK_VOTE_IN_FAVOUR : KICK_VOTE_AGAINST;
|
||||
static_cast<NetPacketVoteKickPlayer *>(vote.get())->SetData(voteData);
|
||||
boost::mutex::scoped_lock lock(m_outPacketListMutex);
|
||||
m_outPacketList.push_back(vote);
|
||||
}
|
||||
|
||||
GameInfo
|
||||
ClientThread::GetGameInfo(unsigned gameId) const
|
||||
{
|
||||
@@ -1007,6 +1022,21 @@ ClientThread::ClearGameInfoMap()
|
||||
m_gameInfoMap.clear();
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::StartPetition(unsigned petitionId, unsigned proposingPlayerId, unsigned kickPlayerId, int timeoutSec, int numVotesToKick)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_curPetitionIdMutex);
|
||||
m_curPetitionId = petitionId;
|
||||
}
|
||||
GetGui().startVoteOnKick(kickPlayerId, timeoutSec, numVotesToKick);
|
||||
if (GetGuiPlayerId() != kickPlayerId
|
||||
&& GetGuiPlayerId() != proposingPlayerId)
|
||||
{
|
||||
GetGui().changeVoteOnKickButtonsState(true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::UpdateStatData(const ServerStats &stats)
|
||||
{
|
||||
|
||||
@@ -153,7 +153,7 @@ AbstractServerGameStateReceiving::Process(ServerGameThread &server)
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
SessionWrapper session = server.GetSessionManager().Select(RECV_TIMEOUT_MSEC);
|
||||
|
||||
if (session.sessionData.get())
|
||||
if (session.sessionData)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet;
|
||||
try
|
||||
@@ -167,7 +167,7 @@ AbstractServerGameStateReceiving::Process(ServerGameThread &server)
|
||||
}
|
||||
|
||||
// Process packet if one was received.
|
||||
if (packet.get())
|
||||
if (packet)
|
||||
{
|
||||
if (packet->IsClientActivity())
|
||||
session.sessionData->ResetActivityTimer();
|
||||
@@ -199,7 +199,7 @@ AbstractServerGameStateReceiving::Process(ServerGameThread &server)
|
||||
}
|
||||
else if (packet->ToNetPacketAskKickPlayer())
|
||||
{
|
||||
if (server.IsRunning() && session.playerData)
|
||||
if (session.playerData)
|
||||
{
|
||||
NetPacketAskKickPlayer::Data askKickData;
|
||||
packet->ToNetPacketAskKickPlayer()->GetData(askKickData);
|
||||
@@ -213,12 +213,23 @@ AbstractServerGameStateReceiving::Process(ServerGameThread &server)
|
||||
startPetitionData.proposingPlayerId = session.playerData->GetUniqueId();
|
||||
startPetitionData.kickPlayerId = voteData->kickPlayerId;
|
||||
startPetitionData.kickTimeoutSec = SERVER_VOTE_KICK_TIMEOUT_SEC;
|
||||
startPetitionData.numVotesNeededToKick = voteData->numVotesToKick;
|
||||
startPetitionData.numVotesNeededToKick = voteData->initialNumVotesToKick;
|
||||
static_cast<NetPacketStartKickPlayerPetition *>(startPetition.get())->SetData(startPetitionData);
|
||||
server.SendToAllPlayers(startPetition, SessionData::Game);
|
||||
// TODO notify first vote.
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet->ToNetPacketVoteKickPlayer())
|
||||
{
|
||||
if (session.playerData)
|
||||
{
|
||||
NetPacketVoteKickPlayer::Data voteData;
|
||||
packet->ToNetPacketVoteKickPlayer()->GetData(voteData);
|
||||
|
||||
server.InternalVoteKick(voteData.petitionId, voteData.vote);
|
||||
}
|
||||
}
|
||||
// Chat text is always allowed.
|
||||
else if (packet->ToNetPacketSendChatText())
|
||||
{
|
||||
|
||||
@@ -229,24 +229,52 @@ ServerGameThread::InternalKickPlayer(unsigned playerId)
|
||||
boost::shared_ptr<VoteKickData>
|
||||
ServerGameThread::InternalAskVoteKick(unsigned playerIdByWhom, unsigned playerIdWho)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_voteKickMapMutex);
|
||||
// TODO: Check whether player is allowed to initiate vote.
|
||||
// TODO: Check whether there are more than two players.
|
||||
boost::shared_ptr<VoteKickData> voteData;
|
||||
if (m_game)
|
||||
if (IsRunning())
|
||||
{
|
||||
voteData.reset(new VoteKickData);
|
||||
voteData->petitionId = m_curPetitionId++;
|
||||
voteData->kickPlayerId = playerIdWho;
|
||||
voteData->numVotesToKick = static_cast<unsigned>(ceil(GetCurNumberOfPlayers() / 3. * 2.));
|
||||
voteData->initialNumVotesToKick = static_cast<unsigned>(ceil(GetCurNumberOfPlayers() / 3. * 2.));
|
||||
// Consider first vote.
|
||||
voteData->numVotesToKick--;
|
||||
voteData->numVotesInFavourOfKicking = 1;
|
||||
voteData->votedPlayerIds.push_back(playerIdByWhom);
|
||||
boost::mutex::scoped_lock lock(m_voteKickMapMutex);
|
||||
m_voteKickMap.insert(VoteKickMap::value_type(voteData->petitionId, voteData));
|
||||
}
|
||||
return voteData;
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameThread::InternalVoteKick(unsigned petitionId, KickVote vote)
|
||||
{
|
||||
if (IsRunning())
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_voteKickMapMutex);
|
||||
VoteKickMap::iterator pos = m_voteKickMap.find(petitionId);
|
||||
if (pos != m_voteKickMap.end())
|
||||
{
|
||||
boost::shared_ptr<VoteKickData> curData(pos->second);
|
||||
if (vote == KICK_VOTE_IN_FAVOUR)
|
||||
{
|
||||
curData->numVotesInFavourOfKicking++;
|
||||
if (curData->numVotesInFavourOfKicking >= curData->initialNumVotesToKick)
|
||||
{
|
||||
// Perform kick.
|
||||
InternalKickPlayer(curData->kickPlayerId);
|
||||
}
|
||||
}
|
||||
else
|
||||
curData->numVotesAgainstKicking++;
|
||||
// TODO abort if no longer possible.
|
||||
// TODO remove deprecated list entries.
|
||||
// TODO error handling.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayerDataList
|
||||
ServerGameThread::GetFullPlayerDataList() const
|
||||
{
|
||||
|
||||
@@ -88,6 +88,7 @@ protected:
|
||||
|
||||
void InternalKickPlayer(unsigned playerId);
|
||||
boost::shared_ptr<VoteKickData> InternalAskVoteKick(unsigned playerIdByWhom, unsigned playerIdWho);
|
||||
void InternalVoteKick(unsigned petitionId, KickVote vote);
|
||||
|
||||
PlayerDataList GetFullPlayerDataList() const;
|
||||
|
||||
|
||||
@@ -395,6 +395,13 @@ void Session::startVoteKickPlayer(unsigned playerId)
|
||||
myNetClient->SendAskKickPlayer(playerId);
|
||||
}
|
||||
|
||||
void Session::voteKick(bool doKick)
|
||||
{
|
||||
if (!myNetClient)
|
||||
return; // only act if client is running.
|
||||
myNetClient->SendVoteKick(doKick);
|
||||
}
|
||||
|
||||
bool Session::isNetworkClientRunning() const
|
||||
{
|
||||
// This, and every place which calls this, is a HACK.
|
||||
|
||||
@@ -81,6 +81,7 @@ public:
|
||||
void kickPlayer(unsigned playerId);
|
||||
void kickPlayer(const std::string &playerName);
|
||||
void startVoteKickPlayer(unsigned playerId);
|
||||
void voteKick(bool doKick);
|
||||
|
||||
void resetNetworkTimeout();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user