- fixed startup-time setup of serverinfo CVARs.

Looks I completely forgot this part when refactoring the interface - it must account for the callbacks not doing anything due to the network code not being operational yet.
This commit is contained in:
Christoph Oelckers 2020-04-13 11:53:08 +02:00
parent 6722b64ac0
commit 17df95d69e
4 changed files with 45 additions and 45 deletions

View file

@ -172,7 +172,7 @@ void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type)
{ {
return; return;
} }
else if ((Flags & CVAR_LATCH) && callbacks && callbacks->MustLatch()) if ((Flags & CVAR_LATCH) && callbacks && callbacks->MustLatch())
{ {
FLatchedValue latch; FLatchedValue latch;
@ -186,15 +186,13 @@ void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type)
LatchedValues.Push (latch); LatchedValues.Push (latch);
Flags &= ~CVAR_UNSAFECONTEXT; Flags &= ~CVAR_UNSAFECONTEXT;
return;
} }
else if ((Flags & CVAR_SERVERINFO) && callbacks && callbacks->SendServerInfoChange) if ((Flags & CVAR_SERVERINFO) && callbacks && callbacks->SendServerInfoChange)
{ {
callbacks->SendServerInfoChange (this, value, type); if (callbacks->SendServerInfoChange(this, value, type)) return;
}
else
{
ForceSet (value, type);
} }
ForceSet (value, type);
} }
bool FBaseCVar::ToBool (UCVarValue value, ECVarType type) bool FBaseCVar::ToBool (UCVarValue value, ECVarType type)
@ -969,17 +967,14 @@ void FFlagCVar::DoSet (UCVarValue value, ECVarType type)
// another flag might have made to the same cvar earlier in the script. // another flag might have made to the same cvar earlier in the script.
if (ValueVar.GetFlags() && callbacks && callbacks->SendServerFlagChange) if (ValueVar.GetFlags() && callbacks && callbacks->SendServerFlagChange)
{ {
callbacks->SendServerFlagChange(&ValueVar, BitNum, newval, false); if (callbacks->SendServerFlagChange(&ValueVar, BitNum, newval, false)) return;
} }
int val = *ValueVar;
if (newval)
val |= BitVal;
else else
{ val &= ~BitVal;
int val = *ValueVar; ValueVar = val;
if (newval)
val |= BitVal;
else
val &= ~BitVal;
ValueVar = val;
}
} }
// //
@ -1072,13 +1067,14 @@ void FMaskCVar::DoSet (UCVarValue value, ECVarType type)
{ {
if (BitVal & (1<<i)) if (BitVal & (1<<i))
{ {
callbacks->SendServerFlagChange (&ValueVar, i, !!(val & (1<<i)), silent); if (!callbacks->SendServerFlagChange(&ValueVar, i, !!(val & (1 << i)), silent)) goto fallback; // the failure case here is either always or never.
silent = true; // only warn once if SendServerFlagChange needs to. silent = true; // only warn once if SendServerFlagChange needs to.
} }
} }
} }
else else
{ {
fallback:
int vval = *ValueVar; int vval = *ValueVar;
vval &= ~BitVal; vval &= ~BitVal;
vval |= val; vval |= val;

View file

@ -109,8 +109,8 @@ class FBaseCVar;
struct ConsoleCallbacks struct ConsoleCallbacks
{ {
void (*UserInfoChanged)(FBaseCVar*); void (*UserInfoChanged)(FBaseCVar*);
void (*SendServerInfoChange)(FBaseCVar* cvar, UCVarValue value, ECVarType type); bool (*SendServerInfoChange)(FBaseCVar* cvar, UCVarValue value, ECVarType type);
void (*SendServerFlagChange)(FBaseCVar* cvar, int bitnum, bool set, bool silent); bool (*SendServerFlagChange)(FBaseCVar* cvar, int bitnum, bool set, bool silent);
FBaseCVar* (*GetUserCVar)(int playernum, const char* cvarname); FBaseCVar* (*GetUserCVar)(int playernum, const char* cvarname);
bool (*MustLatch)(); bool (*MustLatch)();

View file

@ -54,8 +54,8 @@ void D_SetupUserInfo (void);
void D_UserInfoChanged (FBaseCVar *info); void D_UserInfoChanged (FBaseCVar *info);
void D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type); bool D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type);
void D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent); bool D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent);
void D_DoServerInfoChange (uint8_t **stream, bool singlebit); void D_DoServerInfoChange (uint8_t **stream, bool singlebit);
void D_WriteUserInfoStrings (int player, uint8_t **stream, bool compact=false); void D_WriteUserInfoStrings (int player, uint8_t **stream, bool compact=false);

View file

@ -623,7 +623,7 @@ static const char *SetServerVar (char *name, ECVarType type, uint8_t **stream, b
EXTERN_CVAR (Float, sv_gravity) EXTERN_CVAR (Float, sv_gravity)
void D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type) bool D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type)
{ {
if (gamestate != GS_STARTUP && !demoplayback) if (gamestate != GS_STARTUP && !demoplayback)
{ {
@ -631,43 +631,47 @@ void D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type)
{ {
Printf("Only setting controllers can change %s\n", cvar->GetName()); Printf("Only setting controllers can change %s\n", cvar->GetName());
cvar->MarkSafe(); cvar->MarkSafe();
return; return true;
} }
} size_t namelen;
size_t namelen;
namelen = strlen (cvar->GetName ()); namelen = strlen(cvar->GetName());
Net_WriteByte (DEM_SINFCHANGED); Net_WriteByte(DEM_SINFCHANGED);
Net_WriteByte ((uint8_t)(namelen | (type << 6))); Net_WriteByte((uint8_t)(namelen | (type << 6)));
Net_WriteBytes ((uint8_t *)cvar->GetName (), (int)namelen); Net_WriteBytes((uint8_t*)cvar->GetName(), (int)namelen);
switch (type) switch (type)
{ {
case CVAR_Bool: Net_WriteByte (value.Bool); break; case CVAR_Bool: Net_WriteByte(value.Bool); break;
case CVAR_Int: Net_WriteLong (value.Int); break; case CVAR_Int: Net_WriteLong(value.Int); break;
case CVAR_Float: Net_WriteFloat (value.Float); break; case CVAR_Float: Net_WriteFloat(value.Float); break;
case CVAR_String: Net_WriteString (value.String); break; case CVAR_String: Net_WriteString(value.String); break;
default: break; // Silence GCC default: break; // Silence GCC
}
return true;
} }
return false;
} }
void D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent) bool D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent)
{ {
if (gamestate != GS_STARTUP && !demoplayback) if (gamestate != GS_STARTUP && !demoplayback)
{ {
if (netgame && !players[consoleplayer].settings_controller) if (netgame && !players[consoleplayer].settings_controller)
{ {
if (!silent) Printf("Only setting controllers can change %s\n", cvar->GetName()); if (!silent) Printf("Only setting controllers can change %s\n", cvar->GetName());
return; return true;
} }
int namelen = (int)strlen(cvar->GetName());
Net_WriteByte(DEM_SINFCHANGEDXOR);
Net_WriteByte((uint8_t)namelen);
Net_WriteBytes((uint8_t*)cvar->GetName(), namelen);
Net_WriteByte(uint8_t(bitnum | (set << 5)));
return true;
} }
return false;
int namelen = (int)strlen (cvar->GetName ());
Net_WriteByte (DEM_SINFCHANGEDXOR);
Net_WriteByte ((uint8_t)namelen);
Net_WriteBytes ((uint8_t *)cvar->GetName (), namelen);
Net_WriteByte (uint8_t(bitnum | (set << 5)));
} }
void D_DoServerInfoChange (uint8_t **stream, bool singlebit) void D_DoServerInfoChange (uint8_t **stream, bool singlebit)