[server] Implement Console::PrintVariableList

This commit is contained in:
RD42 2023-11-15 18:51:54 +08:00
parent acbd3ab863
commit 0fe7b68fb3
2 changed files with 37 additions and 0 deletions

View File

@ -75,6 +75,38 @@ ConsoleVariable_s* CConsole::FindVariable(char* pVarName)
return NULL; return NULL;
} }
void CConsole::PrintVariableList()
{
char val[1034]; // Max str size of 1024 + the (string) tag.
logprintf("Console Variables:");
StringConvarMap::iterator itor;
for (itor = ConsoleVariables.begin(); itor != ConsoleVariables.end(); itor++)
{
val[0] = 0;
switch (itor->second->VarType)
{
case CON_VARTYPE_FLOAT:
sprintf(val, "%f (float)", *(float*)itor->second->VarPtr);
break;
case CON_VARTYPE_INT:
sprintf(val, "%d (int)", *(int*)itor->second->VarPtr);
break;
case CON_VARTYPE_BOOL:
sprintf(val, "%d (bool)", *(bool*)itor->second->VarPtr);
break;
case CON_VARTYPE_STRING:
sprintf(val, "\"%s\" (string)", (char*)itor->second->VarPtr);
break;
}
const char* VarName = itor->first.c_str();
logprintf(" %s\t%s= %s%s%s%s", VarName, (strlen(VarName)<6)?"\t":"", val,
(itor->second->VarFlags & CON_VARFLAG_READONLY)?" (read-only)":"",
(itor->second->VarFlags & CON_VARFLAG_DEBUG)?" (debug)":"",
(itor->second->VarFlags & CON_VARFLAG_RULE)?" (rule)":"");
}
logprintf("");
}
void CConsole::AddVariable(char* pVarName, CON_VARTYPE VarType, DWORD VarFlags, void* VarPtr, void CConsole::AddVariable(char* pVarName, CON_VARTYPE VarType, DWORD VarFlags, void* VarPtr,
VARCHANGEFUNC VarChangeFunc) VARCHANGEFUNC VarChangeFunc)
{ {

View File

@ -4,6 +4,10 @@
enum CON_VARTYPE {CON_VARTYPE_FLOAT, CON_VARTYPE_INT, CON_VARTYPE_BOOL, CON_VARTYPE_STRING}; enum CON_VARTYPE {CON_VARTYPE_FLOAT, CON_VARTYPE_INT, CON_VARTYPE_BOOL, CON_VARTYPE_STRING};
#define CON_VARFLAG_DEBUG 1
#define CON_VARFLAG_READONLY 2
#define CON_VARFLAG_RULE 4 // Gets sent with a RULES query responce
typedef void (*VARCHANGEFUNC)(); typedef void (*VARCHANGEFUNC)();
struct ConsoleVariable_s struct ConsoleVariable_s
@ -25,6 +29,7 @@ public:
~CConsole(); ~CConsole();
ConsoleVariable_s* FindVariable(char* pVarName); ConsoleVariable_s* FindVariable(char* pVarName);
void PrintVariableList();
void AddVariable(char* pVarName, CON_VARTYPE VarType, DWORD VarFlags, void* VarPtr, void AddVariable(char* pVarName, CON_VARTYPE VarType, DWORD VarFlags, void* VarPtr,
VARCHANGEFUNC VarChangeFunc = NULL); VARCHANGEFUNC VarChangeFunc = NULL);