Allow user-created variables

This commit is contained in:
smallmodel 2024-11-11 20:41:54 +01:00
parent 50fdbaf152
commit 9e060d11b6
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
3 changed files with 42 additions and 1 deletions

View file

@ -120,6 +120,7 @@ functions exported to the main executable
// console variable interaction
cvar_t *(*Cvar_Get)(const char *var_name, const char *value, int flags);
cvar_t *(*Cvar_Find)(const char *var_name);
void (*Cvar_Set)(const char *var_name, const char *value);
// ClientCommand and ConsoleCommand parameter access

View file

@ -514,6 +514,7 @@ Returns whether or not the variable should be filtered
*/
static qboolean CG_IsVariableFiltered(const char *name)
{
cvar_t *var;
size_t i;
for (i = 0; i < ARRAY_LEN(whiteListedVariables); i++) {
@ -530,6 +531,42 @@ static qboolean CG_IsVariableFiltered(const char *name)
}
}
// Filtered
return qtrue;
}
/*
====================
CG_IsSetVariableFiltered
Returns whether or not the variable should be filtered
====================
*/
static qboolean CG_IsSetVariableFiltered(const char *name, char type)
{
cvar_t *var;
if (!CG_IsVariableFiltered(name)) {
return qfalse;
}
if (type != 'u' && type != 's') {
// Don't allow custom info variables to avoid flooding
// the client with many serverinfo and userinfo variables
var = cgi.Cvar_Find(name);
if (!var) {
// Allow as it doesn't exist
return qfalse;
}
if (var->flags & CVAR_USER_CREATED) {
// Allow, it's user-created, wouldn't cause issues
return qfalse;
}
}
// Filtered
return qtrue;
}
@ -609,6 +646,8 @@ static qboolean CG_IsStatementFiltered(char *cmd)
if (!Q_stricmp(com_token, "set") || !Q_stricmp(com_token, "setu") || !Q_stricmp(com_token, "seta")
|| !Q_stricmp(com_token, "sets")) {
char type = com_token[3];
//
// variable
//
@ -618,7 +657,7 @@ static qboolean CG_IsStatementFiltered(char *cmd)
continue;
}
if (CG_IsVariableFiltered(com_token)) {
if (CG_IsSetVariableFiltered(com_token, type)) {
return qtrue;
}
} else {

View file

@ -627,6 +627,7 @@ void CL_InitCGameDLL( clientGameImport_t *cgi, clientGameExport_t **cge ) {
cgi->LV_ConvertString = Sys_LV_CL_ConvertString;
cgi->Cvar_Get = Cvar_Get;
cgi->Cvar_Find = Cvar_FindVar;
cgi->Cvar_Set = Cvar_Set;
cgi->Argc = Cmd_Argc;