Skip to content

Commit

Permalink
Fixed|Multiplayer|All Games|libcommon: GameRuleset mismanagement in a…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
danij-deng committed Apr 13, 2014
1 parent fcc51c0 commit 612c909
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 47 deletions.
2 changes: 0 additions & 2 deletions doomsday/plugins/common/include/d_net.h
Expand Up @@ -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);

/**
Expand Down
22 changes: 0 additions & 22 deletions doomsday/plugins/common/src/d_net.cpp
Expand Up @@ -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;
Expand All @@ -132,9 +113,6 @@ int D_NetServerStarted(int before)
#endif
P_ResetPlayerRespawnClasses();

// Set the game parameters.
NetSv_ApplyGameRulesFromConfig();

#if __JDOOM64__
uint netEpisode = 0;
#else
Expand Down
42 changes: 21 additions & 21 deletions doomsday/plugins/common/src/gamesession.cpp
Expand Up @@ -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__
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -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;

Expand Down

0 comments on commit 612c909

Please sign in to comment.