#include "quakedef.h"
cvar_t *cvar_vars = NULL;
+cvar_t *cvar_hashtable[65536];
char *cvar_null_string = "";
/*
*/
cvar_t *Cvar_FindVar (const char *var_name)
{
+ int hashindex;
cvar_t *var;
- for (var = cvar_vars;var;var = var->next)
+ // 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))
return var;
return buf;
}
+// written by LordHavoc
+void Cvar_CompleteCvarPrint (const char *partial)
+{
+ cvar_t *cvar;
+ size_t len = strlen(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);
+}
+
+
/*
============
Cvar_Set
var->integer = (int) var->value;
if ((var->flags & CVAR_NOTIFY) && changed && sv.active)
SV_BroadcastPrintf("\"%s\" changed to \"%s\"\n", var->name, var->string);
+#if 0
+ // TODO: add infostring support to the server?
+ if ((var->flags & CVAR_SERVERINFO) && changed && sv.active)
+ {
+ InfoString_SetValue(svs.serverinfo, sizeof(svs.serverinfo), var->name, var->string);
+ if (sv.active)
+ {
+ MSG_WriteByte (&sv.reliable_datagram, svc_serverinfostring);
+ MSG_WriteString (&sv.reliable_datagram, var->name);
+ MSG_WriteString (&sv.reliable_datagram, var->string);
+ }
+ }
+#endif
+ if ((var->flags & CVAR_USERINFO) && changed && cls.state != ca_dedicated)
+ {
+ InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), var->name, var->string);
+ if (cls.state == ca_connected)
+ Cmd_ForwardStringToServer(va("setinfo \"%s\" \"%s\"\n", var->name, var->string));
+ }
}
void Cvar_SetQuick (cvar_t *var, const char *value)
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
+ int hashindex;
cvar_t *current, *next, *cvar;
char *oldstr;
cvar_vars = 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));
+ variable->nextonhashchain = cvar_hashtable[hashindex];
+ cvar_hashtable[hashindex] = variable;
}
/*
*/
cvar_t *Cvar_Get (const char *name, const char *value, int flags)
{
- cvar_t *cvar;
+ int hashindex;
+ cvar_t *current, *next, *cvar;
if (developer.integer)
Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
strcpy(cvar->defstring, value);
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
+ cvar->description = "custom cvar";
// link the variable in
- cvar->next = cvar_vars;
- cvar_vars = cvar;
+// alphanumerical order
+ for( current = NULL, next = cvar_vars ; next && strcmp( next->name, cvar->name ) < 0 ; current = next, next = next->next )
+ ;
+ if( current )
+ current->next = cvar;
+ else
+ cvar_vars = cvar;
+ cvar->next = next;
+
+ // link to head of list in this hash table index
+ hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name));
+ cvar->nextonhashchain = cvar_hashtable[hashindex];
+ cvar_hashtable[hashindex] = cvar;
+
return cvar;
}
if (partial && strncasecmp (partial,cvar->name,len))
continue;
- Con_Printf("%s is \"%s\" [\"%s\"]\n", cvar->name, cvar->string, cvar->defstring);
+ Con_Printf("%s is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
count++;
}