From 17df95d69efedb5065bb5352f58b1c74548aec35 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 13 Apr 2020 11:53:08 +0200 Subject: [PATCH] - 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. --- src/common/console/c_cvars.cpp | 30 +++++++++----------- src/common/console/c_cvars.h | 4 +-- src/d_netinf.h | 4 +-- src/d_netinfo.cpp | 52 ++++++++++++++++++---------------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/common/console/c_cvars.cpp b/src/common/console/c_cvars.cpp index 20a0119f7..5b15a7ebc 100644 --- a/src/common/console/c_cvars.cpp +++ b/src/common/console/c_cvars.cpp @@ -172,7 +172,7 @@ void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type) { return; } - else if ((Flags & CVAR_LATCH) && callbacks && callbacks->MustLatch()) + if ((Flags & CVAR_LATCH) && callbacks && callbacks->MustLatch()) { FLatchedValue latch; @@ -186,15 +186,13 @@ void FBaseCVar::SetGenericRep (UCVarValue value, ECVarType type) LatchedValues.Push (latch); Flags &= ~CVAR_UNSAFECONTEXT; + return; } - else if ((Flags & CVAR_SERVERINFO) && callbacks && callbacks->SendServerInfoChange) + if ((Flags & CVAR_SERVERINFO) && callbacks && callbacks->SendServerInfoChange) { - callbacks->SendServerInfoChange (this, value, type); - } - else - { - ForceSet (value, type); + if (callbacks->SendServerInfoChange(this, value, type)) return; } + ForceSet (value, 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. 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 - { - int val = *ValueVar; - if (newval) - val |= BitVal; - else - val &= ~BitVal; - ValueVar = val; - } + val &= ~BitVal; + ValueVar = val; } // @@ -1072,13 +1067,14 @@ void FMaskCVar::DoSet (UCVarValue value, ECVarType type) { if (BitVal & (1<SendServerFlagChange (&ValueVar, i, !!(val & (1<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. } } } else { + fallback: int vval = *ValueVar; vval &= ~BitVal; vval |= val; diff --git a/src/common/console/c_cvars.h b/src/common/console/c_cvars.h index 37ae5903d..1b3ac6fa9 100644 --- a/src/common/console/c_cvars.h +++ b/src/common/console/c_cvars.h @@ -109,8 +109,8 @@ class FBaseCVar; struct ConsoleCallbacks { void (*UserInfoChanged)(FBaseCVar*); - void (*SendServerInfoChange)(FBaseCVar* cvar, UCVarValue value, ECVarType type); - void (*SendServerFlagChange)(FBaseCVar* cvar, int bitnum, bool set, bool silent); + bool (*SendServerInfoChange)(FBaseCVar* cvar, UCVarValue value, ECVarType type); + bool (*SendServerFlagChange)(FBaseCVar* cvar, int bitnum, bool set, bool silent); FBaseCVar* (*GetUserCVar)(int playernum, const char* cvarname); bool (*MustLatch)(); diff --git a/src/d_netinf.h b/src/d_netinf.h index 2a360d5a7..5e46b7b14 100644 --- a/src/d_netinf.h +++ b/src/d_netinf.h @@ -54,8 +54,8 @@ void D_SetupUserInfo (void); void D_UserInfoChanged (FBaseCVar *info); -void D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type); -void D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent); +bool D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type); +bool D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent); void D_DoServerInfoChange (uint8_t **stream, bool singlebit); void D_WriteUserInfoStrings (int player, uint8_t **stream, bool compact=false); diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index 1ee85a569..00ad7e62c 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -623,7 +623,7 @@ static const char *SetServerVar (char *name, ECVarType type, uint8_t **stream, b 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) { @@ -631,43 +631,47 @@ void D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type) { Printf("Only setting controllers can change %s\n", cvar->GetName()); 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 ((uint8_t)(namelen | (type << 6))); - Net_WriteBytes ((uint8_t *)cvar->GetName (), (int)namelen); - switch (type) - { - case CVAR_Bool: Net_WriteByte (value.Bool); break; - case CVAR_Int: Net_WriteLong (value.Int); break; - case CVAR_Float: Net_WriteFloat (value.Float); break; - case CVAR_String: Net_WriteString (value.String); break; - default: break; // Silence GCC + Net_WriteByte(DEM_SINFCHANGED); + Net_WriteByte((uint8_t)(namelen | (type << 6))); + Net_WriteBytes((uint8_t*)cvar->GetName(), (int)namelen); + switch (type) + { + case CVAR_Bool: Net_WriteByte(value.Bool); break; + case CVAR_Int: Net_WriteLong(value.Int); break; + case CVAR_Float: Net_WriteFloat(value.Float); break; + case CVAR_String: Net_WriteString(value.String); break; + 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 (netgame && !players[consoleplayer].settings_controller) { 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; } - - 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 false; } void D_DoServerInfoChange (uint8_t **stream, bool singlebit)