#include "quakedef.h"
+char *cvar_dummy_description = "custom cvar";
+
cvar_t *cvar_vars = NULL;
-cvar_t *cvar_hashtable[65536];
+cvar_t *cvar_hashtable[CVAR_HASHSIZE];
char *cvar_null_string = "";
/*
cvar_t *var;
// use hash lookup to minimize search time
- hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name));
+ hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name)) % CVAR_HASHSIZE;
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;
+}
+
/*
============
// Loop through the command list and print all matches
for (cvar = cvar_vars; cvar; cvar = cvar->next)
if (!strncasecmp(partial, cvar->name, len))
- Con_Printf ("%c3%s%s : \"%s\" (\"%s\") : %s\n", STRING_COLOR_TAG, cvar->name, STRING_COLOR_DEFAULT_STR, cvar->string, cvar->defstring, cvar->description);
+ Con_Printf ("^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
}
{
qboolean changed;
size_t valuelen;
+ prvm_prog_t *tmpprog;
+ int i;
- changed = strcmp(var->string, value);
+ changed = strcmp(var->string, value) != 0;
// LordHavoc: don't reallocate when there is no change
if (!changed)
return;
// holds weird values it may cause confusion...
if (!strcmp(var->name, "_cl_color"))
{
- CL_SetInfo("topcolor", va("%i", (var->integer >> 4) & 15), true, false, false, false);
- CL_SetInfo("bottomcolor", va("%i", (var->integer) & 15), true, false, false, false);
+ 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);
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 to 0, clear rcon_password for
+ // security reasons (prevents a send-rcon-password-as-plaintext
+ // attack based on NQ protocol session takeover and svc_stufftext)
+ if(var->integer <= 0)
+ Cvar_Set("rcon_password", "");
+ }
+ else if (!strcmp(var->name, "net_slist_favorites"))
+ NetConn_UpdateFavorites();
}
+
+ tmpprog = prog;
+ for(i = 0; i < PRVM_MAXPROGS; ++i)
+ {
+ if(PRVM_ProgLoaded(i))
+ {
+ PRVM_SetProg(i);
+ if(var->globaldefindex_progid[i] == prog->id)
+ {
+ // MUST BE SYNCED WITH prvm_edict.c PRVM_LoadProgs
+ int j;
+ const char *s;
+ prvm_eval_t *val = (prvm_eval_t *)(prog->globals.generic + prog->globaldefs[var->globaldefindex[i]].ofs);
+ switch(prog->globaldefs[var->globaldefindex[i]].type & ~DEF_SAVEGLOBAL)
+ {
+ case ev_float:
+ val->_float = var->value;
+ break;
+ case ev_vector:
+ s = var->string;
+ VectorClear(val->vector);
+ for (j = 0;j < 3;j++)
+ {
+ while (*s && ISWHITESPACE(*s))
+ s++;
+ if (!*s)
+ break;
+ val->vector[j] = atof(s);
+ while (!ISWHITESPACE(*s))
+ s++;
+ if (!*s)
+ break;
+ }
+ break;
+ case ev_string:
+ PRVM_ChangeEngineString(var->globaldefindex_stringno[i], var->string);
+ val->string = var->globaldefindex_stringno[i];
+ break;
+ }
+ }
+ }
+ }
+ prog = tmpprog;
}
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);
}
variable->next = next;
// link to head of list in this hash table index
- hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name));
+ hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name)) % CVAR_HASHSIZE;
variable->nextonhashchain = cvar_hashtable[hashindex];
cvar_hashtable[hashindex] = variable;
}
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;
}
+// check for pure evil
+ if (!*name)
+ {
+ Con_Printf("Cvar_Get: invalid variable name\n");
+ return NULL;
+ }
+
// check for overlap with a command
if (Cmd_Exists (name))
{
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
cvar->next = next;
// link to head of list in this hash table index
- hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name));
+ hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name)) % CVAR_HASHSIZE;
cvar->nextonhashchain = cvar_hashtable[hashindex];
cvar_hashtable[hashindex] = cvar;
// perform a variable print or set
if (Cmd_Argc() == 1)
{
- Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, v->string, v->defstring);
+ Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, ((v->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : v->string), v->defstring);
return true;
}
cvar_t *var;
// restore the default values of all cvars
for (var = cvar_vars ; var ; var = var->next)
- Cvar_SetQuick(var, var->defstring);
+ if((var->flags & CVAR_NORESETTODEFAULTS) == 0)
+ Cvar_SetQuick(var, var->defstring);
}
cvar_t *var;
// restore the default values of all cvars
for (var = cvar_vars ; var ; var = var->next)
- if (!(var->flags & CVAR_SAVE))
+ if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == 0)
Cvar_SetQuick(var, var->defstring);
}
cvar_t *var;
// restore the default values of all cvars
for (var = cvar_vars ; var ; var = var->next)
- if (var->flags & CVAR_SAVE)
+ if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == CVAR_SAVE)
Cvar_SetQuick(var, var->defstring);
}
void Cvar_WriteVariables (qfile_t *f)
{
cvar_t *var;
+ char buf1[MAX_INPUTLINE], buf2[MAX_INPUTLINE];
// don't save cvars that match their default value
for (var = cvar_vars ; var ; var = var->next)
if ((var->flags & CVAR_SAVE) && (strcmp(var->string, var->defstring) || (var->flags & CVAR_ALLOCATED)))
- FS_Printf(f, "%s%s \"%s\"\n", var->flags & CVAR_ALLOCATED ? "seta " : "", var->name, var->string);
+ {
+ Cmd_QuoteString(buf1, sizeof(buf1), var->name, "\"\\$");
+ Cmd_QuoteString(buf2, sizeof(buf2), var->string, "\"\\$");
+ FS_Printf(f, "%s\"%s\" \"%s\"\n", var->flags & CVAR_ALLOCATED ? "seta " : "", buf1, buf2);
+ }
}
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);
+ Con_Printf("%s is \"%s\" [\"%s\"] %s\n", cvar->name, ((cvar->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : 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, (count > 1) ? "s" : "", partial);
+ else
+ Con_Printf("%i cvar%s beginning with \"%s\"\n", count, (count > 1) ? "s" : "", 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);
}
-
+#ifdef FILLALLCVARSWITHRUBBISH
+void Cvar_FillAll_f()
+{
+ char *buf, *p, *q;
+ int n, i;
+ cvar_t *var;
+ qboolean verify;
+ if(Cmd_Argc() != 2)
+ {
+ Con_Printf("Usage: %s length to plant rubbish\n", Cmd_Argv(0));
+ Con_Printf("Usage: %s -length to verify that the rubbish is still there\n", Cmd_Argv(0));
+ return;
+ }
+ n = atoi(Cmd_Argv(1));
+ verify = (n < 0);
+ if(verify)
+ n = -n;
+ buf = Z_Malloc(n + 1);
+ buf[n] = 0;
+ for(var = cvar_vars; var; var = var->next)
+ {
+ for(i = 0, p = buf, q = var->name; i < n; ++i)
+ {
+ *p++ = *q++;
+ if(!*q)
+ q = var->name;
+ }
+ if(verify && strcmp(var->string, buf))
+ {
+ Con_Printf("\n%s does not contain the right rubbish, either this is the first run or a possible overrun was detected, or something changed it intentionally; it DOES contain: %s\n", var->name, var->string);
+ }
+ Cvar_SetQuick(var, buf);
+ }
+ Z_Free(buf);
+}
+#endif /* FILLALLCVARSWITHRUBBISH */