#include "quakedef.h"
+char *cvar_dummy_description = "custom cvar";
+
cvar_t *cvar_vars = NULL;
cvar_t *cvar_hashtable[65536];
char *cvar_null_string = "";
// use hash lookup to minimize search time
hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name));
for (var = cvar_hashtable[hashindex];var;var = var->nextonhashchain)
- if (!strcasecmp (var_name, var->name))
+ if (!strcmp (var_name, var->name))
return var;
return NULL;
return var->defstring;
}
+/*
+============
+Cvar_VariableDescription
+============
+*/
+const char *Cvar_VariableDescription (const char *var_name)
+{
+ cvar_t *var;
+
+ var = Cvar_FindVar (var_name);
+ if (!var)
+ return cvar_null_string;
+ return var->description;
+}
+
/*
============
#endif
if ((var->flags & CVAR_USERINFO) && cls.state != ca_dedicated)
CL_SetInfo(var->name, var->string, true, false, false, false);
+ else if ((var->flags & CVAR_NQUSERINFOHACK) && cls.state != ca_dedicated)
+ {
+ // update the cls.userinfo to have proper values for the
+ // silly nq config variables.
+ //
+ // this is done when these variables are changed rather than at
+ // connect time because if the user or code checks the userinfo and it
+ // holds weird values it may cause confusion...
+ if (!strcmp(var->name, "_cl_color"))
+ {
+ int top = (var->integer >> 4) & 15, bottom = var->integer & 15;
+ CL_SetInfo("topcolor", va("%i", top), true, false, false, false);
+ CL_SetInfo("bottomcolor", va("%i", bottom), true, false, false, false);
+ if (cls.protocol != PROTOCOL_QUAKEWORLD && cls.netcon)
+ {
+ MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
+ MSG_WriteString(&cls.netcon->message, va("color %i %i", top, bottom));
+ }
+ }
+ else if (!strcmp(var->name, "_cl_rate"))
+ CL_SetInfo("rate", va("%i", var->integer), true, false, false, false);
+ else if (!strcmp(var->name, "_cl_playerskin"))
+ CL_SetInfo("playerskin", var->string, true, false, false, false);
+ else if (!strcmp(var->name, "_cl_playermodel"))
+ CL_SetInfo("playermodel", var->string, true, false, false, false);
+ else if (!strcmp(var->name, "_cl_name"))
+ CL_SetInfo("name", var->string, true, false, false, false);
+ else if (!strcmp(var->name, "rcon_secure"))
+ {
+ // whenever rcon_secure is changed, clear rcon_password for
+ // security reasons (prevents a send-rcon-password-as-plaintext
+ // attack based on NQ protocol session takeover and svc_stufftext)
+ Cvar_Set("rcon_password", "");
+ }
+ }
}
void Cvar_SetQuick (cvar_t *var, const char *value)
char val[MAX_INPUTLINE];
if ((float)((int)value) == value)
- sprintf(val, "%i", (int)value);
+ dpsnprintf(val, sizeof(val), "%i", (int)value);
else
- sprintf(val, "%f", value);
+ dpsnprintf(val, sizeof(val), "%f", value);
Cvar_SetQuick(var, val);
}
char val[MAX_INPUTLINE];
if ((float)((int)value) == value)
- sprintf(val, "%i", (int)value);
+ dpsnprintf(val, sizeof(val), "%i", (int)value);
else
- sprintf(val, "%f", value);
+ dpsnprintf(val, sizeof(val), "%f", value);
Cvar_Set(var_name, val);
}
Adds a newly allocated variable to the variable list or sets its value.
============
*/
-cvar_t *Cvar_Get (const char *name, const char *value, int flags)
+cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *newdescription)
{
int hashindex;
cvar_t *current, *next, *cvar;
{
cvar->flags |= flags;
Cvar_SetQuick_Internal (cvar, value);
+ if(newdescription && (cvar->flags & CVAR_ALLOCATED))
+ {
+ if(cvar->description != cvar_dummy_description)
+ Z_Free(cvar->description);
+
+ if(*newdescription)
+ {
+ alloclen = strlen(newdescription) + 1;
+ cvar->description = (char *)Z_Malloc(alloclen);
+ memcpy(cvar->description, newdescription, alloclen);
+ }
+ else
+ cvar->description = cvar_dummy_description;
+ }
return cvar;
}
memcpy(cvar->defstring, value, alloclen);
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
- cvar->description = "custom cvar";
+
+ if(newdescription && *newdescription)
+ {
+ alloclen = strlen(newdescription) + 1;
+ cvar->description = (char *)Z_Malloc(alloclen);
+ memcpy(cvar->description, newdescription, alloclen);
+ }
+ else
+ cvar->description = cvar_dummy_description; // actually checked by VM_cvar_type
// link the variable in
// alphanumerical order
const char *partial;
size_t len;
int count;
+ qboolean ispattern;
if (Cmd_Argc() > 1)
{
len = 0;
}
+ ispattern = partial && (strchr(partial, '*') || strchr(partial, '?'));
+
count = 0;
for (cvar = cvar_vars; cvar; cvar = cvar->next)
{
- if (partial && strncasecmp (partial,cvar->name,len))
+ if (len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp (partial,cvar->name,len)))
continue;
Con_Printf("%s is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
count++;
}
- if (partial)
- Con_Printf("%i cvar(s) beginning with \"%s\"\n", count, partial);
+ if (len)
+ {
+ if(ispattern)
+ Con_Printf("%i cvar(s) matching \"%s\"\n", count, partial);
+ else
+ Con_Printf("%i cvar(s) beginning with \"%s\"\n", count, partial);
+ }
else
Con_Printf("%i cvar(s)\n", count);
}
// make sure it's the right number of parameters
if (Cmd_Argc() < 3)
{
- Con_Printf("Set: wrong number of parameters, usage: set <variablename> <value>\n");
+ Con_Printf("Set: wrong number of parameters, usage: set <variablename> <value> [<description>]\n");
return;
}
return;
}
- Con_DPrint("Set: ");
+ if (developer.integer >= 100)
+ Con_DPrint("Set: ");
// all looks ok, create/modify the cvar
- Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0);
+ Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), 0, Cmd_Argc() > 3 ? Cmd_Argv(3) : NULL);
}
void Cvar_SetA_f (void)
// make sure it's the right number of parameters
if (Cmd_Argc() < 3)
{
- Con_Printf("SetA: wrong number of parameters, usage: seta <variablename> <value>\n");
+ Con_Printf("SetA: wrong number of parameters, usage: seta <variablename> <value> [<description>]\n");
return;
}
return;
}
- Con_DPrint("SetA: ");
+ if (developer.integer >= 100)
+ Con_DPrint("SetA: ");
// all looks ok, create/modify the cvar
- Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE);
+ Cvar_Get(Cmd_Argv(1), Cmd_Argv(2), CVAR_SAVE, Cmd_Argc() > 3 ? Cmd_Argv(3) : NULL);
}