More work on vote kick. Some network packets are exchanged, but still not functional.

This commit is contained in:
lotodore
2008-11-16 22:57:11 +00:00
parent f501ef1a20
commit 1cfe551f19
10 changed files with 87 additions and 6 deletions
+1
View File
@@ -68,6 +68,7 @@ public:
void SendJoinGame(unsigned gameId, const std::string &password);
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password);
void SendResetTimeout();
void SendAskKickPlayer(unsigned playerId);
GameInfo GetGameInfo(unsigned gameId) const;
PlayerInfo GetPlayerInfo(unsigned playerId) const;
+6
View File
@@ -769,6 +769,12 @@ AbstractClientStateReceiving::Process(ClientThread &client)
tmpPacket->ToNetPacketGameListAdminChanged()->GetData(adminChangedData);
client.UpdateGameInfoAdmin(adminChangedData.gameId, adminChangedData.newAdminplayerId);
}
else if (tmpPacket->ToNetPacketStartKickPlayerPetition())
{
NetPacketStartKickPlayerPetition::Data petitionData;
tmpPacket->ToNetPacketStartKickPlayerPetition()->GetData(petitionData);
// TODO
}
else if (tmpPacket->ToNetPacketAvatarHeader())
{
NetPacketAvatarHeader::Data headerData;
+11
View File
@@ -253,6 +253,17 @@ ClientThread::SendResetTimeout()
m_outPacketList.push_back(reset);
}
void
ClientThread::SendAskKickPlayer(unsigned playerId)
{
boost::shared_ptr<NetPacket> ask(new NetPacketAskKickPlayer);
NetPacketAskKickPlayer::Data askData;
askData.playerId = playerId;
static_cast<NetPacketAskKickPlayer *>(ask.get())->SetData(askData);
boost::mutex::scoped_lock lock(m_outPacketListMutex);
m_outPacketList.push_back(ask);
}
GameInfo
ClientThread::GetGameInfo(unsigned gameId) const
{
+15 -3
View File
@@ -64,6 +64,7 @@ using namespace std;
#define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60
#define SERVER_GAME_ADMIN_TIMEOUT_SEC 300 // 5 min, MUST be > SERVER_GAME_ADMIN_WARNING_REMAINING_SEC
#define SERVER_VOTE_KICK_TIMEOUT_SEC 30
// Helper functions
// TODO: these are hacks.
@@ -198,13 +199,24 @@ AbstractServerGameStateReceiving::Process(ServerGameThread &server)
}
else if (packet->ToNetPacketAskKickPlayer())
{
if (server.IsRunning())
if (server.IsRunning() && session.playerData)
{
NetPacketAskKickPlayer::Data askKickData;
packet->ToNetPacketAskKickPlayer()->GetData(askKickData);
// TODO start vote kick.
//askKickData.playerId
boost::shared_ptr<VoteKickData> voteData(server.InternalAskVoteKick(session.playerData->GetUniqueId(), askKickData.playerId));
if (voteData)
{
boost::shared_ptr<NetPacket> startPetition(new NetPacketStartKickPlayerPetition);
NetPacketStartKickPlayerPetition::Data startPetitionData;
startPetitionData.petitionId = voteData->petitionId;
startPetitionData.proposingPlayerId = session.playerData->GetUniqueId();
startPetitionData.kickPlayerId = voteData->kickPlayerId;
startPetitionData.kickTimeoutSec = SERVER_VOTE_KICK_TIMEOUT_SEC;
startPetitionData.numVotesNeededToKick = voteData->numVotesToKick;
static_cast<NetPacketStartKickPlayerPetition *>(startPetition.get())->SetData(startPetitionData);
server.GetSender().Send(session.sessionData, startPetition);
}
}
}
// Chat text is always allowed.
+22 -1
View File
@@ -37,7 +37,7 @@ using namespace std;
ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig)
: m_adminPlayerId(adminPlayerId), m_lobbyThread(lobbyThread), m_gui(gui),
m_gameData(gameData), m_id(id), m_name(name), m_password(pwd), m_playerConfig(playerConfig),
m_curState(NULL), m_gameNum(1),
m_curState(NULL), m_gameNum(1), m_curPetitionId(1),
m_stateTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start),
m_stateTimerFlag(0)
{
@@ -226,6 +226,27 @@ ServerGameThread::InternalKickPlayer(unsigned playerId)
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_KICKED);
}
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)
{
voteData.reset(new VoteKickData);
voteData->petitionId = m_curPetitionId++;
voteData->kickPlayerId = playerIdWho;
voteData->numVotesToKick = static_cast<unsigned>(ceil(GetCurNumberOfPlayers() / 3. * 2.));
// Consider first vote.
voteData->numVotesToKick--;
voteData->votedPlayerIds.push_back(playerIdByWhom);
m_voteKickMap.insert(VoteKickMap::value_type(voteData->petitionId, voteData));
}
return voteData;
}
PlayerDataList
ServerGameThread::GetFullPlayerDataList() const
{
+6
View File
@@ -77,6 +77,7 @@ public:
protected:
typedef std::deque<SessionWrapper> SessionQueue;
typedef std::map<unsigned, boost::shared_ptr<VoteKickData> > VoteKickMap;
// Main function of the thread.
virtual void Main();
@@ -86,6 +87,7 @@ protected:
void ResetGame();
void InternalKickPlayer(unsigned playerId);
boost::shared_ptr<VoteKickData> InternalAskVoteKick(unsigned playerIdByWhom, unsigned playerIdWho);
PlayerDataList GetFullPlayerDataList() const;
@@ -140,6 +142,9 @@ private:
unsigned m_adminPlayerId;
mutable boost::mutex m_adminPlayerIdMutex;
VoteKickMap m_voteKickMap;
mutable boost::mutex m_voteKickMapMutex;
ServerLobbyThread &m_lobbyThread;
boost::shared_ptr<ReceiverHelper> m_receiver;
GuiInterface &m_gui;
@@ -153,6 +158,7 @@ private:
ConfigFile *m_playerConfig;
ServerGameState *m_curState;
unsigned m_gameNum;
unsigned m_curPetitionId;
boost::timers::portable::microsec_timer m_stateTimer;
unsigned m_stateTimerFlag;