{
qboolean changed;
size_t valuelen;
- 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(new_value);
+ valuelen = strlen(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, new_value, valuelen + 1);
+ memcpy ((char *)var->string, value, valuelen + 1);
var->value = atof (var->string);
var->integer = (int) var->value;
if ((var->flags & CVAR_NOTIFY) && changed && sv.active && !sv_disablenotify.integer)
CL_SetInfo(var->name, var->string, true, false, false, false);
Cvar_UpdateAutoCvar(var);
+
+ // Call the function stored in the cvar for bounds checking, cleanup, etc
+ if (var->callback)
+ var->callback(var);
}
void Cvar_SetQuick (cvar_t *var, const char *value)
void Cvar_Set_NoCallback(cvar_t *var, const char *value)
{
- void (*callback_save)(char *) = var->callback;
+ void (*callback_save)(cvar_t *) = var->callback;
var->callback = NULL;
Cvar_SetQuick_Internal(var, value);
var->callback = callback_save;
Cvar_Set(cvars, var_name, val);
}
-void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(char *))
+void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *))
{
variable->callback = callback;
}
const char *defstring;
- void (*callback)(char *value);
+ void (*callback)(struct cvar_s *var);
qboolean ignore_callback;
char **aliases;
void Cvar_RegisterAlias(cvar_t *variable, const char *alias );
-void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(char *));
+void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *));
/// registers a cvar that already has the name, string, and optionally the
/// archive elements set.
cvar_t cl_color = {CVAR_READONLY | CVAR_CLIENT | CVAR_SAVE, "_cl_color", "0", "internal storage cvar for current player colors (changed by color command)"};
// Ignore the callbacks so this two-to-three way synchronization doesn't cause an infinite loop.
-static void CL_Color_c(char *string)
+static void CL_Color_c(cvar_t *var)
{
char vabuf[1024];
- Cvar_Set_NoCallback(&topcolor, va(vabuf, sizeof(vabuf), "%i", ((atoi(string) >> 4) & 15)));
- Cvar_Set_NoCallback(&bottomcolor, va(vabuf, sizeof(vabuf), "%i", (atoi(string) & 15)));
+ Cvar_Set_NoCallback(&topcolor, va(vabuf, sizeof(vabuf), "%i", ((var->integer >> 4) & 15)));
+ Cvar_Set_NoCallback(&bottomcolor, va(vabuf, sizeof(vabuf), "%i", (var->integer & 15)));
}
-static void CL_Topcolor_c(char *string)
+static void CL_Topcolor_c(cvar_t *var)
{
char vabuf[1024];
- Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", atoi(string)*16 + bottomcolor.integer));
+ Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", var->integer*16 + bottomcolor.integer));
}
-static void CL_Bottomcolor_c(char *string)
+static void CL_Bottomcolor_c(cvar_t *var)
{
char vabuf[1024];
- Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", topcolor.integer*16 + atoi(string)));
+ Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", topcolor.integer*16 + var->integer));
}
static void CL_Color_f(cmd_state_t *cmd)
}
}
-static void CL_RCon_ClearPassword_c(char *string)
+static void CL_RCon_ClearPassword_c(cvar_t *var)
{
// 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(atoi(string) <= 0)
+ if(var->integer <= 0)
Cvar_SetQuick(&rcon_password, "");
}
static int nFavorites_idfp = 0;
static char favorites_idfp[MAX_FAVORITESERVERS][FP64_SIZE+1];
-void NetConn_UpdateFavorites_c(char *string)
+void NetConn_UpdateFavorites_c(cvar_t *var)
{
const char *p;
nFavorites = 0;
nFavorites_idfp = 0;
- p = string;
+ p = var->string;
while((size_t) nFavorites < sizeof(favorites) / sizeof(*favorites) && COM_ParseToken_Console(&p))
{
if(com_token[0] != '[' && strlen(com_token) == FP64_SIZE && !strchr(com_token, '.'))
void ServerList_QueryList(qboolean resetcache, qboolean querydp, qboolean queryqw, qboolean consoleoutput);
/// called whenever net_slist_favorites changes
-void NetConn_UpdateFavorites_c(char *string);
+void NetConn_UpdateFavorites_c(cvar_t *var);
#endif
#define MAX_CHALLENGES 128
//===========================================================================
// Disable cheats if sv_cheats is turned off
-static void SV_DisableCheats_c(char *value)
+static void SV_DisableCheats_c(cvar_t *var)
{
prvm_prog_t *prog = SVVM_prog;
int i = 0;
- if (value[0] == '0' && !value[1])
+ if (var->value == 0)
{
while (svs.clients[i].edict)
{
#undef PRVM_DECLARE_function
};
-static void Host_Timescale_c(char *string)
+static void Host_Timescale_c(cvar_t *var)
{
- double value;
- value = atof(string);
-
- if(value < 0.00001 && value != 0)
- string[0] = '0', string[1] = 0;
+ if(var->value < 0.00001 && var->value != 0)
+ Cvar_SetValueQuick(var, 0);
}
//============================================================================