fixed some problems with force_vote

This commit is contained in:
oy 2012-08-18 20:14:23 +02:00
parent 34ebab8cab
commit 8b5dddf2ba
3 changed files with 39 additions and 26 deletions

View file

@ -165,10 +165,10 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg)
{ {
CNetMsg_Sv_VoteSet *pMsg = (CNetMsg_Sv_VoteSet *)pRawMsg; CNetMsg_Sv_VoteSet *pMsg = (CNetMsg_Sv_VoteSet *)pRawMsg;
int BlockTick = m_CallvoteBlockTick; int BlockTick = m_CallvoteBlockTick;
OnReset();
char aBuf[128]; char aBuf[128];
if(pMsg->m_Timeout) if(pMsg->m_Timeout)
{ {
OnReset();
str_copy(m_aDescription, pMsg->m_pDescription, sizeof(m_aDescription)); str_copy(m_aDescription, pMsg->m_pDescription, sizeof(m_aDescription));
str_copy(m_aReason, pMsg->m_pReason, sizeof(m_aReason)); str_copy(m_aReason, pMsg->m_pReason, sizeof(m_aReason));
m_Closetime = time_get() + time_freq() * pMsg->m_Timeout; m_Closetime = time_get() + time_freq() * pMsg->m_Timeout;
@ -208,15 +208,18 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg)
m_pClient->m_pChat->AddLine(-1, 0, aBuf); m_pClient->m_pChat->AddLine(-1, 0, aBuf);
break; break;
case VOTE_END_ABORT: case VOTE_END_ABORT:
OnReset();
m_pClient->m_pChat->AddLine(-1, 0, Localize("Vote aborted")); m_pClient->m_pChat->AddLine(-1, 0, Localize("Vote aborted"));
break; break;
case VOTE_END_PASS: case VOTE_END_PASS:
OnReset();
if(pMsg->m_ClientID == -1) if(pMsg->m_ClientID == -1)
m_pClient->m_pChat->AddLine(-1, 0, Localize("Admin forced vote yes")); m_pClient->m_pChat->AddLine(-1, 0, Localize("Admin forced vote yes"));
else else
m_pClient->m_pChat->AddLine(-1, 0, Localize("Vote passed")); m_pClient->m_pChat->AddLine(-1, 0, Localize("Vote passed"));
break; break;
case VOTE_END_FAIL: case VOTE_END_FAIL:
OnReset();
if(pMsg->m_ClientID == -1) if(pMsg->m_ClientID == -1)
m_pClient->m_pChat->AddLine(-1, 0, Localize("Admin forced vote no")); m_pClient->m_pChat->AddLine(-1, 0, Localize("Admin forced vote no"));
else else

View file

@ -335,6 +335,17 @@ void CGameContext::EndVote(int Type, bool Force)
SendVoteSet(Type, -1); SendVoteSet(Type, -1);
} }
void CGameContext::ForceVote(int Type, const char *pDescription, const char *pReason)
{
CNetMsg_Sv_VoteSet Msg;
Msg.m_Type = Type;
Msg.m_Timeout = 0;
Msg.m_ClientID = -1;
Msg.m_pDescription = pDescription;
Msg.m_pReason = pReason;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, -1);
}
void CGameContext::SendVoteSet(int Type, int ToClientID) void CGameContext::SendVoteSet(int Type, int ToClientID)
{ {
CNetMsg_Sv_VoteSet Msg; CNetMsg_Sv_VoteSet Msg;
@ -348,20 +359,12 @@ void CGameContext::SendVoteSet(int Type, int ToClientID)
} }
else else
{ {
Msg.m_ClientID = m_VoteCreator;
Msg.m_Type = Type; Msg.m_Type = Type;
Msg.m_Timeout = 0; Msg.m_Timeout = 0;
if(m_VoteCreator == -1) Msg.m_ClientID = m_VoteCreator;
{
Msg.m_pDescription = m_aVoteDescription;
Msg.m_pReason = m_aVoteReason;
}
else
{
Msg.m_pDescription = ""; Msg.m_pDescription = "";
Msg.m_pReason = ""; Msg.m_pReason = "";
} }
}
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ToClientID); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ToClientID);
} }
@ -510,10 +513,10 @@ void CGameContext::OnTick()
Server()->SetRconCID(IServer::RCON_CID_VOTE); Server()->SetRconCID(IServer::RCON_CID_VOTE);
Console()->ExecuteLine(m_aVoteCommand); Console()->ExecuteLine(m_aVoteCommand);
Server()->SetRconCID(IServer::RCON_CID_SERV); Server()->SetRconCID(IServer::RCON_CID_SERV);
EndVote(VOTE_END_PASS, m_VoteEnforce==VOTE_ENFORCE_YES); if(m_VoteCreator != -1 && m_apPlayers[m_VoteCreator])
if(m_apPlayers[m_VoteCreator])
m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0;
EndVote(VOTE_END_PASS, m_VoteEnforce==VOTE_ENFORCE_YES);
} }
else if(m_VoteEnforce == VOTE_ENFORCE_NO || (m_VoteUpdate && No >= (Total+1)/2) || time_get() > m_VoteCloseTime) else if(m_VoteEnforce == VOTE_ENFORCE_NO || (m_VoteUpdate && No >= (Total+1)/2) || time_get() > m_VoteCloseTime)
EndVote(VOTE_END_FAIL, m_VoteEnforce==VOTE_ENFORCE_NO); EndVote(VOTE_END_FAIL, m_VoteEnforce==VOTE_ENFORCE_NO);
@ -725,17 +728,23 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
} }
else if(MsgID == NETMSGTYPE_CL_CALLVOTE) else if(MsgID == NETMSGTYPE_CL_CALLVOTE)
{ {
if((g_Config.m_SvSpamprotection && ((pPlayer->m_LastVoteTry && pPlayer->m_LastVoteTry+Server()->TickSpeed()*3 > Server()->Tick()) || CNetMsg_Cl_CallVote *pMsg = (CNetMsg_Cl_CallVote *)pRawMsg;
(pPlayer->m_LastVoteCall && pPlayer->m_LastVoteCall+Server()->TickSpeed()*VOTE_COOLDOWN > Server()->Tick()))) || int64 Now = Server()->Tick();
if(pMsg->m_Force)
{
if(!Server()->IsAuthed(ClientID))
return;
}
else
{
if((g_Config.m_SvSpamprotection && ((pPlayer->m_LastVoteTry && pPlayer->m_LastVoteTry+Server()->TickSpeed()*3 > Now) ||
(pPlayer->m_LastVoteCall && pPlayer->m_LastVoteCall+Server()->TickSpeed()*VOTE_COOLDOWN > Now))) ||
pPlayer->GetTeam() == TEAM_SPECTATORS || m_VoteCloseTime) pPlayer->GetTeam() == TEAM_SPECTATORS || m_VoteCloseTime)
return; return;
CNetMsg_Cl_CallVote *pMsg = (CNetMsg_Cl_CallVote *)pRawMsg;
if(pMsg->m_Force && !Server()->IsAuthed(ClientID))
return;
int64 Now = Server()->Tick();
pPlayer->m_LastVoteTry = Now; pPlayer->m_LastVoteTry = Now;
}
int Type = VOTE_UNKNOWN; int Type = VOTE_UNKNOWN;
char aDesc[VOTE_DESC_LENGTH] = {0}; char aDesc[VOTE_DESC_LENGTH] = {0};
@ -753,10 +762,10 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
str_format(aCmd, sizeof(aCmd), "%s", pOption->m_aCommand); str_format(aCmd, sizeof(aCmd), "%s", pOption->m_aCommand);
if(pMsg->m_Force) if(pMsg->m_Force)
{ {
EndVote(VOTE_START_OP, true);
Server()->SetRconCID(ClientID); Server()->SetRconCID(ClientID);
Console()->ExecuteLine(aCmd); Console()->ExecuteLine(aCmd);
Server()->SetRconCID(IServer::RCON_CID_SERV); Server()->SetRconCID(IServer::RCON_CID_SERV);
ForceVote(VOTE_START_OP, aDesc, pReason);
return; return;
} }
Type = VOTE_START_OP; Type = VOTE_START_OP;
@ -810,10 +819,10 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
str_format(aCmd, sizeof(aCmd), "set_team %d -1 %d", SpectateID, g_Config.m_SvVoteSpectateRejoindelay); str_format(aCmd, sizeof(aCmd), "set_team %d -1 %d", SpectateID, g_Config.m_SvVoteSpectateRejoindelay);
if(pMsg->m_Force) if(pMsg->m_Force)
{ {
EndVote(VOTE_START_SPEC, true);
Server()->SetRconCID(ClientID); Server()->SetRconCID(ClientID);
Console()->ExecuteLine(aCmd); Console()->ExecuteLine(aCmd);
Server()->SetRconCID(IServer::RCON_CID_SERV); Server()->SetRconCID(IServer::RCON_CID_SERV);
ForceVote(VOTE_START_SPEC, aDesc, pReason);
return; return;
} }
Type = VOTE_START_SPEC; Type = VOTE_START_SPEC;

View file

@ -92,6 +92,7 @@ public:
// voting // voting
void StartVote(int Type, const char *pDesc, const char *pCommand, const char *pReason); void StartVote(int Type, const char *pDesc, const char *pCommand, const char *pReason);
void EndVote(int Type, bool Force); void EndVote(int Type, bool Force);
void ForceVote(int Type, const char *pDescription, const char *pReason);
void SendVoteSet(int Type, int ToClientID); void SendVoteSet(int Type, int ToClientID);
void SendVoteStatus(int ClientID, int Total, int Yes, int No); void SendVoteStatus(int ClientID, int Total, int Yes, int No);
void AbortVoteOnDisconnect(int ClientID); void AbortVoteOnDisconnect(int ClientID);