return buf;
}
+void Cvar_PrintHelp(cvar_t *cvar, qboolean full)
+{
+ Con_Printf("^3%s^7 is \"%s\" [\"%s\"] ", cvar->name, ((cvar->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : cvar->string), cvar->defstring);
+ if (full)
+ Con_Printf("%s", cvar->description);
+ Con_Printf("\n");
+}
+
// written by LadyHavoc
void Cvar_CompleteCvarPrint(cvar_state_t *cvars, const char *partial, int neededflags)
{
// Loop through the command list and print all matches
for (cvar = cvars->vars; cvar; cvar = cvar->next)
if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags))
- Con_Printf ("^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
+ Cvar_PrintHelp(cvar, true);
}
// check if a cvar is held by some progs
qboolean changed;
size_t valuelen;
char vabuf[1024];
+ char new_value[MAX_INPUTLINE];
changed = strcmp(var->string, value) != 0;
// LadyHavoc: don't reallocate when there is no change
if (!changed)
return;
+ memcpy(new_value,value,MAX_INPUTLINE);
+
+ // Call the function stored in the cvar for bounds checking, cleanup, etc
+ if (var->callback)
+ var->callback(new_value);
+
// LadyHavoc: don't reallocate when the buffer is the same size
- valuelen = strlen(value);
+ valuelen = strlen(new_value);
if (!var->string || strlen(var->string) != valuelen)
{
Z_Free ((char *)var->string); // free the old value string
var->string = (char *)Z_Malloc (valuelen + 1);
}
- memcpy ((char *)var->string, value, valuelen + 1);
+ memcpy ((char *)var->string, new_value, valuelen + 1);
var->value = atof (var->string);
var->integer = (int) var->value;
if ((var->flags & CVAR_NOTIFY) && changed && sv.active && !sv_disablenotify.integer)
- SV_BroadcastPrintf("\"%s\" changed to \"%s\"\n", var->name, var->string);
+ SV_BroadcastPrintf("\001^3Server cvar \"%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)
Cvar_Set(cvars, var_name, val);
}
+void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(char *))
+{
+ variable->callback = callback;
+}
+
/*
============
Cvar_RegisterVariable
// perform a variable print or set
if (Cmd_Argc(cmd) == 1)
{
- Con_Printf("\"%s\" is \"%s\" [\"%s\"]\n", v->name, ((v->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : v->string), v->defstring);
+ Cvar_PrintHelp(v, true);
return true;
}
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->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : cvar->string), cvar->defstring, cvar->description);
+ Cvar_PrintHelp(cvar, true);
count++;
}