forked from necropotame/teeworlds-infclass
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config var improvements #103
Open
duralakun
wants to merge
10
commits into
master
Choose a base branch
from
cfg_vars
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b8f89d8
created cfgvar_buffer.cpp + printcfg command
duralakun 1c976aa
added printcmd command and tiny improvements to printcfg
duralakun d7ef914
created commands - resetcfg_nextround_start, resetcfg_nextround_end, …
duralakun 5bdf8c3
small improvements
duralakun 9d34ddc
reset improvements
duralakun 35f97c8
renamed resetcfg_nextround_start to set_config_for_nextround_begin
duralakun 48fdedc
added unnecessary null pointer cheks + tiny override fix
duralakun c8207ba
dont print passwords
duralakun 809d00e
dont print passwords 2
duralakun be02832
small improvements
duralakun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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 | ||
|
||
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 | ||
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 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 | ||
|
||
set_cfg_for_nextround_end # stop remembering original config vars | ||
|
||
restart 1 # restarts round in 1 second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,334 @@ | ||
/* (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 <base/system.h> | ||
#include <engine/console.h> | ||
#include "cfgvar_buffer.h" | ||
#include "config.h" | ||
#include "console.h" | ||
#include "string.h" | ||
|
||
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, bool OverrideOld) | ||
{ | ||
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 (!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) | ||
{ | ||
m_pCfgVarsTemp[i].m_IntValue = *m_pCfgVars[i].m_pIntValue; | ||
} | ||
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; | ||
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 | ||
{ | ||
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); | ||
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); | ||
} | ||
} | ||
|
||
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 | ||
{ | ||
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); | ||
} | ||
} | ||
} | ||
|
||
void CCfgVarBuffer::Init() | ||
{ | ||
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_CfgVarsNum++; \ | ||
} | ||
|
||
#define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc) \ | ||
{ \ | ||
m_CfgVarsNum++; \ | ||
} | ||
|
||
#include "config_variables.h" | ||
#include "game/variables.h" | ||
|
||
#undef MACRO_CONFIG_INT | ||
#undef MACRO_CONFIG_STR | ||
|
||
m_pCfgVars = new CfgVar[m_CfgVarsNum]; | ||
int tCount = 0; | ||
|
||
// read all config variables and save their information to m_pCfgVars | ||
#define MACRO_CFGVAR_SAVE_NAME(ScriptName) \ | ||
{ \ | ||
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); \ | ||
m_pCfgVars[tCount].m_pScriptName[i-1] = 0; \ | ||
} | ||
|
||
#define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ | ||
{ \ | ||
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_pCfgVars[tCount].m_Type = CFG_TYPE_STR; \ | ||
m_pCfgVars[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 | ||
#undef MACRO_CFGVAR_SAVE_NAME | ||
} | ||
|
||
void CCfgVarBuffer::RegisterConsoleCommands(CConsole *pConsole) | ||
{ | ||
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"); | ||
} | ||
|
||
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; | ||
} | ||
return false; | ||
} | ||
|
||
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++) | ||
{ | ||
if (pCfgName && pCfgName[0] != 0) | ||
if (!strstr(m_pCfgVars[i].m_pScriptName, pCfgName)) continue; | ||
|
||
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 | ||
{ | ||
if (strstr(m_pCfgVars[i].m_pScriptName, "password")) // dont print passwords | ||
str_format(lineBuff, 512, "%s *****************", m_pCfgVars[i].m_pScriptName); | ||
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); | ||
} | ||
} | ||
|
||
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; | ||
m_ResetNextRoundCounter = 2; | ||
if (m_pCfgVarRoundBackup) | ||
{ | ||
m_pCfgVarRoundBackup->Apply(); | ||
delete m_pCfgVarRoundBackup; | ||
} | ||
m_pCfgVarRoundBackup = new CfgVarBackup(); | ||
return true; | ||
} | ||
|
||
bool CCfgVarBuffer::ConSetCfgForNextRound_End(IConsole::IResult *pResult, void *pUserData) | ||
{ | ||
m_BackupRoundCfgVars = false; | ||
return true; | ||
} | ||
|
||
bool CCfgVarBuffer::ConPrintRoundCfg(IConsole::IResult *pResult, void *pUserData) | ||
{ | ||
if (!m_pCfgVarRoundBackup) | ||
{ | ||
((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::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; | ||
m_ResetNextRoundCounter--; | ||
if (m_ResetNextRoundCounter > 0) return; | ||
|
||
m_pCfgVarRoundBackup->Apply(); | ||
|
||
// reset | ||
delete m_pCfgVarRoundBackup; | ||
m_pCfgVarRoundBackup = NULL; | ||
m_BackupRoundCfgVars = false; | ||
} | ||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please just remove unused code at all? |
||
// 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_CfgVarsNum; i++) | ||
{ | ||
char lineBuff[512]; | ||
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_pCfgVars[i].m_pScriptName, m_pCfgVars[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; | ||
} | ||
*/ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this line need to be here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for debug purposes. I also uncomment these lines, because they can be useful for debugging.
We could introduce a verbose flag set during the compile-process, which would activate this line.