3066: Disallow more commands with testing mode r=def- a=heinrich5991

Also show some useful error message

Supersedes #2778.

Co-authored-by: Andrii <bannzay3@gmail.com>
Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
This commit is contained in:
bors[bot] 2020-10-11 14:39:29 +00:00 committed by GitHub
commit 7e84e1ef43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 29 deletions

View file

@ -2650,20 +2650,6 @@ int CServer::Run()
return ErrorShutdown();
}
void CServer::ConTestingCommands(CConsole::IResult *pResult, void *pUser)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "Value: %d", g_Config.m_SvTestingCommands);
((CConsole *)pUser)->Print(CConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
}
void CServer::ConRescue(CConsole::IResult *pResult, void *pUser)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "Value: %d", g_Config.m_SvRescue);
((CConsole *)pUser)->Print(CConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
}
void CServer::ConKick(IConsole::IResult *pResult, void *pUser)
{
if(pResult->NumArguments() > 1)
@ -3531,9 +3517,6 @@ int main(int argc, const char **argv) // ignore_convention
if(argc > 1) // ignore_convention
pConsole->ParseArguments(argc - 1, &argv[1]); // ignore_convention
pConsole->Register("sv_test_cmds", "", CFGFLAG_SERVER, CServer::ConTestingCommands, pConsole, "Turns testing commands aka cheats on/off (setting only works in initial config)");
pConsole->Register("sv_rescue", "", CFGFLAG_SERVER, CServer::ConRescue, pConsole, "Allow /rescue command so players can teleport themselves out of freeze (setting only works in initial config)");
pEngine->InitLogfile();
// run the server

View file

@ -31,14 +31,15 @@ enum
CFGFLAG_STORE = 1 << 3,
CFGFLAG_MASTER = 1 << 4,
CFGFLAG_ECON = 1 << 5,
// DDRace
// DDRace
CMDFLAG_TEST = 1 << 6,
CFGFLAG_CHAT = 1 << 7,
CFGFLAG_GAME = 1 << 8,
CFGFLAG_NONTEEHISTORIC = 1 << 9,
CFGFLAG_COLLIGHT = 1 << 10,
CFGFLAG_COLALPHA = 1 << 11,
CFGFLAG_READONLY = 1 << 12,
};
#endif

View file

@ -187,7 +187,7 @@ MACRO_CONFIG_INT(SvReservedSlots, sv_reserved_slots, 0, 0, 16, CFGFLAG_SERVER, "
MACRO_CONFIG_STR(SvReservedSlotsPass, sv_reserved_slots_pass, 32, "", CFGFLAG_SERVER, "The password that is required to use a reserved slot")
MACRO_CONFIG_INT(SvHit, sv_hit, 1, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAME, "Whether players can hammer/grenade/laser each other or not")
MACRO_CONFIG_INT(SvEndlessDrag, sv_endless_drag, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAME, "Turns endless hooking on/off")
MACRO_CONFIG_INT(SvTestingCommands, sv_test_cmds, 0, 0, 1, CFGFLAG_SERVER, "Turns testing commands aka cheats on/off (setting only works in initial config)")
MACRO_CONFIG_INT(SvTestingCommands, sv_test_cmds, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_READONLY, "Turns testing commands aka cheats on/off (setting only works in initial config)")
MACRO_CONFIG_INT(SvFreezeDelay, sv_freeze_delay, 3, 1, 30, CFGFLAG_SERVER | CFGFLAG_GAME, "How many seconds the players will remain frozen (applies to all except delayed freeze in switch layer & deepfreeze)")
MACRO_CONFIG_INT(ClDDRaceBindsSet, cl_race_binds_set, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "What level the DDRace binds are set to (this is automated, you don't need to use this)")
MACRO_CONFIG_INT(SvEndlessSuperHook, sv_endless_super_hook, 0, 0, 1, CFGFLAG_SERVER, "Endless hook for super players on/off")

View file

@ -477,8 +477,27 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, bo
}
else
{
if(pCommand->m_Flags & CMDFLAG_TEST && !g_Config.m_SvTestingCommands)
if(ClientID != IConsole::CLIENT_ID_GAME && (pCommand->m_Flags & CFGFLAG_GAME || pCommand->m_Flags & CMDFLAG_TEST))
{
if(g_Config.m_SvTestingCommands)
{
m_Cheated = true;
}
else
{
char aBuf[256];
if(pCommand->m_Flags & CFGFLAG_GAME)
{
str_format(aBuf, sizeof(aBuf), "Cannot execute game command '%s', put it into the map config or start the server with 'sv_test_cmds 1' to enable it", Result.m_pCommand);
}
else
{
str_format(aBuf, sizeof(aBuf), "Cannot execute testing command '%s', start the server with 'sv_test_cmds 1' to enable it", Result.m_pCommand);
}
Print(OUTPUT_LEVEL_STANDARD, "console", aBuf);
return;
}
}
if(m_pfnTeeHistorianCommandCallback && !(pCommand->m_Flags & CFGFLAG_NONTEEHISTORIC))
{
@ -500,9 +519,6 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, bo
{
pCommand->m_pfnCallback(&Result, pCommand->m_pUserData);
}
if(pCommand->m_Flags & CMDFLAG_TEST)
m_Cheated = true;
}
}
}
@ -705,6 +721,7 @@ struct CIntVariableData
int m_Min;
int m_Max;
int m_OldValue;
bool m_Readonly;
};
struct CColVariableData
@ -730,6 +747,12 @@ static void IntVariableCommand(IConsole::IResult *pResult, void *pUserData)
if(pResult->NumArguments())
{
if(pData->m_Readonly && pResult->m_ClientID >= 0)
{
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", "This is read-only variable");
return;
}
int Val = pResult->GetInteger(0);
// do clamping
@ -954,7 +977,7 @@ CConsole::CConsole(int FlagMask)
// TODO: this should disappear
#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Flags, Desc) \
{ \
static CIntVariableData Data = {this, &g_Config.m_##Name, Min, Max, Def}; \
static CIntVariableData Data = {this, &g_Config.m_##Name, Min, Max, Def, static_cast<bool>((Flags)&CFGFLAG_READONLY)}; \
Register(#ScriptName, "?i", Flags, IntVariableCommand, &Data, Desc); \
}

View file

@ -2950,13 +2950,13 @@ void CGameContext::OnConsoleInit()
Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneParam, this, "Tune variable to value");
Console()->Register("toggle_tune", "s[tuning] i[value 1] i[value 2]", CFGFLAG_SERVER | CFGFLAG_GAME, ConToggleTuneParam, this, "Toggle tune variable");
Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "Reset tuning");
Console()->Register("tune_reset", "", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneReset, this, "Reset tuning");
Console()->Register("tune_dump", "", CFGFLAG_SERVER, ConTuneDump, this, "Dump tuning");
Console()->Register("tune_zone", "i[zone] s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneZone, this, "Tune in zone a variable to value");
Console()->Register("tune_zone_dump", "i[zone]", CFGFLAG_SERVER, ConTuneDumpZone, this, "Dump zone tuning in zone x");
Console()->Register("tune_zone_reset", "?i[zone]", CFGFLAG_SERVER, ConTuneResetZone, this, "reset zone tuning in zone x or in all zones");
Console()->Register("tune_zone_enter", "i[zone] r[message]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneSetZoneMsgEnter, this, "which message to display on zone enter; use 0 for normal area");
Console()->Register("tune_zone_reset", "?i[zone]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneResetZone, this, "reset zone tuning in zone x or in all zones");
Console()->Register("tune_zone_leave", "i[zone] r[message]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneSetZoneMsgLeave, this, "which message to display on zone leave; use 0 for normal area");
Console()->Register("tune_zone_enter", "i[zone] r[message]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneSetZoneMsgEnter, this, "which message to display on zone enter; use 0 for normal area");
Console()->Register("mapbug", "s[mapbug]", CFGFLAG_SERVER | CFGFLAG_GAME, ConMapbug, this, "Enable map compatibility mode using the specified bug (example: grenade-doublexplosion@ddnet.tw)");
Console()->Register("switch_open", "i[switch]", CFGFLAG_SERVER | CFGFLAG_GAME, ConSwitchOpen, this, "Whether a switch is deactivated by default (otherwise activated)");
Console()->Register("pause_game", "", CFGFLAG_SERVER, ConPause, this, "Pause/unpause game");

View file

@ -173,7 +173,7 @@ MACRO_CONFIG_STR(SvServerType, sv_server_type, 64, "none", CFGFLAG_SERVER, "Type
MACRO_CONFIG_INT(SvSendVotesPerTick, sv_send_votes_per_tick, 5, 1, 15, CFGFLAG_SERVER, "Number of vote options being send per tick")
MACRO_CONFIG_INT(SvRescue, sv_rescue, 0, 0, 1, CFGFLAG_SERVER, "Allow /rescue command so players can teleport themselves out of freeze (setting only works in initial config)")
MACRO_CONFIG_INT(SvRescue, sv_rescue, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_READONLY, "Allow /rescue command so players can teleport themselves out of freeze (setting only works in initial config)")
MACRO_CONFIG_INT(SvRescueDelay, sv_rescue_delay, 1, 0, 1000, CFGFLAG_SERVER, "Number of seconds between two rescues")
MACRO_CONFIG_INT(SvPractice, sv_practice, 1, 0, 1, CFGFLAG_SERVER, "Enable practice mode for teams. Means you can use /rescue, but in turn your rank doesn't count.")