From b8f89d883033dcfcef50b214c1f923ed78d686a0 Mon Sep 17 00:00:00 2001 From: duralakun Date: Fri, 15 Feb 2019 18:04:42 +0100 Subject: [PATCH 01/10] created cfgvar_buffer.cpp + printcfg command --- src/engine/server/server.cpp | 3 + src/engine/shared/cfgvar_buffer.cpp | 153 ++++++++++++++++++++++++++++ src/engine/shared/cfgvar_buffer.h | 40 ++++++++ src/engine/shared/console.cpp | 15 ++- src/engine/shared/console.h | 3 + 5 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 src/engine/shared/cfgvar_buffer.cpp create mode 100644 src/engine/shared/cfgvar_buffer.h diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 9f270a549..5954a6bbc 100755 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -32,6 +32,7 @@ #include "register.h" #include "server.h" +#include #include /* INFECTION MODIFICATION START ***************************************/ @@ -2850,6 +2851,8 @@ int main(int argc, const char **argv) // ignore_convention // restore empty config strings to their defaults pConfig->RestoreStrings(); + CCfgVarBuffer::Init(); + pEngine->InitLogfile(); // run the server diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp new file mode 100644 index 000000000..ea9b8e21b --- /dev/null +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -0,0 +1,153 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +/* Modifications Copyright 2019 The InfclassR (https://github.com/yavl/teeworlds-infclassR/) Authors */ + +#include +#include "cfgvar_buffer.h" +#include "config.h" +#include "console.h" +#include + +int CCfgVarBuffer::m_CfgVarsCounter; +CCfgVarBuffer::CfgVar *CCfgVarBuffer::m_CfgVars; + +void CCfgVarBuffer::Init() +{ + m_CfgVarsCounter = 0; + + // Count how many config variables there are + #define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ + { \ + m_CfgVarsCounter++; \ + } + + #define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc) \ + { \ + m_CfgVarsCounter++; \ + } + + #include "config_variables.h" + #include "game/variables.h" + + #undef MACRO_CONFIG_INT + #undef MACRO_CONFIG_STR + + m_CfgVars = new CfgVar[m_CfgVarsCounter]; + int tCount = 0; + + // read all config variables and save their information to m_CfgVars + #define MACRO_CFGVAR_SAVE_NAME(ScriptName) \ + { \ + int i = 0; \ + for ( ; i < 256; i++) \ + if (#ScriptName[i] == 0) break; \ + i++; \ + m_CfgVars[tCount].m_pScriptName = new char[i]; \ + m_CfgVars[tCount].m_ScriptNameLength = i; \ + std::cout << "JDBG " << #ScriptName << " i: " << i << "\n"; \ + str_copy(m_CfgVars[tCount].m_pScriptName, #ScriptName, i); \ + m_CfgVars[tCount].m_pScriptName[i-1] = 0; \ + } + + #define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ + { \ + m_CfgVars[tCount].m_Type = CFG_TYPE_INT; \ + m_CfgVars[tCount].m_pIntValue = &g_Config.m_##Name; \ + MACRO_CFGVAR_SAVE_NAME(ScriptName); \ + tCount++; \ + } + + #define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc) \ + { \ + m_CfgVars[tCount].m_Type = CFG_TYPE_STR; \ + m_CfgVars[tCount].m_pStrValue = g_Config.m_##Name; \ + MACRO_CFGVAR_SAVE_NAME(ScriptName); \ + tCount++; \ + } + + #include "config_variables.h" + #include "game/variables.h" + + #undef MACRO_CONFIG_INT + #undef MACRO_CONFIG_STR +} + + +void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) +{ + if (*pCfgName == 0) + { + // print all config variables and their values + for (int i = 0; i < m_CfgVarsCounter; i++) + { + char lineBuff[512]; + if (m_CfgVars[i].m_Type == CFG_TYPE_INT) + str_format(lineBuff, 512, "%s %i", m_CfgVars[i].m_pScriptName, *m_CfgVars[i].m_pIntValue); + else + str_format(lineBuff, 512, "%s %s", m_CfgVars[i].m_pScriptName, m_CfgVars[i].m_pStrValue); + pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); + } + return; + } + + // search for config vars that contain pCfgName and print them and their values + for (int i = 0; i < m_CfgVarsCounter; i++) + { + bool contains = false; + int m = 0; + for (int k = 0; k < m_CfgVars[i].m_ScriptNameLength; k++) + { + if (pCfgName[m] == m_CfgVars[i].m_pScriptName[k]) + m++; + else + m = 0; + if (pCfgName[m] == 0) + { + contains = true; + break; + } + } + if (!contains) continue; + + char lineBuff[512]; + if (m_CfgVars[i].m_Type == CFG_TYPE_INT) + str_format(lineBuff, 512, "%s %i", m_CfgVars[i].m_pScriptName, *m_CfgVars[i].m_pIntValue); + else + str_format(lineBuff, 512, "%s %s", m_CfgVars[i].m_pScriptName, m_CfgVars[i].m_pStrValue); + pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); + } +} + +/* +// puts all config vars and their values inside a string +// returns false if it runs out of memory +bool CCfgVarBuffer::GetCfgStr(char *pStr, int StrSize) +{ + for (int i = 0; i < m_CfgVarsCounter; i++) + { + char lineBuff[512]; + if (m_CfgVars[i].m_Type == CFG_TYPE_INT) + str_format(lineBuff, 512, "%s %i \n", m_CfgVars[i].m_pScriptName, *m_CfgVars[i].m_pIntValue); + else + str_format(lineBuff, 512, "%s %s \n", m_CfgVars[i].m_pScriptName, m_CfgVars[i].m_pStrValue); + int m = 0; + for ( ; m < 512; m++) + if (lineBuff[m] == 0) break; + if (StrSize-m <= 0) + { + *pStr = 0; + dbg_msg("GetCfgStr", "Error: out of memory"); + return false; + } + for (int u = 0; u < m; u++) + pStr[u] = lineBuff[u]; + StrSize -= m; + pStr += m; + } + *pStr = 0; + return true; +} +*/ + + + diff --git a/src/engine/shared/cfgvar_buffer.h b/src/engine/shared/cfgvar_buffer.h new file mode 100644 index 000000000..541babf52 --- /dev/null +++ b/src/engine/shared/cfgvar_buffer.h @@ -0,0 +1,40 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +/* Modifications Copyright 2019 The InfclassR (https://github.com/yavl/teeworlds-infclassR/) Authors */ + +#ifndef ENGINE_SHARED_CFGVAR_BUFFER_H +#define ENGINE_SHARED_CFGVAR_BUFFER_H + +#include +#include "console.h" + +class CCfgVarBuffer +{ + + enum + { + CFG_TYPE_INT = 0, + CFG_TYPE_STR = 1 + }; + + struct CfgVar + { + int m_Type; + char *m_pScriptName; + int m_ScriptNameLength; + int *m_pIntValue; + char *m_pStrValue; + }; + +public: + static void Init(); + static void ConPrintCfg(CConsole* pConsole, const char *pCfgName); + +private: + static CfgVar *m_CfgVars; + static int m_CfgVarsCounter; + +}; + + +#endif diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index c8711f9c2..7c752b65b 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -1,5 +1,6 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +/* Modifications Copyright 2019 The InfclassR (https://github.com/yavl/teeworlds-infclassR/) Authors */ #include #include @@ -11,6 +12,10 @@ #include "config.h" #include "console.h" #include "linereader.h" +#include "cfgvar_buffer.h" + +#include +#include // todo: rework this @@ -483,14 +488,18 @@ void CConsole::ExecuteFile(const char *pFilename) bool CConsole::Con_Echo(IResult *pResult, void *pUserData) { ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", pResult->GetString(0)); - return true; } bool CConsole::Con_Exec(IResult *pResult, void *pUserData) { ((CConsole*)pUserData)->ExecuteFile(pResult->GetString(0)); - + return true; +} + +bool CConsole::Con_PrintCfg(IResult *pResult, void *pUserData) +{ + CCfgVarBuffer::ConPrintCfg(((CConsole*)pUserData), pResult->GetString(0)); return true; } @@ -717,6 +726,8 @@ CConsole::CConsole(int FlagMask) Register("echo", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Echo, this, "Echo the text"); Register("exec", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Exec, this, "Execute the specified file"); + Register("printcfg", "?r", CFGFLAG_SERVER, Con_PrintCfg, this, "Prints config vars and their values"); + Register("toggle", "sii", CFGFLAG_SERVER|CFGFLAG_CLIENT, ConToggle, this, "Toggle config value"); Register("+toggle", "sii", CFGFLAG_CLIENT, ConToggleStroke, this, "Toggle config value via keypress"); diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index a13003b98..344345395 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -1,8 +1,10 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +/* Modifications Copyright 2019 The InfclassR (https://github.com/yavl/teeworlds-infclassR/) Authors */ #ifndef ENGINE_SHARED_CONSOLE_H #define ENGINE_SHARED_CONSOLE_H +#include #include #include "memheap.h" @@ -54,6 +56,7 @@ class CConsole : public IConsole static bool Con_Chain(IResult *pResult, void *pUserData); static bool Con_Echo(IResult *pResult, void *pUserData); static bool Con_Exec(IResult *pResult, void *pUserData); + static bool Con_PrintCfg(IResult *pResult, void *pUserData); static bool ConToggle(IResult *pResult, void *pUser); static bool ConToggleStroke(IResult *pResult, void *pUser); static bool ConModCommandAccess(IResult *pResult, void *pUser); From 1c976aa2ed567816a2d26e67e5444f9e8036ecbc Mon Sep 17 00:00:00 2001 From: duralakun Date: Fri, 15 Feb 2019 19:04:26 +0100 Subject: [PATCH 02/10] added printcmd command and tiny improvements to printcfg --- src/engine/shared/cfgvar_buffer.cpp | 9 +++++ src/engine/shared/cfgvar_buffer.h | 1 + src/engine/shared/console.cpp | 51 ++++++++++++++++++++++++++++- src/engine/shared/console.h | 1 + 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index ea9b8e21b..9c831aa13 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -118,6 +118,15 @@ void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) } } +bool CCfgVarBuffer::IsConfigVar(const char* pStr) +{ + for (int i = 0; i < m_CfgVarsCounter; i++) + { + if (str_comp_nocase(m_CfgVars[i].m_pScriptName, pStr) == 0) return true; + } + return false; +} + /* // puts all config vars and their values inside a string // returns false if it runs out of memory diff --git a/src/engine/shared/cfgvar_buffer.h b/src/engine/shared/cfgvar_buffer.h index 541babf52..8b0b72d57 100644 --- a/src/engine/shared/cfgvar_buffer.h +++ b/src/engine/shared/cfgvar_buffer.h @@ -29,6 +29,7 @@ class CCfgVarBuffer public: static void Init(); static void ConPrintCfg(CConsole* pConsole, const char *pCfgName); + static bool IsConfigVar(const char* pStr); private: static CfgVar *m_CfgVars; diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 7c752b65b..a6c28faab 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -499,10 +499,58 @@ bool CConsole::Con_Exec(IResult *pResult, void *pUserData) bool CConsole::Con_PrintCfg(IResult *pResult, void *pUserData) { + char aBuff[256]; + if (pResult->GetString(0)[0] == 0) + str_format(aBuff, 256, "Printing all config variables :"); + else + str_format(aBuff, 256, "Printing all config variables containing '%s' :", pResult->GetString(0)); + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "- - - - - - - - - - - - - - - - - - - - - - - -"); + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuff); + CCfgVarBuffer::ConPrintCfg(((CConsole*)pUserData), pResult->GetString(0)); return true; } +bool CConsole::Con_PrintCmd(IResult *pResult, void *pUserData) +{ + char aBuff[256]; + if (pResult->GetString(0)[0] == 0) + str_format(aBuff, 256, "Printing all commands :"); + else + str_format(aBuff, 256, "Printing all commands containing '%s' :", pResult->GetString(0)); + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "- - - - - - - - - - - - - - - - - - - - - - - -"); + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuff); + + const char *pCmdName = pResult->GetString(0); + for(CCommand *pCommand = ((CConsole*)pUserData)->m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext) + { + if (CCfgVarBuffer::IsConfigVar(pCommand->m_pName)) continue; + + bool contains = false; + int m = 0; + for (int k = 0; k < 512; k++) + { + if (pCmdName[m] == 0) + { + contains = true; + break; + } + if (pCommand->m_pName[k] == 0) + break; + if (pCmdName[m] == pCommand->m_pName[k]) + m++; + else + m = 0; + } + if (!contains) continue; + + char lineBuff[512]; + str_format(lineBuff, 512, "%s %s -> %s", pCommand->m_pName, pCommand->m_pUsage, pCommand->m_pHelp); + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); + } + return true; +} + bool CConsole::ConModCommandAccess(IResult *pResult, void *pUser) { CConsole* pConsole = static_cast(pUser); @@ -726,7 +774,8 @@ CConsole::CConsole(int FlagMask) Register("echo", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Echo, this, "Echo the text"); Register("exec", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Exec, this, "Execute the specified file"); - Register("printcfg", "?r", CFGFLAG_SERVER, Con_PrintCfg, this, "Prints config vars and their values"); + Register("printcfg", "?r", CFGFLAG_SERVER, Con_PrintCfg, this, "Search for config vars that contain r and print their names and values"); + Register("printcmd", "?r", CFGFLAG_SERVER, Con_PrintCmd, this, "Search for commandos that contain r and print them"); Register("toggle", "sii", CFGFLAG_SERVER|CFGFLAG_CLIENT, ConToggle, this, "Toggle config value"); Register("+toggle", "sii", CFGFLAG_CLIENT, ConToggleStroke, this, "Toggle config value via keypress"); diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index 344345395..6743c0d74 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -57,6 +57,7 @@ class CConsole : public IConsole static bool Con_Echo(IResult *pResult, void *pUserData); static bool Con_Exec(IResult *pResult, void *pUserData); static bool Con_PrintCfg(IResult *pResult, void *pUserData); + static bool Con_PrintCmd(IResult *pResult, void *pUserData); static bool ConToggle(IResult *pResult, void *pUser); static bool ConToggleStroke(IResult *pResult, void *pUser); static bool ConModCommandAccess(IResult *pResult, void *pUser); From d7ef914b7278c407edf3feca411bed86b0a08a15 Mon Sep 17 00:00:00 2001 From: duralakun Date: Sat, 16 Feb 2019 21:01:49 +0100 Subject: [PATCH 03/10] created commands - resetcfg_nextround_start, resetcfg_nextround_end, print_round_cfg + improved previous commits + created fr_boooper.cfg --- bin/fr_boooper.cfg | 37 +++++ src/engine/server/server.cpp | 1 + src/engine/shared/cfgvar_buffer.cpp | 239 ++++++++++++++++++++-------- src/engine/shared/cfgvar_buffer.h | 48 +++++- src/engine/shared/console.cpp | 38 ++--- src/game/server/gamecontroller.cpp | 3 + 6 files changed, 272 insertions(+), 94 deletions(-) create mode 100644 bin/fr_boooper.cfg diff --git a/bin/fr_boooper.cfg b/bin/fr_boooper.cfg new file mode 100644 index 000000000..225ed6127 --- /dev/null +++ b/bin/fr_boooper.cfg @@ -0,0 +1,37 @@ +resetcfg_nextround_start # remember original config vars from this point on and reset them next round + +# only allow humans to be looper this round +inf_enable_engineer 0 +inf_enable_soldier 0 +inf_enable_scientist 0 +inf_enable_biologist 0 +inf_enable_looper 1 +inf_enable_mercenary 0 +inf_enable_sniper 0 +inf_enable_ninja 0 +inf_enable_medic 0 +inf_enable_hero 0 + +# only allow zombies to be boomer this round +inf_proba_smoker 0 +inf_proba_hunter 0 +inf_proba_bat 0 +inf_proba_boomer 100 +inf_proba_ghost 0 +inf_proba_spider 0 +inf_proba_ghoul 0 +inf_proba_slug 0 +inf_proba_voodoo 0 +inf_proba_witch 0 +inf_proba_undead 0 + +# change looper settings +inf_slow_motion_max_speed 0 # disable max speed +inf_slow_motion_gravity -25 # let zombies fly up +inf_slow_motion_gun_duration 20 # increase effect with gun to 2 seconds +inf_slow_motion_wall_duration 20 # decrease effect with gun to 2 seconds +inf_looper_barrier_life_span 30 # decrease wall time to 30 seconds + +resetcfg_nextround_end # stop remembering original config vars + +restart 1 # restarts round in 1 second diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 5954a6bbc..634f9c226 100755 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -2851,6 +2851,7 @@ int main(int argc, const char **argv) // ignore_convention // restore empty config strings to their defaults pConfig->RestoreStrings(); + CCfgVarBuffer::RegisterConsoleCommands(((CConsole*)pConsole)); CCfgVarBuffer::Init(); pEngine->InitLogfile(); diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index 9c831aa13..cb637c825 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -3,27 +3,120 @@ /* Modifications Copyright 2019 The InfclassR (https://github.com/yavl/teeworlds-infclassR/) Authors */ #include +#include #include "cfgvar_buffer.h" #include "config.h" #include "console.h" -#include +#include "string.h" -int CCfgVarBuffer::m_CfgVarsCounter; -CCfgVarBuffer::CfgVar *CCfgVarBuffer::m_CfgVars; +int CCfgVarBuffer::m_CfgVarsNum; +CCfgVarBuffer::CfgVar *CCfgVarBuffer::m_pCfgVars; + +bool CCfgVarBuffer::m_BackupRoundCfgVars; +int CCfgVarBuffer::m_ResetNextRoundCounter; +CCfgVarBuffer::CfgVarBackup *CCfgVarBuffer::m_pCfgVarRoundBackup; + +CCfgVarBuffer::CfgVarBackup::CfgVarBackup() +{ + m_pCfgVarsTemp = new CfgVarTemp[m_CfgVarsNum]; + for (int i = 0; i < m_CfgVarsNum; i++) + { + m_pCfgVarsTemp[i].active = false; + m_pCfgVarsTemp[i].m_pStrValue = NULL; + } +} + +CCfgVarBuffer::CfgVarBackup::~CfgVarBackup() +{ + for (int i = 0; i < m_CfgVarsNum; i++) + { + delete[] m_pCfgVarsTemp[i].m_pStrValue; + } + delete[] m_pCfgVarsTemp; +} + +void CCfgVarBuffer::CfgVarBackup::Add(const char* pCfgVarScriptName) +{ + int i = 0; + for ( ; i < m_CfgVarsNum; i++) + if (strcmp(m_pCfgVars[i].m_pScriptName, pCfgVarScriptName) == 0) break; + if (i >= m_CfgVarsNum) + { + dbg_msg("CfgVarBuffer", "Error: Could not find config variable '%s'", pCfgVarScriptName); + return; + } + if (m_pCfgVarsTemp[i].active) // var is already backed up + return; + m_pCfgVarsTemp[i].active = true; + // copy data to backup buffer + if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) + { + m_pCfgVarsTemp[i].m_IntValue = *m_pCfgVars[i].m_pIntValue; + } + else if (m_pCfgVars[i].m_Type == CFG_TYPE_STR) + { + if (!m_pCfgVars[i].m_pStrValue) + return; + int StrSize = strlen(m_pCfgVars[i].m_pStrValue) + 1; + m_pCfgVarsTemp[i].m_pStrValue = new char[StrSize]; + str_copy(m_pCfgVarsTemp[i].m_pStrValue, m_pCfgVars[i].m_pStrValue, StrSize); + } + else + dbg_msg("CfgVarBuffer", "Error: config variable '%s' has an unknown type", pCfgVarScriptName); +} + +void CCfgVarBuffer::CfgVarBackup::ConsolePrint(CConsole *pConsole, const char *pCfgName) +{ + char aBuff[256]; + if (!pCfgName || pCfgName[0] == 0) + str_format(aBuff, 256, "Printing all cfg vars changed for this round :"); + else + str_format(aBuff, 256, "Printing all cfg vars changed for this round containing '%s' :", pCfgName); + pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "- - - - - - - - - - - - - - - - - - - - - - - -"); + pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuff); + + for (int i = 0; i < m_CfgVarsNum; i++) + { + if (!m_pCfgVarsTemp[i].active) continue; + if (pCfgName && pCfgName[0] != 0 && !strstr(m_pCfgVars[i].m_pScriptName, pCfgName)) continue; // check if pCfgName is a substring of m_pScriptName + char lineBuff[512]; + if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) + str_format(lineBuff, 512, "%s %i -> %i", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_IntValue, *m_pCfgVars[i].m_pIntValue); + else + str_format(lineBuff, 512, "%s %s -> %s", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_pStrValue ,m_pCfgVars[i].m_pStrValue); + pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); + } +} + +void CCfgVarBuffer::CfgVarBackup::Apply() +{ + for (int i = 0; i < m_CfgVarsNum; i++) + { + if (!m_pCfgVarsTemp[i].active) continue; + if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) + *m_pCfgVars[i].m_pIntValue = m_pCfgVarsTemp[i].m_IntValue; + else + str_copy(m_pCfgVars[i].m_pStrValue, m_pCfgVarsTemp[i].m_pStrValue, strlen(m_pCfgVarsTemp[i].m_pStrValue)+1); + } +} void CCfgVarBuffer::Init() { - m_CfgVarsCounter = 0; + m_BackupRoundCfgVars = false; + m_ResetNextRoundCounter = 0; + delete m_pCfgVarRoundBackup; + m_pCfgVarRoundBackup = NULL; // Count how many config variables there are + m_CfgVarsNum = 0; #define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ { \ - m_CfgVarsCounter++; \ + m_CfgVarsNum++; \ } #define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc) \ { \ - m_CfgVarsCounter++; \ + m_CfgVarsNum++; \ } #include "config_variables.h" @@ -32,35 +125,32 @@ void CCfgVarBuffer::Init() #undef MACRO_CONFIG_INT #undef MACRO_CONFIG_STR - m_CfgVars = new CfgVar[m_CfgVarsCounter]; + m_pCfgVars = new CfgVar[m_CfgVarsNum]; int tCount = 0; - // read all config variables and save their information to m_CfgVars + // read all config variables and save their information to m_pCfgVars #define MACRO_CFGVAR_SAVE_NAME(ScriptName) \ { \ - int i = 0; \ - for ( ; i < 256; i++) \ - if (#ScriptName[i] == 0) break; \ + int i = strlen(#ScriptName); \ i++; \ - m_CfgVars[tCount].m_pScriptName = new char[i]; \ - m_CfgVars[tCount].m_ScriptNameLength = i; \ - std::cout << "JDBG " << #ScriptName << " i: " << i << "\n"; \ - str_copy(m_CfgVars[tCount].m_pScriptName, #ScriptName, i); \ - m_CfgVars[tCount].m_pScriptName[i-1] = 0; \ + m_pCfgVars[tCount].m_pScriptName = new char[i]; \ + m_pCfgVars[tCount].m_ScriptNameLength = i; \ + str_copy(m_pCfgVars[tCount].m_pScriptName, #ScriptName, i); \ + m_pCfgVars[tCount].m_pScriptName[i-1] = 0; \ } #define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ { \ - m_CfgVars[tCount].m_Type = CFG_TYPE_INT; \ - m_CfgVars[tCount].m_pIntValue = &g_Config.m_##Name; \ + m_pCfgVars[tCount].m_Type = CFG_TYPE_INT; \ + m_pCfgVars[tCount].m_pIntValue = &g_Config.m_##Name; \ MACRO_CFGVAR_SAVE_NAME(ScriptName); \ tCount++; \ } #define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc) \ { \ - m_CfgVars[tCount].m_Type = CFG_TYPE_STR; \ - m_CfgVars[tCount].m_pStrValue = g_Config.m_##Name; \ + m_pCfgVars[tCount].m_Type = CFG_TYPE_STR; \ + m_pCfgVars[tCount].m_pStrValue = g_Config.m_##Name; \ MACRO_CFGVAR_SAVE_NAME(ScriptName); \ tCount++; \ } @@ -72,59 +162,84 @@ void CCfgVarBuffer::Init() #undef MACRO_CONFIG_STR } +void CCfgVarBuffer::RegisterConsoleCommands(CConsole *pConsole) +{ + pConsole->Register("resetcfg_nextround_start", "", CFGFLAG_SERVER, ConResetCfgNextRound_Start, pConsole, + "cfg var changes between this start command and the stop command will be reset at the end of next round"); + pConsole->Register("resetcfg_nextround_end", "", CFGFLAG_SERVER, ConResetCfgNextRound_End, pConsole, + "cfg var changes between the start command and this stop command will be reset at the end of next round"); + pConsole->Register("print_round_cfg", "?s", CFGFLAG_SERVER, ConPrintRoundCfg, pConsole, + "show round specifc config vars, format: config_var original_value -> temp_value"); +} -void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) +bool CCfgVarBuffer::IsConfigVar(const char* pStr) { - if (*pCfgName == 0) + for (int i = 0; i < m_CfgVarsNum; i++) { - // print all config variables and their values - for (int i = 0; i < m_CfgVarsCounter; i++) - { - char lineBuff[512]; - if (m_CfgVars[i].m_Type == CFG_TYPE_INT) - str_format(lineBuff, 512, "%s %i", m_CfgVars[i].m_pScriptName, *m_CfgVars[i].m_pIntValue); - else - str_format(lineBuff, 512, "%s %s", m_CfgVars[i].m_pScriptName, m_CfgVars[i].m_pStrValue); - pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); - } - return; + if (str_comp_nocase(m_pCfgVars[i].m_pScriptName, pStr) == 0) return true; } + return false; +} - // search for config vars that contain pCfgName and print them and their values - for (int i = 0; i < m_CfgVarsCounter; i++) +void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) +{ + // search for config vars that contain pCfgName and print them and their values - if pCfgName is NULL print all vars + for (int i = 0; i < m_CfgVarsNum; i++) { - bool contains = false; - int m = 0; - for (int k = 0; k < m_CfgVars[i].m_ScriptNameLength; k++) - { - if (pCfgName[m] == m_CfgVars[i].m_pScriptName[k]) - m++; - else - m = 0; - if (pCfgName[m] == 0) - { - contains = true; - break; - } - } - if (!contains) continue; + if (pCfgName && pCfgName[0] != 0) + if (!strstr(m_pCfgVars[i].m_pScriptName, pCfgName)) continue; char lineBuff[512]; - if (m_CfgVars[i].m_Type == CFG_TYPE_INT) - str_format(lineBuff, 512, "%s %i", m_CfgVars[i].m_pScriptName, *m_CfgVars[i].m_pIntValue); + if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) + str_format(lineBuff, 512, "%s %i", m_pCfgVars[i].m_pScriptName, *m_pCfgVars[i].m_pIntValue); else - str_format(lineBuff, 512, "%s %s", m_CfgVars[i].m_pScriptName, m_CfgVars[i].m_pStrValue); + str_format(lineBuff, 512, "%s %s", m_pCfgVars[i].m_pScriptName, m_pCfgVars[i].m_pStrValue); pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); } } -bool CCfgVarBuffer::IsConfigVar(const char* pStr) +bool CCfgVarBuffer::ConResetCfgNextRound_Start(IConsole::IResult *pResult, void *pUserData) +{ + //((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "Reset upcomming config variables at the end of next round"); + m_BackupRoundCfgVars = true; + m_ResetNextRoundCounter = 2; + if (!m_pCfgVarRoundBackup) + m_pCfgVarRoundBackup = new CfgVarBackup(); + return true; +} + +bool CCfgVarBuffer::ConResetCfgNextRound_End(IConsole::IResult *pResult, void *pUserData) { - for (int i = 0; i < m_CfgVarsCounter; i++) + m_BackupRoundCfgVars = false; + return true; +} + +bool CCfgVarBuffer::ConPrintRoundCfg(IConsole::IResult *pResult, void *pUserData) +{ + if (!m_pCfgVarRoundBackup) { - if (str_comp_nocase(m_CfgVars[i].m_pScriptName, pStr) == 0) return true; + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "There are no special config vars for this round"); + return true; } - return false; + m_pCfgVarRoundBackup->ConsolePrint((CConsole*)pUserData, pResult->GetString(0)); + return true; +} + +void CCfgVarBuffer::OnExecuteLine(const char* pCfgVarScriptName) +{ + if (!m_BackupRoundCfgVars) return; + if (!IsConfigVar(pCfgVarScriptName)) return; + m_pCfgVarRoundBackup->Add(pCfgVarScriptName); +} + +void CCfgVarBuffer::OnRoundStart() +{ + if (m_ResetNextRoundCounter <= 0) return; + m_ResetNextRoundCounter--; + if (m_ResetNextRoundCounter > 0) return; + m_pCfgVarRoundBackup->Apply(); + delete m_pCfgVarRoundBackup; + m_pCfgVarRoundBackup = NULL; } /* @@ -132,13 +247,13 @@ bool CCfgVarBuffer::IsConfigVar(const char* pStr) // returns false if it runs out of memory bool CCfgVarBuffer::GetCfgStr(char *pStr, int StrSize) { - for (int i = 0; i < m_CfgVarsCounter; i++) + for (int i = 0; i < m_CfgVarsNum; i++) { char lineBuff[512]; - if (m_CfgVars[i].m_Type == CFG_TYPE_INT) - str_format(lineBuff, 512, "%s %i \n", m_CfgVars[i].m_pScriptName, *m_CfgVars[i].m_pIntValue); + if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) + str_format(lineBuff, 512, "%s %i \n", m_pCfgVars[i].m_pScriptName, *m_pCfgVars[i].m_pIntValue); else - str_format(lineBuff, 512, "%s %s \n", m_CfgVars[i].m_pScriptName, m_CfgVars[i].m_pStrValue); + str_format(lineBuff, 512, "%s %s \n", m_pCfgVars[i].m_pScriptName, m_pCfgVars[i].m_pStrValue); int m = 0; for ( ; m < 512; m++) if (lineBuff[m] == 0) break; @@ -158,5 +273,3 @@ bool CCfgVarBuffer::GetCfgStr(char *pStr, int StrSize) } */ - - diff --git a/src/engine/shared/cfgvar_buffer.h b/src/engine/shared/cfgvar_buffer.h index 8b0b72d57..0ce00d899 100644 --- a/src/engine/shared/cfgvar_buffer.h +++ b/src/engine/shared/cfgvar_buffer.h @@ -6,6 +6,7 @@ #define ENGINE_SHARED_CFGVAR_BUFFER_H #include +#include #include "console.h" class CCfgVarBuffer @@ -19,21 +20,54 @@ class CCfgVarBuffer struct CfgVar { - int m_Type; - char *m_pScriptName; + int m_Type; // CFG_TYPE_INT or CFG_TYPE_STR + char *m_pScriptName; // for example "sv_rcon_password" int m_ScriptNameLength; - int *m_pIntValue; - char *m_pStrValue; + int *m_pIntValue; // contains pointer to get/set and int config var + char *m_pStrValue; // contains pointer to get/set a string config var + }; + + struct CfgVarTemp + { + bool active; + int m_IntValue; + char *m_pStrValue; + }; + + // use delete on objects from this class if you dont need them anymore + class CfgVarBackup + { + public: + CfgVarBackup(); + ~CfgVarBackup(); + void Add(const char* pCfgVarScriptName); + void ConsolePrint(CConsole *pConsole, const char *pCfgName = NULL); + void Apply(); + + private: + CfgVarTemp *m_pCfgVarsTemp; }; public: static void Init(); - static void ConPrintCfg(CConsole* pConsole, const char *pCfgName); + static void RegisterConsoleCommands(CConsole *pConsole); static bool IsConfigVar(const char* pStr); + static void ConPrintCfg(CConsole* pConsole, const char *pCfgName); + static bool ConResetCfgNextRound_Start(IConsole::IResult *pResult, void *pUserData); + static bool ConResetCfgNextRound_End(IConsole::IResult *pResult, void *pUserData); + static bool ConPrintRoundCfg(IConsole::IResult *pResult, void *pUserData); + + static void OnExecuteLine(const char* pCfgVarScriptName); + static void OnRoundStart(); + private: - static CfgVar *m_CfgVars; - static int m_CfgVarsCounter; + static CfgVar *m_pCfgVars; // array that contains the name and pointers of all config vars once + static int m_CfgVarsNum; // how many different config vars there are - how many elements inside m_CfgVars + + static bool m_BackupRoundCfgVars; + static int m_ResetNextRoundCounter; + static CfgVarBackup *m_pCfgVarRoundBackup; // saves config vars in the same order as m_pCfgVars to restore them at the end of a round }; diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index a6c28faab..841952ea2 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -9,14 +9,12 @@ #include #include +#include "string.h" #include "config.h" #include "console.h" #include "linereader.h" #include "cfgvar_buffer.h" -#include -#include - // todo: rework this const char *CConsole::CResult::GetString(unsigned Index) @@ -367,6 +365,8 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, bo } else { + CCfgVarBuffer::OnExecuteLine(pCommand->m_pName); + bool ValideArguments = pCommand->m_pfnCallback(&Result, pCommand->m_pUserData); if(!ValideArguments) { @@ -514,7 +514,7 @@ bool CConsole::Con_PrintCfg(IResult *pResult, void *pUserData) bool CConsole::Con_PrintCmd(IResult *pResult, void *pUserData) { char aBuff[256]; - if (pResult->GetString(0)[0] == 0) + if (!pResult->GetString(0) || pResult->GetString(0)[0] == 0) str_format(aBuff, 256, "Printing all commands :"); else str_format(aBuff, 256, "Printing all commands containing '%s' :", pResult->GetString(0)); @@ -526,26 +526,14 @@ bool CConsole::Con_PrintCmd(IResult *pResult, void *pUserData) { if (CCfgVarBuffer::IsConfigVar(pCommand->m_pName)) continue; - bool contains = false; - int m = 0; - for (int k = 0; k < 512; k++) - { - if (pCmdName[m] == 0) - { - contains = true; - break; - } - if (pCommand->m_pName[k] == 0) - break; - if (pCmdName[m] == pCommand->m_pName[k]) - m++; - else - m = 0; - } - if (!contains) continue; + if (pCmdName && pCmdName[0] != 0) + if (!strstr(pCommand->m_pName, pCmdName)) continue; // continue if command doesnt contain pCmdName char lineBuff[512]; - str_format(lineBuff, 512, "%s %s -> %s", pCommand->m_pName, pCommand->m_pUsage, pCommand->m_pHelp); + if (pCommand->m_pUsage && pCommand->m_pUsage[0] != 0) + str_format(lineBuff, 512, "%s %s -> %s", pCommand->m_pName, pCommand->m_pUsage, pCommand->m_pHelp); + else + str_format(lineBuff, 512, "%s -> %s", pCommand->m_pName, pCommand->m_pHelp); ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); } return true; @@ -774,8 +762,8 @@ CConsole::CConsole(int FlagMask) Register("echo", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Echo, this, "Echo the text"); Register("exec", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Exec, this, "Execute the specified file"); - Register("printcfg", "?r", CFGFLAG_SERVER, Con_PrintCfg, this, "Search for config vars that contain r and print their names and values"); - Register("printcmd", "?r", CFGFLAG_SERVER, Con_PrintCmd, this, "Search for commandos that contain r and print them"); + Register("print_cfg", "?s", CFGFLAG_SERVER, Con_PrintCfg, this, "Search for config vars that contain X and print their names and values"); + Register("print_cmd", "?s", CFGFLAG_SERVER, Con_PrintCmd, this, "Search for commandos that contain X and print them"); Register("toggle", "sii", CFGFLAG_SERVER|CFGFLAG_CLIENT, ConToggle, this, "Toggle config value"); Register("+toggle", "sii", CFGFLAG_CLIENT, ConToggleStroke, this, "Toggle config value via keypress"); @@ -783,6 +771,8 @@ CConsole::CConsole(int FlagMask) Register("mod_command", "s?i", CFGFLAG_SERVER, ConModCommandAccess, this, "Specify command accessibility for moderators"); Register("mod_status", "", CFGFLAG_SERVER, ConModCommandStatus, this, "List all commands which are accessible for moderators"); + //Register("testt", "", CFGFLAG_SERVER, CCfgVarBuffer::ConResetCfgAtNextRoundEnd_Start, this, "testt"); + // TODO: this should disappear #define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ { \ diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index cb385fbb7..414b6557c 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -1,6 +1,8 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +/* Modifications Copyright 2019 The InfclassR (https://github.com/yavl/teeworlds-infclassR/) Authors */ #include +#include #include #include @@ -136,6 +138,7 @@ void IGameController::StartRound() { ResetGame(); + CCfgVarBuffer::OnRoundStart(); Server()->OnRoundStart(); GameServer()->OnStartRound(); From 5bdf8c3278c6f64cb4d7c53c0b76dd68c5f10776 Mon Sep 17 00:00:00 2001 From: duralakun Date: Sun, 17 Feb 2019 06:29:15 +0100 Subject: [PATCH 04/10] small improvements --- bin/fr_boooper.cfg | 3 +++ src/engine/shared/cfgvar_buffer.cpp | 8 ++++++++ src/engine/shared/console.cpp | 10 ---------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/fr_boooper.cfg b/bin/fr_boooper.cfg index 225ed6127..26e1dd4ce 100644 --- a/bin/fr_boooper.cfg +++ b/bin/fr_boooper.cfg @@ -1,3 +1,6 @@ +# to start this funround type in rcon console: exec fr_boooper.cfg +# you can also add it as vote: add_vote "boooper round" exec fr_boooper.cfg + resetcfg_nextround_start # remember original config vars from this point on and reset them next round # only allow humans to be looper this round diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index cb637c825..a85516058 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -183,6 +183,14 @@ bool CCfgVarBuffer::IsConfigVar(const char* pStr) void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) { + char aBuff[256]; + if (!pCfgName || pCfgName[0] == 0) + str_format(aBuff, 256, "Printing all config variables :"); + else + str_format(aBuff, 256, "Printing all config variables containing '%s' :", pCfgName); + pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "- - - - - - - - - - - - - - - - - - - - - - - -"); + pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuff); + // search for config vars that contain pCfgName and print them and their values - if pCfgName is NULL print all vars for (int i = 0; i < m_CfgVarsNum; i++) { diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 841952ea2..575a1e748 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -499,14 +499,6 @@ bool CConsole::Con_Exec(IResult *pResult, void *pUserData) bool CConsole::Con_PrintCfg(IResult *pResult, void *pUserData) { - char aBuff[256]; - if (pResult->GetString(0)[0] == 0) - str_format(aBuff, 256, "Printing all config variables :"); - else - str_format(aBuff, 256, "Printing all config variables containing '%s' :", pResult->GetString(0)); - ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "- - - - - - - - - - - - - - - - - - - - - - - -"); - ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuff); - CCfgVarBuffer::ConPrintCfg(((CConsole*)pUserData), pResult->GetString(0)); return true; } @@ -771,8 +763,6 @@ CConsole::CConsole(int FlagMask) Register("mod_command", "s?i", CFGFLAG_SERVER, ConModCommandAccess, this, "Specify command accessibility for moderators"); Register("mod_status", "", CFGFLAG_SERVER, ConModCommandStatus, this, "List all commands which are accessible for moderators"); - //Register("testt", "", CFGFLAG_SERVER, CCfgVarBuffer::ConResetCfgAtNextRoundEnd_Start, this, "testt"); - // TODO: this should disappear #define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ { \ From 9d34ddc4806534d7906eba3b7b14852be3618b07 Mon Sep 17 00:00:00 2001 From: duralakun Date: Sun, 17 Feb 2019 08:18:13 +0100 Subject: [PATCH 05/10] reset improvements --- src/engine/shared/cfgvar_buffer.cpp | 32 ++++++++++++++++++++++------- src/engine/shared/cfgvar_buffer.h | 5 +++-- src/engine/shared/console.cpp | 4 +++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index a85516058..7fca2a069 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -35,7 +35,7 @@ CCfgVarBuffer::CfgVarBackup::~CfgVarBackup() delete[] m_pCfgVarsTemp; } -void CCfgVarBuffer::CfgVarBackup::Add(const char* pCfgVarScriptName) +void CCfgVarBuffer::CfgVarBackup::Add(const char* pCfgVarScriptName, bool OverrideOld) { int i = 0; for ( ; i < m_CfgVarsNum; i++) @@ -45,7 +45,7 @@ void CCfgVarBuffer::CfgVarBackup::Add(const char* pCfgVarScriptName) dbg_msg("CfgVarBuffer", "Error: Could not find config variable '%s'", pCfgVarScriptName); return; } - if (m_pCfgVarsTemp[i].active) // var is already backed up + if (!OverrideOld && m_pCfgVarsTemp[i].active) // var is already backed up return; m_pCfgVarsTemp[i].active = true; // copy data to backup buffer @@ -211,8 +211,12 @@ bool CCfgVarBuffer::ConResetCfgNextRound_Start(IConsole::IResult *pResult, void //((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "Reset upcomming config variables at the end of next round"); m_BackupRoundCfgVars = true; m_ResetNextRoundCounter = 2; - if (!m_pCfgVarRoundBackup) - m_pCfgVarRoundBackup = new CfgVarBackup(); + if (m_pCfgVarRoundBackup) + { + m_pCfgVarRoundBackup->Apply(); + delete m_pCfgVarRoundBackup; + } + m_pCfgVarRoundBackup = new CfgVarBackup(); return true; } @@ -226,28 +230,42 @@ bool CCfgVarBuffer::ConPrintRoundCfg(IConsole::IResult *pResult, void *pUserData { if (!m_pCfgVarRoundBackup) { - ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "There are no special config vars for this round"); + ((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "Round cfg vars are disabled, you can activate them with resetcfg_nextround_start"); return true; } m_pCfgVarRoundBackup->ConsolePrint((CConsole*)pUserData, pResult->GetString(0)); return true; } -void CCfgVarBuffer::OnExecuteLine(const char* pCfgVarScriptName) +void CCfgVarBuffer::BeforeSetCfg(const char* pCfgVarScriptName) { if (!m_BackupRoundCfgVars) return; + if (!m_pCfgVarRoundBackup) return; if (!IsConfigVar(pCfgVarScriptName)) return; m_pCfgVarRoundBackup->Add(pCfgVarScriptName); } +void CCfgVarBuffer::AfterSetCfg(const char* pCfgVarScriptName) +{ + if (m_BackupRoundCfgVars) return; + if (!m_pCfgVarRoundBackup) return; + if (!IsConfigVar(pCfgVarScriptName)) return; + m_pCfgVarRoundBackup->Add(pCfgVarScriptName, true); +} + void CCfgVarBuffer::OnRoundStart() { - if (m_ResetNextRoundCounter <= 0) return; + if (m_ResetNextRoundCounter <= 0) + return; m_ResetNextRoundCounter--; if (m_ResetNextRoundCounter > 0) return; + m_pCfgVarRoundBackup->Apply(); + + // reset delete m_pCfgVarRoundBackup; m_pCfgVarRoundBackup = NULL; + m_BackupRoundCfgVars = false; } /* diff --git a/src/engine/shared/cfgvar_buffer.h b/src/engine/shared/cfgvar_buffer.h index 0ce00d899..c73b51218 100644 --- a/src/engine/shared/cfgvar_buffer.h +++ b/src/engine/shared/cfgvar_buffer.h @@ -40,7 +40,7 @@ class CCfgVarBuffer public: CfgVarBackup(); ~CfgVarBackup(); - void Add(const char* pCfgVarScriptName); + void Add(const char* pCfgVarScriptName, bool OverrideOld = false); void ConsolePrint(CConsole *pConsole, const char *pCfgName = NULL); void Apply(); @@ -58,7 +58,8 @@ class CCfgVarBuffer static bool ConResetCfgNextRound_End(IConsole::IResult *pResult, void *pUserData); static bool ConPrintRoundCfg(IConsole::IResult *pResult, void *pUserData); - static void OnExecuteLine(const char* pCfgVarScriptName); + static void BeforeSetCfg(const char* pCfgVarScriptName); + static void AfterSetCfg(const char* pCfgVarScriptName); static void OnRoundStart(); private: diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 575a1e748..2fe46d655 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -365,7 +365,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, bo } else { - CCfgVarBuffer::OnExecuteLine(pCommand->m_pName); + CCfgVarBuffer::BeforeSetCfg(pCommand->m_pName); bool ValideArguments = pCommand->m_pfnCallback(&Result, pCommand->m_pUserData); if(!ValideArguments) @@ -377,6 +377,8 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, bo Print(OUTPUT_LEVEL_STANDARD, "Console", "Invalid arguments."); Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); } + + CCfgVarBuffer::AfterSetCfg(pCommand->m_pName); } } } From 35f97c8612804919a79ebdd7ef2615e6b60b8129 Mon Sep 17 00:00:00 2001 From: duralakun Date: Sun, 17 Feb 2019 12:02:19 +0100 Subject: [PATCH 06/10] renamed resetcfg_nextround_start to set_config_for_nextround_begin --- bin/fr_boooper.cfg | 8 ++++---- src/engine/shared/cfgvar_buffer.cpp | 15 +++++++-------- src/engine/shared/cfgvar_buffer.h | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bin/fr_boooper.cfg b/bin/fr_boooper.cfg index 26e1dd4ce..ec6be7794 100644 --- a/bin/fr_boooper.cfg +++ b/bin/fr_boooper.cfg @@ -1,7 +1,7 @@ # to start this funround type in rcon console: exec fr_boooper.cfg # you can also add it as vote: add_vote "boooper round" exec fr_boooper.cfg -resetcfg_nextround_start # remember original config vars from this point on and reset them next round +set_cfg_for_nextround_begin # remember original config vars from this point on and reset them next round # only allow humans to be looper this round inf_enable_engineer 0 @@ -31,10 +31,10 @@ inf_proba_undead 0 # change looper settings inf_slow_motion_max_speed 0 # disable max speed inf_slow_motion_gravity -25 # let zombies fly up -inf_slow_motion_gun_duration 20 # increase effect with gun to 2 seconds -inf_slow_motion_wall_duration 20 # decrease effect with gun to 2 seconds +inf_slow_motion_gun_duration 20 # increase gun effect duration to 2 seconds +inf_slow_motion_wall_duration 20 # decrease wall effect duration to 2 seconds inf_looper_barrier_life_span 30 # decrease wall time to 30 seconds -resetcfg_nextround_end # stop remembering original config vars +set_cfg_for_nextround_end # stop remembering original config vars restart 1 # restarts round in 1 second diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index 7fca2a069..5b4197309 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -164,10 +164,10 @@ void CCfgVarBuffer::Init() void CCfgVarBuffer::RegisterConsoleCommands(CConsole *pConsole) { - pConsole->Register("resetcfg_nextround_start", "", CFGFLAG_SERVER, ConResetCfgNextRound_Start, pConsole, - "cfg var changes between this start command and the stop command will be reset at the end of next round"); - pConsole->Register("resetcfg_nextround_end", "", CFGFLAG_SERVER, ConResetCfgNextRound_End, pConsole, - "cfg var changes between the start command and this stop command will be reset at the end of next round"); + pConsole->Register("set_cfg_for_nextround_begin", "", CFGFLAG_SERVER, ConSetCfgForNextRound_Begin, pConsole, + "cfg var changes between this begin command and the end command will be reset at the end of next round"); + pConsole->Register("set_cfg_for_nextround_end", "", CFGFLAG_SERVER, ConSetCfgForNextRound_End, pConsole, + "cfg var changes between the begin command and this end command will be reset at the end of next round"); pConsole->Register("print_round_cfg", "?s", CFGFLAG_SERVER, ConPrintRoundCfg, pConsole, "show round specifc config vars, format: config_var original_value -> temp_value"); } @@ -206,7 +206,7 @@ void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) } } -bool CCfgVarBuffer::ConResetCfgNextRound_Start(IConsole::IResult *pResult, void *pUserData) +bool CCfgVarBuffer::ConSetCfgForNextRound_Begin(IConsole::IResult *pResult, void *pUserData) { //((CConsole*)pUserData)->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", "Reset upcomming config variables at the end of next round"); m_BackupRoundCfgVars = true; @@ -220,7 +220,7 @@ bool CCfgVarBuffer::ConResetCfgNextRound_Start(IConsole::IResult *pResult, void return true; } -bool CCfgVarBuffer::ConResetCfgNextRound_End(IConsole::IResult *pResult, void *pUserData) +bool CCfgVarBuffer::ConSetCfgForNextRound_End(IConsole::IResult *pResult, void *pUserData) { m_BackupRoundCfgVars = false; return true; @@ -255,8 +255,7 @@ void CCfgVarBuffer::AfterSetCfg(const char* pCfgVarScriptName) void CCfgVarBuffer::OnRoundStart() { - if (m_ResetNextRoundCounter <= 0) - return; + if (m_ResetNextRoundCounter <= 0) return; m_ResetNextRoundCounter--; if (m_ResetNextRoundCounter > 0) return; diff --git a/src/engine/shared/cfgvar_buffer.h b/src/engine/shared/cfgvar_buffer.h index c73b51218..39eae856d 100644 --- a/src/engine/shared/cfgvar_buffer.h +++ b/src/engine/shared/cfgvar_buffer.h @@ -54,8 +54,8 @@ class CCfgVarBuffer static bool IsConfigVar(const char* pStr); static void ConPrintCfg(CConsole* pConsole, const char *pCfgName); - static bool ConResetCfgNextRound_Start(IConsole::IResult *pResult, void *pUserData); - static bool ConResetCfgNextRound_End(IConsole::IResult *pResult, void *pUserData); + static bool ConSetCfgForNextRound_Begin(IConsole::IResult *pResult, void *pUserData); + static bool ConSetCfgForNextRound_End(IConsole::IResult *pResult, void *pUserData); static bool ConPrintRoundCfg(IConsole::IResult *pResult, void *pUserData); static void BeforeSetCfg(const char* pCfgVarScriptName); From 48fdedc96a09e38abe34574203ab463491ba4bf2 Mon Sep 17 00:00:00 2001 From: duralakun Date: Sun, 17 Feb 2019 15:25:03 +0100 Subject: [PATCH 07/10] added unnecessary null pointer cheks + tiny override fix --- src/engine/shared/cfgvar_buffer.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index 5b4197309..ef048a5cb 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -47,6 +47,8 @@ void CCfgVarBuffer::CfgVarBackup::Add(const char* pCfgVarScriptName, bool Overri } if (!OverrideOld && m_pCfgVarsTemp[i].active) // var is already backed up return; + if (OverrideOld && !m_pCfgVarsTemp[i].active) // nothing to override here + return; m_pCfgVarsTemp[i].active = true; // copy data to backup buffer if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) @@ -55,6 +57,11 @@ void CCfgVarBuffer::CfgVarBackup::Add(const char* pCfgVarScriptName, bool Overri } else if (m_pCfgVars[i].m_Type == CFG_TYPE_STR) { + if (m_pCfgVarsTemp[i].m_pStrValue) + { + delete[] m_pCfgVarsTemp[i].m_pStrValue; + m_pCfgVarsTemp[i].m_pStrValue = NULL; + } if (!m_pCfgVars[i].m_pStrValue) return; int StrSize = strlen(m_pCfgVars[i].m_pStrValue) + 1; @@ -83,7 +90,16 @@ void CCfgVarBuffer::CfgVarBackup::ConsolePrint(CConsole *pConsole, const char *p if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) str_format(lineBuff, 512, "%s %i -> %i", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_IntValue, *m_pCfgVars[i].m_pIntValue); else - str_format(lineBuff, 512, "%s %s -> %s", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_pStrValue ,m_pCfgVars[i].m_pStrValue); + { + if (m_pCfgVarsTemp[i].m_pStrValue && m_pCfgVars[i].m_pStrValue) + str_format(lineBuff, 512, "%s %s -> %s", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_pStrValue, m_pCfgVars[i].m_pStrValue); + else if (m_pCfgVarsTemp[i].m_pStrValue && !m_pCfgVars[i].m_pStrValue) + str_format(lineBuff, 512, "%s %s -> NULL", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_pStrValue); + else if (!m_pCfgVarsTemp[i].m_pStrValue && m_pCfgVars[i].m_pStrValue) + str_format(lineBuff, 512, "%s NULL -> %s", m_pCfgVars[i].m_pScriptName, m_pCfgVars[i].m_pStrValue); + else if (!m_pCfgVarsTemp[i].m_pStrValue && !m_pCfgVars[i].m_pStrValue) + str_format(lineBuff, 512, "%s NULL -> NULL", m_pCfgVars[i].m_pScriptName); + } pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); } } @@ -96,7 +112,12 @@ void CCfgVarBuffer::CfgVarBackup::Apply() if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) *m_pCfgVars[i].m_pIntValue = m_pCfgVarsTemp[i].m_IntValue; else - str_copy(m_pCfgVars[i].m_pStrValue, m_pCfgVarsTemp[i].m_pStrValue, strlen(m_pCfgVarsTemp[i].m_pStrValue)+1); + { + if (!m_pCfgVarsTemp[i].m_pStrValue) + dbg_msg("CfgVarBuffer", "Error: cannot apply cfg backup for config variable '%s' -> NULL pointer string", m_pCfgVars[i].m_pScriptName); + else + str_copy(m_pCfgVars[i].m_pStrValue, m_pCfgVarsTemp[i].m_pStrValue, strlen(m_pCfgVarsTemp[i].m_pStrValue)+1); + } } } From c8207ba91f1ef591ff41338e118d3625a8960748 Mon Sep 17 00:00:00 2001 From: duralakun Date: Sun, 17 Feb 2019 21:44:58 +0100 Subject: [PATCH 08/10] dont print passwords --- src/engine/shared/cfgvar_buffer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index ef048a5cb..84e5b44f3 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -86,6 +86,7 @@ void CCfgVarBuffer::CfgVarBackup::ConsolePrint(CConsole *pConsole, const char *p { if (!m_pCfgVarsTemp[i].active) continue; if (pCfgName && pCfgName[0] != 0 && !strstr(m_pCfgVars[i].m_pScriptName, pCfgName)) continue; // check if pCfgName is a substring of m_pScriptName + if (strstr(m_pCfgVars[i].m_pScriptName, "password")) continue; // dont print passwords char lineBuff[512]; if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) str_format(lineBuff, 512, "%s %i -> %i", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_IntValue, *m_pCfgVars[i].m_pIntValue); @@ -217,6 +218,7 @@ void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) { if (pCfgName && pCfgName[0] != 0) if (!strstr(m_pCfgVars[i].m_pScriptName, pCfgName)) continue; + if (strstr(m_pCfgVars[i].m_pScriptName, "password")) continue; // dont print passwords char lineBuff[512]; if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) From 809d00e1533cd3a7e386ab25f7629065a2e6b237 Mon Sep 17 00:00:00 2001 From: duralakun Date: Sun, 17 Feb 2019 22:11:41 +0100 Subject: [PATCH 09/10] dont print passwords 2 --- src/engine/shared/cfgvar_buffer.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index 84e5b44f3..8a1f3d44a 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -86,13 +86,14 @@ void CCfgVarBuffer::CfgVarBackup::ConsolePrint(CConsole *pConsole, const char *p { if (!m_pCfgVarsTemp[i].active) continue; if (pCfgName && pCfgName[0] != 0 && !strstr(m_pCfgVars[i].m_pScriptName, pCfgName)) continue; // check if pCfgName is a substring of m_pScriptName - if (strstr(m_pCfgVars[i].m_pScriptName, "password")) continue; // dont print passwords char lineBuff[512]; if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) str_format(lineBuff, 512, "%s %i -> %i", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_IntValue, *m_pCfgVars[i].m_pIntValue); else { - if (m_pCfgVarsTemp[i].m_pStrValue && m_pCfgVars[i].m_pStrValue) + if (strstr(m_pCfgVars[i].m_pScriptName, "password")) // dont print passwords + str_format(lineBuff, 512, "%s *****************", m_pCfgVars[i].m_pScriptName); + else if (m_pCfgVarsTemp[i].m_pStrValue && m_pCfgVars[i].m_pStrValue) str_format(lineBuff, 512, "%s %s -> %s", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_pStrValue, m_pCfgVars[i].m_pStrValue); else if (m_pCfgVarsTemp[i].m_pStrValue && !m_pCfgVars[i].m_pStrValue) str_format(lineBuff, 512, "%s %s -> NULL", m_pCfgVars[i].m_pScriptName, m_pCfgVarsTemp[i].m_pStrValue); @@ -218,13 +219,17 @@ void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) { if (pCfgName && pCfgName[0] != 0) if (!strstr(m_pCfgVars[i].m_pScriptName, pCfgName)) continue; - if (strstr(m_pCfgVars[i].m_pScriptName, "password")) continue; // dont print passwords char lineBuff[512]; if (m_pCfgVars[i].m_Type == CFG_TYPE_INT) str_format(lineBuff, 512, "%s %i", m_pCfgVars[i].m_pScriptName, *m_pCfgVars[i].m_pIntValue); else - str_format(lineBuff, 512, "%s %s", m_pCfgVars[i].m_pScriptName, m_pCfgVars[i].m_pStrValue); + { + if (strstr(m_pCfgVars[i].m_pScriptName, "password")) // dont print passwords + str_format(lineBuff, 512, "%s *****************", m_pCfgVars[i].m_pScriptName); + else + str_format(lineBuff, 512, "%s %s", m_pCfgVars[i].m_pScriptName, m_pCfgVars[i].m_pStrValue); + } pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); } } From be028328870f6362f0cb0cb4297f7f82fdfeb733 Mon Sep 17 00:00:00 2001 From: duralakun Date: Mon, 18 Feb 2019 18:00:11 +0100 Subject: [PATCH 10/10] small improvements --- src/engine/shared/cfgvar_buffer.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/engine/shared/cfgvar_buffer.cpp b/src/engine/shared/cfgvar_buffer.cpp index 8a1f3d44a..767371090 100644 --- a/src/engine/shared/cfgvar_buffer.cpp +++ b/src/engine/shared/cfgvar_buffer.cpp @@ -154,8 +154,7 @@ void CCfgVarBuffer::Init() // read all config variables and save their information to m_pCfgVars #define MACRO_CFGVAR_SAVE_NAME(ScriptName) \ { \ - int i = strlen(#ScriptName); \ - i++; \ + int i = strlen(#ScriptName) + 1; \ m_pCfgVars[tCount].m_pScriptName = new char[i]; \ m_pCfgVars[tCount].m_ScriptNameLength = i; \ str_copy(m_pCfgVars[tCount].m_pScriptName, #ScriptName, i); \ @@ -183,6 +182,7 @@ void CCfgVarBuffer::Init() #undef MACRO_CONFIG_INT #undef MACRO_CONFIG_STR + #undef MACRO_CFGVAR_SAVE_NAME } void CCfgVarBuffer::RegisterConsoleCommands(CConsole *pConsole) @@ -197,6 +197,7 @@ void CCfgVarBuffer::RegisterConsoleCommands(CConsole *pConsole) bool CCfgVarBuffer::IsConfigVar(const char* pStr) { + if (!pStr) return false; for (int i = 0; i < m_CfgVarsNum; i++) { if (str_comp_nocase(m_pCfgVars[i].m_pScriptName, pStr) == 0) return true; @@ -227,8 +228,13 @@ void CCfgVarBuffer::ConPrintCfg(CConsole* pConsole, const char *pCfgName) { if (strstr(m_pCfgVars[i].m_pScriptName, "password")) // dont print passwords str_format(lineBuff, 512, "%s *****************", m_pCfgVars[i].m_pScriptName); - else - str_format(lineBuff, 512, "%s %s", m_pCfgVars[i].m_pScriptName, m_pCfgVars[i].m_pStrValue); + else + { + if (m_pCfgVars[i].m_pStrValue) + str_format(lineBuff, 512, "%s %s", m_pCfgVars[i].m_pScriptName, m_pCfgVars[i].m_pStrValue); + else + str_format(lineBuff, 512, "%s NULL", m_pCfgVars[i].m_pScriptName); + } } pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", lineBuff); }