/* Relay -- a tool to record and play Quake2 demos Copyright (C) 2000 Conor Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Conor Davis cedavis@planetquake.com */ #include "sv_local.h" cvar_t *cvar(const char *var_name, const char *value, int flags) { cvar_t *cvar; // search existing cvars for (cvar = server.cvars; cvar; cvar = cvar->next) { if (!strcmp(var_name, cvar->name)) return cvar; } // make a new cvar cvar = Z_Malloc(sizeof(cvar_t)); cvar->name = Z_Strdup(var_name); cvar->string = Z_Strdup(value); cvar->latched_string = NULL; cvar->value = atof(value); cvar->flags = flags; cvar->modified = true; // ??? cvar->next = server.cvars; server.cvars = cvar; return cvar; } void cvar_set(const char *var_name, const char *value) { cvar_t *cvar; for (cvar = server.cvars; cvar; cvar = cvar->next) { if (!strcmp(var_name, cvar->name)) { if (cvar->flags & CVAR_NOSET) return; if (cvar->flags & CVAR_LATCH && server.status == SV_RUNNING) { if (cvar->latched_string) Z_Free(cvar->latched_string); cvar->latched_string = Z_Strdup(value); printf("cvar will be changed for next game\n"); } else { if (cvar->string) Z_Free(cvar->string); cvar->string = Z_Strdup(value); cvar->value = atof(value); cvar->modified = true; // ??? } return; } } // make a new cvar (does the Q2 cvar_set do this?) cvar = Z_Malloc(sizeof(cvar_t)); cvar->name = Z_Strdup(var_name); cvar->string = Z_Strdup(value); cvar->latched_string = NULL; cvar->value = (float)atof(value); cvar->flags = 0; cvar->modified = true; // ??? cvar->next = server.cvars; server.cvars = cvar; } // cvar_forceset disregards CVAR_NOSET and CVAR_LATCH flags void cvar_forceset(const char *var_name, const char *value) { cvar_t *cvar; for (cvar = server.cvars; cvar; cvar = cvar->next) { if (!strcmp(var_name, cvar->name)) { if (cvar->string) Z_Free(cvar->string); cvar->string = Z_Strdup(value); cvar->value = atof(value); cvar->modified = true; // ??? return; } } // make a new cvar (does the Q2 cvar_set do this?) cvar = Z_Malloc(sizeof(cvar_t)); cvar->name = Z_Strdup(var_name); cvar->string = Z_Strdup(value); cvar->latched_string = NULL; cvar->value = (float)atof(value); cvar->flags = 0; cvar->modified = true; // ??? cvar->next = server.cvars; server.cvars = cvar; } void UnlatchCvars() { cvar_t *var; for (var = server.cvars; var; var = var->next) { if (var->latched_string) { Z_Free(var->string); var->string = var->latched_string; var->latched_string = NULL; } } } void FreeAllCvars() { cvar_t *var, *next; for (var = server.cvars; var; var = next) { next = var->next; Z_Free(var->name); Z_Free(var->string); if (var->latched_string) Z_Free(var->latched_string); Z_Free(var); } server.cvars = NULL; }