mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #1058
1058: Add /pausevoted and /specvoted r=heinrich5991 a=def- - Also fix /pause and /spec with name parameter a bit - Move out common code between pause/spec
This commit is contained in:
commit
e64919ddcb
|
@ -269,17 +269,11 @@ void CGameContext::ConRules(IConsole::IResult *pResult, void *pUserData)
|
|||
}
|
||||
}
|
||||
|
||||
void CGameContext::ConToggleSpec(IConsole::IResult *pResult, void *pUserData)
|
||||
void ToggleSpecPause(IConsole::IResult *pResult, void *pUserData, int PauseType)
|
||||
{
|
||||
if(!CheckClientID(pResult->m_ClientID))
|
||||
return;
|
||||
|
||||
if(!g_Config.m_SvPauseable)
|
||||
{
|
||||
ConTogglePause(pResult, pUserData);
|
||||
return;
|
||||
}
|
||||
|
||||
CGameContext *pSelf = (CGameContext *) pUserData;
|
||||
IServer* pServ = pSelf->Server();
|
||||
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
|
||||
|
@ -287,66 +281,81 @@ void CGameContext::ConToggleSpec(IConsole::IResult *pResult, void *pUserData)
|
|||
return;
|
||||
|
||||
int PauseState = pPlayer->IsPaused();
|
||||
if(PauseState <= 0)
|
||||
{
|
||||
if(pResult->NumArguments() > 0)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_SPEC, false);
|
||||
pPlayer->SpectatePlayerName(pResult->GetString(0));
|
||||
}
|
||||
else if(-PauseState == CPlayer::PAUSE_SPEC)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_NONE, false);
|
||||
}
|
||||
else if(-PauseState != CPlayer::PAUSE_SPEC)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_SPEC, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
if(PauseState > 0)
|
||||
{
|
||||
char aBuf[128];
|
||||
str_format(aBuf, sizeof(aBuf), "You are force-paused for %d seconds.", (PauseState - pServ->Tick()) / pServ->TickSpeed());
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "spec", aBuf);
|
||||
return;
|
||||
}
|
||||
else if(pResult->NumArguments() > 0)
|
||||
{
|
||||
if(-PauseState == PauseType && pPlayer->m_SpectatorID != pResult->m_ClientID && pServ->ClientIngame(pPlayer->m_SpectatorID) && !str_comp(pServ->ClientName(pPlayer->m_SpectatorID), pResult->GetString(0)))
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_NONE, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
pPlayer->Pause(PauseType, false);
|
||||
pPlayer->SpectatePlayerName(pResult->GetString(0));
|
||||
}
|
||||
}
|
||||
else if(-PauseState == PauseType)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_NONE, false);
|
||||
}
|
||||
else if(-PauseState != PauseType)
|
||||
{
|
||||
pPlayer->Pause(PauseType, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleSpecPauseVoted(IConsole::IResult *pResult, void *pUserData, int PauseType)
|
||||
{
|
||||
if(!CheckClientID(pResult->m_ClientID))
|
||||
return;
|
||||
|
||||
CGameContext *pSelf = (CGameContext *) pUserData;
|
||||
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
|
||||
if(!pPlayer)
|
||||
return;
|
||||
|
||||
int PauseState = pPlayer->IsPaused();
|
||||
if(PauseState > 0)
|
||||
{
|
||||
IServer* pServ = pSelf->Server();
|
||||
char aBuf[128];
|
||||
str_format(aBuf, sizeof(aBuf), "You are force-paused for %d seconds.", (PauseState - pServ->Tick()) / pServ->TickSpeed());
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "spec", aBuf);
|
||||
}
|
||||
else if(!pSelf->m_VoteCloseTime || (!pSelf->m_VoteKick && !pSelf->m_VoteSpec) || (pPlayer->IsPaused() && pPlayer->m_SpectatorID == pSelf->m_VoteVictim) || pResult->m_ClientID == pSelf->m_VoteVictim)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_NONE, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
pPlayer->Pause(PauseType, false);
|
||||
pPlayer->m_SpectatorID = pSelf->m_VoteVictim;
|
||||
}
|
||||
}
|
||||
|
||||
void CGameContext::ConToggleSpec(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
ToggleSpecPause(pResult, pUserData, g_Config.m_SvPauseable ? CPlayer::PAUSE_SPEC : CPlayer::PAUSE_PAUSED);
|
||||
}
|
||||
|
||||
void CGameContext::ConToggleSpecVoted(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
ToggleSpecPauseVoted(pResult, pUserData, g_Config.m_SvPauseable ? CPlayer::PAUSE_SPEC : CPlayer::PAUSE_PAUSED);
|
||||
}
|
||||
|
||||
void CGameContext::ConTogglePause(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
if(!CheckClientID(pResult->m_ClientID))
|
||||
return;
|
||||
ToggleSpecPause(pResult, pUserData, CPlayer::PAUSE_PAUSED);
|
||||
}
|
||||
|
||||
CGameContext *pSelf = (CGameContext *) pUserData;
|
||||
IServer* pServ = pSelf->Server();
|
||||
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
|
||||
if(!pPlayer)
|
||||
return;
|
||||
|
||||
int PauseState = pPlayer->IsPaused();
|
||||
if(PauseState <= 0)
|
||||
{
|
||||
if(pResult->NumArguments() > 0)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_PAUSED, false);
|
||||
pPlayer->SpectatePlayerName(pResult->GetString(0));
|
||||
}
|
||||
else if(-PauseState == CPlayer::PAUSE_PAUSED)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_NONE, false);
|
||||
}
|
||||
else if(-PauseState != CPlayer::PAUSE_PAUSED)
|
||||
{
|
||||
pPlayer->Pause(CPlayer::PAUSE_PAUSED, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char aBuf[128];
|
||||
str_format(aBuf, sizeof(aBuf), "You are force-paused for %d seconds.", (PauseState - pServ->Tick()) / pServ->TickSpeed());
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "spec", aBuf);
|
||||
return;
|
||||
}
|
||||
void CGameContext::ConTogglePauseVoted(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
ToggleSpecPauseVoted(pResult, pUserData, CPlayer::PAUSE_PAUSED);
|
||||
}
|
||||
|
||||
void CGameContext::ConTeamTop5(IConsole::IResult *pResult, void *pUserData)
|
||||
|
|
|
@ -19,6 +19,8 @@ CHAT_COMMAND("c", "r[message]", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_NONTEEHISTOR
|
|||
CHAT_COMMAND("converse", "r[message]", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_NONTEEHISTORIC, ConConverse, this, "Converse with the last person you whispered to (private message)");
|
||||
CHAT_COMMAND("pause", "?r[player name]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTogglePause, this, "Toggles pause")
|
||||
CHAT_COMMAND("spec", "?r[player name]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConToggleSpec, this, "Toggles spec (if not available behaves as /pause)")
|
||||
CHAT_COMMAND("pausevoted", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTogglePauseVoted, this, "Toggles pause on the currently voted player")
|
||||
CHAT_COMMAND("specvoted", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConToggleSpecVoted, this, "Toggles spec on the currently voted player)")
|
||||
CHAT_COMMAND("dnd", "", CFGFLAG_CHAT|CFGFLAG_SERVER|CFGFLAG_NONTEEHISTORIC, ConDND, this, "Toggle Do Not Disturb (no chat and server messages)")
|
||||
CHAT_COMMAND("mapinfo", "?r[map]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConMapInfo, this, "Show info about the map with name r gives (current map by default)")
|
||||
CHAT_COMMAND("timeout", "s[code]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTimeout, this, "Set timeout protection code s")
|
||||
|
|
|
@ -1487,6 +1487,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
|||
m_apPlayers[ClientID]->m_Last_KickVote = time_get();
|
||||
m_VoteKick = true;
|
||||
m_VoteSpec = false;
|
||||
m_VoteVictim = KickID;
|
||||
}
|
||||
else if(str_comp_nocase(pMsg->m_Type, "spectate") == 0)
|
||||
{
|
||||
|
@ -1533,6 +1534,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
|||
}
|
||||
m_VoteKick = false;
|
||||
m_VoteSpec = true;
|
||||
m_VoteVictim = SpectateID;
|
||||
}
|
||||
|
||||
if(aCmd[0] && str_comp(aCmd, "info") != 0)
|
||||
|
|
|
@ -300,7 +300,9 @@ private:
|
|||
static void ConRules(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConKill(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConTogglePause(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConTogglePauseVoted(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConToggleSpec(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConToggleSpecVoted(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConForcePause(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConTeamTop5(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConTop5(IConsole::IResult *pResult, void *pUserData);
|
||||
|
@ -374,6 +376,7 @@ public:
|
|||
class IScore *Score() { return m_pScore; }
|
||||
bool m_VoteKick;
|
||||
bool m_VoteSpec;
|
||||
int m_VoteVictim;
|
||||
enum
|
||||
{
|
||||
VOTE_ENFORCE_NO_ADMIN = VOTE_ENFORCE_YES + 1,
|
||||
|
|
Loading…
Reference in a new issue