- 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;
}
else if ((Flags & CVAR_LATCH) && callbacks && callbacks->MustLatch())
if ((Flags & CVAR_LATCH) && callbacks && callbacks->MustLatch())
{
FLatchedValue latch;
@ -186,16 +186,14 @@ 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);
if (callbacks->SendServerInfoChange(this, value, type)) return;
}
else
{
ForceSet (value, type);
}
}
bool FBaseCVar::ToBool (UCVarValue value, ECVarType type)
{
@ -969,10 +967,8 @@ 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;
}
else
{
int val = *ValueVar;
if (newval)
val |= BitVal;
@ -980,7 +976,6 @@ void FFlagCVar::DoSet (UCVarValue value, ECVarType type)
val &= ~BitVal;
ValueVar = val;
}
}
//
// Mask cvar implementation
@ -1072,13 +1067,14 @@ void FMaskCVar::DoSet (UCVarValue value, ECVarType type)
{
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.
}
}
}
else
{
fallback:
int vval = *ValueVar;
vval &= ~BitVal;
vval |= val;

View file

@ -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)();

View file

@ -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);

View file

@ -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,8 +631,7 @@ 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;
@ -649,17 +648,19 @@ void D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type)
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());
@ -668,6 +669,9 @@ void D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent)
Net_WriteByte((uint8_t)namelen);
Net_WriteBytes((uint8_t*)cvar->GetName(), namelen);
Net_WriteByte(uint8_t(bitnum | (set << 5)));
return true;
}
return false;
}
void D_DoServerInfoChange (uint8_t **stream, bool singlebit)