X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=cvar.c;h=111550a8632107df7d141d4aebf2592965cdc128;hb=64187ca9a50c407b6679eae12a533ef856306f86;hp=75ff70f44ad1242b7d2b630190d79b756d49605e;hpb=90571e84116d49ec97a787f2728ff24beb3d0253;p=xonotic%2Fdarkplaces.git diff --git a/cvar.c b/cvar.c index 75ff70f4..111550a8 100644 --- a/cvar.c +++ b/cvar.c @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 = ""; /* @@ -38,7 +38,7 @@ cvar_t *Cvar_FindVar (const char *var_name) 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 (!strcmp (var_name, var->name)) return var; @@ -220,7 +220,7 @@ void Cvar_CompleteCvarPrint (const char *partial) // 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); } @@ -234,7 +234,7 @@ void Cvar_SetQuick_Internal (cvar_t *var, const char *value) qboolean changed; size_t valuelen; - changed = strcmp(var->string, value); + changed = strcmp(var->string, value) != 0; // LordHavoc: don't reallocate when there is no change if (!changed) return; @@ -299,7 +299,7 @@ void Cvar_SetQuick_Internal (cvar_t *var, const char *value) // 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) + if(var->integer <= 0) Cvar_Set("rcon_password", ""); } else if (!strcmp(var->name, "net_slist_favorites")) @@ -449,7 +449,7 @@ void Cvar_RegisterVariable (cvar_t *variable) 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; } @@ -493,6 +493,13 @@ cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *ne 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)) { @@ -536,7 +543,7 @@ cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *ne 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; @@ -563,7 +570,7 @@ qboolean Cvar_Command (void) // 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; } @@ -617,7 +624,8 @@ void Cvar_ResetToDefaults_All_f (void) 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); } @@ -626,7 +634,7 @@ void Cvar_ResetToDefaults_NoSaveOnly_f (void) 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); } @@ -636,7 +644,7 @@ void Cvar_ResetToDefaults_SaveOnly_f (void) 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); } @@ -652,11 +660,16 @@ with the archive flag set to true. 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); + } } @@ -694,16 +707,16 @@ void Cvar_List_f (void) 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 (len) { if(ispattern) - Con_Printf("%i cvar(s) matching \"%s\"\n", count, partial); + Con_Printf("%i cvar%s matching \"%s\"\n", count, (count > 1) ? "s" : "", partial); else - Con_Printf("%i cvar(s) beginning with \"%s\"\n", count, partial); + Con_Printf("%i cvar%s beginning with \"%s\"\n", count, (count > 1) ? "s" : "", partial); } else Con_Printf("%i cvar(s)\n", count); @@ -762,4 +775,39 @@ void Cvar_SetA_f (void) 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 */