# HG changeset patch # User Adam Kaminski # Date 1614482989 18000 # Sat Feb 27 22:29:49 2021 -0500 # Node ID 876945e8eb3f402174de0eda930f45cab5618417 # Parent bc79b72158c20d5dce35a86b64a2257fcdad1fb8 Moved SERVER_FlagsetChanged to sv_main.cpp, also made sure any changed flags belonging to "lmsspectatorsettings" get printed as well. diff -r bc79b72158c2 -r 876945e8eb3f src/d_main.cpp --- a/src/d_main.cpp Sun Feb 21 14:42:52 2021 -0500 +++ b/src/d_main.cpp Sat Feb 27 22:29:49 2021 -0500 @@ -402,71 +402,6 @@ //========================================================================== // -// [AK] SERVER_FlagsetChanged -// -// Lists all flag-type CVars belonging to a particular flagset which have -// been changed through modification of the flagset, then prints them to the -// console. If too many flags were changed, then the total number of flags -// is printed to the console instead, thereby shortening the length of the -// message. The name of the flagset and its new value are printed too. -// -//========================================================================== - -void SERVER_FlagsetChanged( FIntCVar& flagset, int maxflags = 2 ) -{ - int value = static_cast( flagset ); - int oldValue = flagset.GetPastValue( ); - - // [AK] Only continue if we're the server, and the value actually changed from before. - if (( NETWORK_GetState( ) != NETSTATE_SERVER ) || ( gamestate == GS_STARTUP ) || ( value == oldValue )) - return; - - FString result; - int flagsChanged = 0; - - for ( int i = 0; i < 32; i++ ) - { - unsigned int bit = ( 1 << i ); - - // [AK] Don't continue if this bit hasn't changed. - if ((( value ^ oldValue ) & bit ) == 0 ) - continue; - - // [AK] Print the name of the CVar and its new value while we still can. - if ( ++flagsChanged <= maxflags ) - { - for ( FBaseCVar* cvar = CVars; cvar; cvar = cvar->GetNext( ) ) - { - // [AK] Make sure that this CVar is a flag. - if ( cvar->IsFlagCVar( ) == false ) - continue; - - FFlagCVar* flagCVar = static_cast( cvar ); - - // [AK] Check if this CVar belongs to the flagset and matches the corresponding bit. - if (( flagCVar->GetValueVar( ) == &flagset ) && ( flagCVar->GetBitVal( ) == bit )) - { - if ( flagsChanged > 1 ) - result += ", "; - - result.AppendFormat( "%s %s", flagCVar->GetName( ), ( value & bit ) ? "ON" : "OFF" ); - break; - } - } - } - } - - // [AK] If too many flags changed, just print how many flags were changed instead. - // This way, we don't print an excessively long message to the console. - if ( flagsChanged > maxflags ) - result.Format( "%d flags changed", flagsChanged ); - - SERVER_Printf( "%s changed to: %d (%s)\n", flagset.GetName( ), value, result ); - SERVERCOMMANDS_SetGameDMFlags( ); -} - -//========================================================================== -// // CVAR dmflags // //========================================================================== diff -r bc79b72158c2 -r 876945e8eb3f src/lastmanstanding.cpp --- a/src/lastmanstanding.cpp Sun Feb 21 14:42:52 2021 -0500 +++ b/src/lastmanstanding.cpp Sat Feb 27 22:29:49 2021 -0500 @@ -803,12 +803,7 @@ CUSTOM_CVAR( Int, lmsspectatorsettings, LMS_SPF_VIEW, CVAR_SERVERINFO ) { - if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) - { - SERVER_Printf( "%s changed to: %d\n", self.GetName( ), (int)self ); - // [BB] Due to ZADF_ALWAYS_APPLY_LMS_SPECTATORSETTINGS, this is necessary in all game modes. - SERVERCOMMANDS_SetLMSSpectatorSettings( ); - } + SERVER_FlagsetChanged( self ); } CVAR( Flag, lms_spectatorchat, lmsspectatorsettings, LMS_SPF_CHAT ); CVAR( Flag, lms_spectatorview, lmsspectatorsettings, LMS_SPF_VIEW ); diff -r bc79b72158c2 -r 876945e8eb3f src/sv_main.cpp --- a/src/sv_main.cpp Sun Feb 21 14:42:52 2021 -0500 +++ b/src/sv_main.cpp Sat Feb 27 22:29:49 2021 -0500 @@ -4291,6 +4291,69 @@ } //***************************************************************************** +// +// [AK] Lists all flag-type CVars belonging to the passed flagset which have +// been changed, then prints them to the console. +// +void SERVER_FlagsetChanged( FIntCVar& flagset, int maxflags ) +{ + int value = static_cast( flagset ); + int oldValue = flagset.GetPastValue( ); + + // [AK] Only continue if we're the server, and the value actually changed from before. + if (( NETWORK_GetState( ) != NETSTATE_SERVER ) || ( gamestate == GS_STARTUP ) || ( value == oldValue )) + return; + + FString result; + int flagsChanged = 0; + + for ( int i = 0; i < 32; i++ ) + { + unsigned int bit = ( 1 << i ); + + // [AK] Don't continue if this bit hasn't changed. + if ((( value ^ oldValue ) & bit ) == 0 ) + continue; + + // [AK] Print the name of the CVar and its new value while we still can. + if ( ++flagsChanged <= maxflags ) + { + for ( FBaseCVar* cvar = CVars; cvar; cvar = cvar->GetNext( ) ) + { + // [AK] Make sure that this CVar is a flag. + if ( cvar->IsFlagCVar( ) == false ) + continue; + + FFlagCVar* flagCVar = static_cast( cvar ); + + // [AK] Check if this CVar belongs to the flagset and matches the corresponding bit. + if (( flagCVar->GetValueVar( ) == &flagset ) && ( flagCVar->GetBitVal( ) == bit )) + { + if ( flagsChanged > 1 ) + result += ", "; + + result.AppendFormat( "%s %s", flagCVar->GetName( ), ( value & bit ) ? "ON" : "OFF" ); + break; + } + } + } + } + + // [AK] If too many flags changed, just print how many flags were changed instead. + // This way, we don't print an excessively long message to the console. + if ( flagsChanged > maxflags ) + result.Format( "%d flags changed", flagsChanged ); + + SERVER_Printf( "%s changed to: %d (%s)\n", flagset.GetName( ), value, result ); + + // [AK] We also need to tell the clients to update the changed flagset. + if ( flagset == *lmsspectatorsettings ) + SERVERCOMMANDS_SetLMSSpectatorSettings( ); + else + SERVERCOMMANDS_SetGameDMFlags( ); +} + +//***************************************************************************** //***************************************************************************** // LONG SERVER_STATISTIC_GetTotalSecondsElapsed( void ) diff -r bc79b72158c2 -r 876945e8eb3f src/sv_main.h --- a/src/sv_main.h Sun Feb 21 14:42:52 2021 -0500 +++ b/src/sv_main.h Sat Feb 27 22:29:49 2021 -0500 @@ -521,6 +521,7 @@ void SERVER_SyncServerModCVars ( const int PlayerToSync ); void SERVER_KillCheat( const char* what ); void STACK_ARGS SERVER_PrintWarning( const char* format, ... ) GCCPRINTF( 1, 2 ); +void SERVER_FlagsetChanged( FIntCVar& flagset, int maxflags = 2 ); // From sv_master.cpp void SERVER_MASTER_Construct( void );