mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-29 20:50:58 +00:00
When save/loading config use revert value for netvars if you are not the server
This commit is contained in:
parent
f5e4d076b9
commit
b67807dd04
1 changed files with 77 additions and 8 deletions
|
@ -1393,6 +1393,18 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth)
|
|||
for (i = MAXVAL+1; var->PossibleValue[i].strvalue; i++)
|
||||
if (v == var->PossibleValue[i].value || !stricmp(var->PossibleValue[i].strvalue, valstr))
|
||||
{
|
||||
if (client && execversion_enabled)
|
||||
{
|
||||
if (var->revert.allocated)
|
||||
{
|
||||
Z_Free(var->revert.v.string);
|
||||
}
|
||||
|
||||
var->revert.v.const_munge = var->PossibleValue[i].strvalue;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var->value = var->PossibleValue[i].value;
|
||||
var->string = var->PossibleValue[i].strvalue;
|
||||
goto finish;
|
||||
|
@ -1453,12 +1465,36 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth)
|
|||
// ...or not.
|
||||
goto badinput;
|
||||
found:
|
||||
if (client && execversion_enabled)
|
||||
{
|
||||
if (var->revert.allocated)
|
||||
{
|
||||
Z_Free(var->revert.v.string);
|
||||
}
|
||||
|
||||
var->revert.v.const_munge = var->PossibleValue[i].strvalue;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var->value = var->PossibleValue[i].value;
|
||||
var->string = var->PossibleValue[i].strvalue;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
if (client && execversion_enabled)
|
||||
{
|
||||
if (var->revert.allocated)
|
||||
{
|
||||
Z_Free(var->revert.v.string);
|
||||
}
|
||||
|
||||
var->revert.v.string = Z_StrDup(valstr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// free the old value string
|
||||
Z_Free(var->zstring);
|
||||
|
||||
|
@ -1796,6 +1832,14 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth)
|
|||
// send the value of the variable
|
||||
UINT8 buf[128];
|
||||
UINT8 *p = buf;
|
||||
|
||||
// Loading from a config in a netgame? Set revert value.
|
||||
if (client && execversion_enabled)
|
||||
{
|
||||
Setvalue(var, value, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(server || (addedtogame && IsPlayerAdmin(consoleplayer))))
|
||||
{
|
||||
CONS_Printf(M_GetText("Only the server or admin can change: %s %s\n"), var->name, var->string);
|
||||
|
@ -2329,18 +2373,43 @@ void CV_SaveVariables(FILE *f)
|
|||
{
|
||||
char stringtowrite[MAXTEXTCMD+1];
|
||||
|
||||
// Silly hack for Min/Max vars
|
||||
if (!strcmp(cvar->string, "MAX") || !strcmp(cvar->string, "MIN"))
|
||||
const char * string;
|
||||
|
||||
if (cvar->revert.v.string != NULL)
|
||||
{
|
||||
if (cvar->flags & CV_FLOAT)
|
||||
sprintf(stringtowrite, "%f", FIXED_TO_FLOAT(cvar->value));
|
||||
else
|
||||
sprintf(stringtowrite, "%d", cvar->value);
|
||||
string = cvar->revert.v.string;
|
||||
}
|
||||
else
|
||||
strcpy(stringtowrite, cvar->string);
|
||||
{
|
||||
string = cvar->string;
|
||||
}
|
||||
|
||||
fprintf(f, "%s \"%s\"\n", cvar->name, stringtowrite);
|
||||
// Silly hack for Min/Max vars
|
||||
#define MINVAL 0
|
||||
#define MAXVAL 1
|
||||
if (
|
||||
cvar->PossibleValue != NULL &&
|
||||
cvar->PossibleValue[0].strvalue &&
|
||||
stricmp(cvar->PossibleValue[0].strvalue, "MIN") == 0
|
||||
){ // bounded cvar
|
||||
int which = stricmp(string, "MAX") == 0;
|
||||
|
||||
if (which || stricmp(string, "MIN") == 0)
|
||||
{
|
||||
INT32 value = cvar->PossibleValue[which].value;
|
||||
|
||||
if (cvar->flags & CV_FLOAT)
|
||||
sprintf(stringtowrite, "%f", FIXED_TO_FLOAT(value));
|
||||
else
|
||||
sprintf(stringtowrite, "%d", value);
|
||||
|
||||
string = stringtowrite;
|
||||
}
|
||||
}
|
||||
#undef MINVAL
|
||||
#undef MAXVAL
|
||||
|
||||
fprintf(f, "%s \"%s\"\n", cvar->name, string);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue