diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index a68d9de49..216264f43 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -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 diff --git a/src/engine/shared/config.h b/src/engine/shared/config.h index f5c3c5b4f..2744fc152 100644 --- a/src/engine/shared/config.h +++ b/src/engine/shared/config.h @@ -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 diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index c78498006..b61eec051 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -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") diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 679a5fee6..6e3bf2e5b 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -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) - return; + 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((Flags)&CFGFLAG_READONLY)}; \ Register(#ScriptName, "?i", Flags, IntVariableCommand, &Data, Desc); \ } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index d3983d0ae..8f55c0953 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -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"); diff --git a/src/game/variables.h b/src/game/variables.h index 214f302da..d0792fc9a 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -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.")