From 612c909053304dcc440e87d178dbd736844f873d Mon Sep 17 00:00:00 2001 From: danij Date: Sun, 13 Apr 2014 10:37:57 +0100 Subject: [PATCH] Fixed|Multiplayer|All Games|libcommon: GameRuleset mismanagement in a networked game The game rule configuration was being changed twice when starting a networked server, once before the session began and then again while applying the first set of rules. --- doomsday/plugins/common/include/d_net.h | 2 - doomsday/plugins/common/src/d_net.cpp | 22 ----------- doomsday/plugins/common/src/gamesession.cpp | 42 ++++++++++----------- doomsday/plugins/common/src/p_mapsetup.cpp | 17 ++++++++- 4 files changed, 36 insertions(+), 47 deletions(-) diff --git a/doomsday/plugins/common/include/d_net.h b/doomsday/plugins/common/include/d_net.h index 5ae88995b0..210415f2f0 100644 --- a/doomsday/plugins/common/include/d_net.h +++ b/doomsday/plugins/common/include/d_net.h @@ -220,8 +220,6 @@ int D_NetConnect(int before); int D_NetDisconnect(int before); -void NetSv_ApplyGameRulesFromConfig(void); - long int D_NetPlayerEvent(int plrNumber, int peType, void *data); /** diff --git a/doomsday/plugins/common/src/d_net.cpp b/doomsday/plugins/common/src/d_net.cpp index a7cb75833a..15f5ffe3c1 100644 --- a/doomsday/plugins/common/src/d_net.cpp +++ b/doomsday/plugins/common/src/d_net.cpp @@ -99,25 +99,6 @@ void D_NetClearBuffer() netWriter = 0; } -void NetSv_ApplyGameRulesFromConfig() -{ - if(IS_CLIENT) return; - - GameRuleset newRules(COMMON_GAMESESSION->rules()); // make a copy - newRules.deathmatch = cfg.netDeathmatch; - newRules.noMonsters = cfg.netNoMonsters; - /*gameRules.*/cfg.jumpEnabled = cfg.netJumping; -#if __JDOOM__ || __JHERETIC__ || __JDOOM64__ - newRules.respawnMonsters = cfg.netRespawn; -#endif -#if __JHEXEN__ - newRules.randomClasses = cfg.netRandomClass; -#endif - COMMON_GAMESESSION->applyNewRules(newRules); - - NetSv_UpdateGameConfigDescription(); -} - int D_NetServerStarted(int before) { if(before) return true; @@ -132,9 +113,6 @@ int D_NetServerStarted(int before) #endif P_ResetPlayerRespawnClasses(); - // Set the game parameters. - NetSv_ApplyGameRulesFromConfig(); - #if __JDOOM64__ uint netEpisode = 0; #else diff --git a/doomsday/plugins/common/src/gamesession.cpp b/doomsday/plugins/common/src/gamesession.cpp index 2f99b5d9cb..29a692889f 100644 --- a/doomsday/plugins/common/src/gamesession.cpp +++ b/doomsday/plugins/common/src/gamesession.cpp @@ -160,27 +160,34 @@ DENG2_PIMPL(GameSession) if(rules.skill > NUM_SKILL_MODES - 1) rules.skill = skillmode_t(NUM_SKILL_MODES - 1); -#if __JDOOM__ || __JHERETIC__ || __JDOOM64__ if(!IS_NETGAME) { +#if !__JHEXEN__ rules.deathmatch = false; - rules.respawnMonsters = false; - - rules.noMonsters = CommandLine_Exists("-nomonsters")? true : false; - } -#endif + rules.respawnMonsters = CommandLine_Check("-respawn")? true : false; -#if __JDOOM__ || __JHERETIC__ || __JDOOM64__ - rules.respawnMonsters = CommandLine_Check("-respawn")? true : false; + rules.noMonsters = CommandLine_Exists("-nomonsters")? true : false; #endif - #if __JDOOM__ || __JHERETIC__ - // Is respawning enabled at all in nightmare skill? - if(rules.skill == SM_NIGHTMARE) - { - rules.respawnMonsters = cfg.respawnMonstersNightmare; + // Is respawning enabled at all in nightmare skill? + if(rules.skill == SM_NIGHTMARE) + { + rules.respawnMonsters = cfg.respawnMonstersNightmare; + } +#endif } + else if(IS_DEDICATED) + { +#if !__JHEXEN__ + rules.deathmatch = cfg.netDeathmatch; + rules.respawnMonsters = cfg.netRespawn; + + rules.noMonsters = cfg.netNoMonsters; + /*rules.*/cfg.jumpEnabled = cfg.netJumping; +#else + rules.randomClasses = cfg.netRandomClass; #endif + } // Fast monsters? #if __JDOOM__ || __JDOOM64__ @@ -206,10 +213,7 @@ DENG2_PIMPL(GameSession) applyRuleFastMissiles(fastMissiles); #endif - if(IS_DEDICATED) - { - NetSv_ApplyGameRulesFromConfig(); - } + NetSv_UpdateGameConfigDescription(); // Update game status cvars: Con_SetInteger2("game-skill", rules.skill, SVF_WRITE_OVERRIDE); @@ -490,10 +494,6 @@ DENG2_PIMPL(GameSession) S_PauseMusic(true); } - // If we're the server, let clients know the map will change. - NetSv_UpdateGameConfigDescription(); - NetSv_SendGameState(GSF_CHANGE_MAP, DDSP_ALL_PLAYERS); - P_SetupMap(gameMapUri); if(revisit) diff --git a/doomsday/plugins/common/src/p_mapsetup.cpp b/doomsday/plugins/common/src/p_mapsetup.cpp index 19a120b77a..87750e0e5c 100644 --- a/doomsday/plugins/common/src/p_mapsetup.cpp +++ b/doomsday/plugins/common/src/p_mapsetup.cpp @@ -686,10 +686,23 @@ void P_SetupMap(Uri const *mapUri) if(IS_DEDICATED) { - // Whenever the game changes, update the game config from - NetSv_ApplyGameRulesFromConfig(); + // Whenever the map changes, update the game rule config. + GameRuleset newRules(COMMON_GAMESESSION->rules()); // make a copy + newRules.deathmatch = cfg.netDeathmatch; + newRules.noMonsters = cfg.netNoMonsters; + /*newRules.*/cfg.jumpEnabled = cfg.netJumping; +#if __JDOOM__ || __JHERETIC__ || __JDOOM64__ + newRules.respawnMonsters = cfg.netRespawn; +#endif +#if __JHEXEN__ + newRules.randomClasses = cfg.netRandomClass; +#endif + COMMON_GAMESESSION->applyNewRules(newRules); } + // If we're the server, let clients know the map will change. + NetSv_SendGameState(GSF_CHANGE_MAP, DDSP_ALL_PLAYERS); + // It begins... mapSetup = true;