memcpy ((char *)var->string, value, valuelen + 1);
var->value = atof (var->string);
var->integer = (int) var->value;
+
+ if(var->internal)
+ {
+ switch (var->internal->type)
+ {
+ case _bool:
+ case _int:
+ case _float:
+ var->internal->integer = var->integer;
+ break;
+ case _string:
+ var->internal->string = (char *)var->string;
+ break;
+ }
+ }
+
if ((var->flags & CF_NOTIFY) && sv.active && !sv_disablenotify.integer)
SV_BroadcastPrintf("\003^3Server cvar \"%s\" changed to \"%s\"\n", var->name, var->string);
#if 0
cvars->hashtable[hashindex] = hash;
}
+void Cvar_RegisterInternal(ivar_t *variable, const char *name, const char *description, int flags)
+{
+ cvar_t *cvar = NULL;
+ char buf[256];
+ int i;
+
+ cvar = Cvar_FindVar(&cvars_all, name, ~0);
+ if(cvar)
+ return;
+
+ cvar = (cvar_t *)Z_Malloc(sizeof(cvar_t));
+ cvar->flags = flags;
+ cvar->name = (char *)Mem_strdup(zonemempool, name);
+ switch (variable->type)
+ {
+ case _bool:
+ case _int:
+ dpsnprintf(buf, sizeof(buf), "%i", variable->integer);
+ break;
+ case _float:
+ dpsnprintf(buf, sizeof(buf), "%.9g", variable->value);
+ break;
+ case _string:
+ dpsnprintf(buf, sizeof(buf), "%s", variable->string);
+ break;
+ }
+
+ cvar->name = (char *)Mem_strdup(zonemempool, name);
+ cvar->string = (char *)Mem_strdup(zonemempool, buf);
+ cvar->defstring = (char *)Mem_strdup(zonemempool, buf);
+ cvar->description = (char *)Mem_strdup(zonemempool, description);
+ cvar->value = variable->value;
+ cvar->integer = variable->integer;
+ cvar->aliases = (char **)Z_Malloc(sizeof(char **));
+ cvar->internal = variable;
+ memset(cvar->aliases, 0, sizeof(char *));
+
+
+ // Mark it as not an autocvar.
+ for (i = 0;i < PRVM_PROG_MAX;i++)
+ cvar->globaldefindex[i] = -1;
+
+ Cvar_Link(cvar, &cvars_all);
+}
+
/*
============
Cvar_RegisterVariable
variable->defstring = (char *)Mem_strdup(zonemempool, variable->string);
variable->value = atof (variable->string);
variable->integer = (int) variable->value;
+ variable->internal = NULL;
variable->aliasindex = 0;
// Mark it as not an autocvar.
cvar->value = atof (cvar->string);
cvar->integer = (int) cvar->value;
cvar->aliases = (char **)Z_Malloc(sizeof(char **));
+ cvar->internal = NULL;
memset(cvar->aliases, 0, sizeof(char *));
if(newdescription && *newdescription)
struct cmd_state_s;
struct qfile_s;
+// TODO
+typedef enum ival_type_e
+{
+ _bool,
+ _int,
+ _float,
+ //_vector,
+ _string
+} ival_type_t;
+
+typedef struct ivar_s
+{
+ union
+ {
+ qbool boolean;
+ int integer;
+ float value;
+ //float *vector;
+ const char *string;
+ };
+
+ ival_type_t type;
+
+} ivar_t;
+
+// Not used, just what the new cvar_t *might* look like.
+typedef struct ncvar_s
+{
+ ivar_t var;
+ ivar_t init;
+ int flags;
+ const char *name;
+ const char *description;
+ const char *string;
+ const char *defstring;
+ void (*callback)(struct ncvar_s *var);
+
+ int globaldefindex[3];
+ int globaldefindex_stringno[3];
+
+ struct ncvar_s *next;
+
+} ncvar_t;
+
typedef struct cvar_s
{
int flags;
int globaldefindex[3];
int globaldefindex_stringno[3];
+ ivar_t *internal;
+
struct cvar_s *next;
} cvar_t;
void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *));
+void Cvar_RegisterInternal(ivar_t *variable, const char *name, const char *description, int flags);
+
/// registers a cvar that already has the name, string, and optionally the
/// archive elements set.
void Cvar_RegisterVariable(cvar_t *variable);
#include "sv_demo.h"
int current_skill;
-cvar_t sv_cheats = {CF_SERVER | CF_NOTIFY, "sv_cheats", "0", "enables cheat commands in any game, and cheat impulses in dpmod"};
+// TODO: Convenience macros? Maybe IVAR_BOOL(sv_cheats, 1) or something
+ivar_t sv_cheats = { .boolean = 0, _bool};
+//cvar_t sv_cheats = {CF_SERVER | CF_NOTIFY, "sv_cheats", "0", "enables cheat commands in any game, and cheat impulses in dpmod"};
cvar_t sv_adminnick = {CF_SERVER | CF_ARCHIVE, "sv_adminnick", "", "nick name to use for admin messages instead of host name"};
cvar_t sv_status_privacy = {CF_SERVER | CF_ARCHIVE, "sv_status_privacy", "0", "do not show IP addresses in 'status' replies to clients"};
cvar_t sv_status_show_qcstatus = {CF_SERVER | CF_ARCHIVE, "sv_status_show_qcstatus", "0", "show the 'qcstatus' field in status replies, not the 'frags' field. Turn this on if your mod uses this field, and the 'frags' field on the other hand has no meaningful value."};
void SV_InitOperatorCommands(void)
{
- Cvar_RegisterVariable(&sv_cheats);
- Cvar_RegisterCallback(&sv_cheats, SV_DisableCheats_c);
+ // TODO: By making cvar_t a superset of ivar_t, we can just cast sv_cheats
+ // to cvar_t and not have to do what ever this shit is.
+ cvar_t *cheats;
+ Cvar_RegisterInternal(&sv_cheats, "sv_cheats", "enables cheat commands in any game, and cheat impulses in dpmod", CF_SERVER | CF_NOTIFY);
+ cheats = Cvar_FindVar(&cvars_all, "sv_cheats", ~0);
+ Cvar_RegisterCallback(cheats, SV_DisableCheats_c);
Cvar_RegisterVariable(&sv_adminnick);
Cvar_RegisterVariable(&sv_status_privacy);
Cvar_RegisterVariable(&sv_status_show_qcstatus);