From 79fedff12d500127143661b5e11b6f582fbd3b4f Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Sun, 21 Jan 2018 01:32:55 +0100 Subject: [PATCH] add /modhelp chat command --- src/game/server/ddracechat.cpp | 39 ++++++++++++++++++++++++++++++++++ src/game/server/ddracechat.h | 2 ++ src/game/server/gamecontext.h | 1 + src/game/server/player.cpp | 1 + src/game/server/player.h | 1 + src/game/variables.h | 2 ++ 6 files changed, 46 insertions(+) diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 096d05146..463f2e877 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -1363,6 +1363,45 @@ void CGameContext::ConProtectedKill(IConsole::IResult *pResult, void *pUserData) //pSelf->SendChatTarget(pResult->m_ClientID, aBuf); } } + +void CGameContext::ConModHelp(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *) pUserData; + + if (!CheckClientID(pResult->m_ClientID)) + return; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if (!pPlayer) + return; + + if(pPlayer->m_ModHelpTick > pSelf->Server()->Tick()) + { + char aBuf[126]; + str_format(aBuf, sizeof(aBuf), "You must wait %d seconds to execute this command again.", + (pPlayer->m_ModHelpTick - pSelf->Server()->Tick()) / pSelf->Server()->TickSpeed()); + pSelf->SendChatTarget(pResult->m_ClientID, aBuf); + return; + } + + pPlayer->m_ModHelpTick = pSelf->Server()->Tick() + g_Config.m_SvModHelpDelay * pSelf->Server()->TickSpeed(); + + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "Moderator help is requested by %s (ID: %d):", + pSelf->Server()->ClientName(pResult->m_ClientID), + pResult->m_ClientID); + + // Send the request to all authed clients. + for ( int i = 0; i < MAX_CLIENTS; i++ ) + { + if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->m_Authed) + { + pSelf->SendChatTarget(pSelf->m_apPlayers[i]->GetCID(), aBuf); + pSelf->SendChatTarget(pSelf->m_apPlayers[i]->GetCID(), pResult->GetString(0)); + } + } +} + #if defined(CONF_SQL) void CGameContext::ConPoints(IConsole::IResult *pResult, void *pUserData) { diff --git a/src/game/server/ddracechat.h b/src/game/server/ddracechat.h index 17db62d19..45134ba21 100644 --- a/src/game/server/ddracechat.h +++ b/src/game/server/ddracechat.h @@ -47,6 +47,8 @@ CHAT_COMMAND("rescue", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConRescue, this, "Telepo CHAT_COMMAND("kill", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConProtectedKill, this, "Kill yourself") +CHAT_COMMAND("modhelp", "r[message]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConModHelp, this, "Request the help of a moderator with a description of the problem") + #if defined(CONF_SQL) CHAT_COMMAND("times", "?s[player name] ?i[number of times to skip]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTimes, this, "/times ?s?i shows last 5 times of the server or of a player beginning with name s starting with time i (i = 1 by default)") CHAT_COMMAND("points", "?r[player name]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConPoints, this, "Shows the global points of a player beginning with name r (your rank by default)") diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index c88c17512..569864b96 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -343,6 +343,7 @@ private: static void ConUnmute(IConsole::IResult *pResult, void *pUserData); static void ConMutes(IConsole::IResult *pResult, void *pUserData); static void ConModerate(IConsole::IResult *pResult, void *pUserData); + static void ConModHelp(IConsole::IResult *pResult, void *pUserData); static void ConList(IConsole::IResult *pResult, void *pUserData); static void ConSetDDRTeam(IConsole::IResult *pResult, void *pUserData); diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index aba398ed0..e00aafbee 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -70,6 +70,7 @@ void CPlayer::Reset() m_LastWhisperTo = -1; m_LastSetSpectatorMode = 0; m_TimeoutCode[0] = '\0'; + m_ModHelpTick = 0; m_TuneZone = 0; m_TuneZoneOld = m_TuneZone; diff --git a/src/game/server/player.h b/src/game/server/player.h index 60ce2fce6..14e97983e 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -177,6 +177,7 @@ public: int m_ChatScore; bool m_Moderating; + int m_ModHelpTick; bool AfkTimer(int new_target_x, int new_target_y); //returns true if kicked void AfkVoteTimer(CNetObj_PlayerInput *NewTarget); diff --git a/src/game/variables.h b/src/game/variables.h index 671e1b580..7abfa9d92 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -164,6 +164,8 @@ MACRO_CONFIG_INT(SvSendVotesPerTick, sv_send_votes_per_tick, 5, 1, 15, CFGFLAG_S MACRO_CONFIG_INT(SvRescue, sv_rescue, 0, 0, 1, CFGFLAG_SERVER, "Allow /rescue command so players can teleport themselves out of freeze") MACRO_CONFIG_INT(SvRescueDelay, sv_rescue_delay, 5, 0, 1000, CFGFLAG_SERVER, "Number of seconds inbetween two rescues") +MACRO_CONFIG_INT(SvModHelpDelay, sv_modhelp_delay, 60, 0, 0, CFGFLAG_SERVER, "Number of seconds to wait before executing /modhelp again") + // debug #ifdef CONF_DEBUG // this one can crash the server if not used correctly MACRO_CONFIG_INT(DbgDummies, dbg_dummies, 0, 0, 15, CFGFLAG_SERVER, "")