char *CON_CvarString(char *name) { cvar_t *var; var = CON_CvarGet(name); if(!var) return ""; return var->string; }
float CON_CvarValue(char *name) { cvar_t *var; var = CON_CvarGet(name); if(!var) return 0; return datof(var->string); }
static CMD(Seta) { if(!param[0] || !param[1]) { return; } CON_CvarSet(param[0], param[1]); if(netgame) { if(playeringame[0] && consoleplayer == 0) { NET_SV_UpdateCvars(CON_CvarGet(param[0])); } } }
void CON_CvarRegister(cvar_t *variable) { char *oldstr; // first check to see if it has allready been defined if(CON_CvarGet(variable->name)) { CON_Printf(WHITE, "CON_CvarRegister: Can't register variable %s, already defined\n", variable->name); return; } // copy the value off, because future sets will Z_Free it oldstr = variable->string; variable->string = Z_Malloc(dstrlen(variable->string)+1, PU_STATIC, 0); dstrcpy(variable->string, oldstr); variable->value = datof(variable->string); variable->defvalue = Z_Malloc(dstrlen(variable->string)+1, PU_STATIC, 0); dstrcpy(variable->defvalue, variable->string); // link the variable in variable->next = cvarcap; cvarcap = variable; }
void CON_CvarSet(char *var_name, char *value) { cvar_t *var; dboolean changed; var = CON_CvarGet(var_name); if(!var) { // there is an error in C code if this happens CON_Printf(WHITE, "CON_CvarSet: variable %s not found\n", var_name); return; } changed = dstrcmp(var->string, value); Z_Free(var->string); // free the old value string var->string = Z_Malloc(dstrlen(value)+1, PU_STATIC, 0); dstrcpy(var->string, value); var->value = datof(var->string); if(var->callback) var->callback(var); }
alist_t *DoRunActions(alist_t *al, dboolean free) { alist_t *next = NULL; action_t *action; cvar_t *cvar; while(al) { next = al->next; if(dstrcmp(al->cmd, "wait") == 0) break; action = FindAction(al->cmd); if(action) { action->proc(action->data, al->param); } else if(cvar = CON_CvarGet(al->cmd)) { if(netgame) { if(cvar->nonclient) { // I'll just have to assume for now that // player# 0 is the server.. if(consoleplayer != 0) { CON_Warnf("Cannot change cvar that's locked by server\n"); goto next; } } } if(!al->param[0]) { char str[256]; sprintf(str, "%s: %s (%s)", cvar->name, cvar->string, cvar->defvalue); CON_AddLine(str, dstrlen(str)); } else { CON_CvarSet(cvar->name, al->param[0]); if(netgame) { if(playeringame[0] && consoleplayer == 0) NET_SV_UpdateCvars(cvar); } } } else CON_Warnf("Unknown command \"%s\"\n", al->cmd); next: if(free) DerefSingleAction(al); al = next; } if(al) // reached wait command { if(free) DerefSingleAction(al); if(next != NULL) return next; } return al; }