From 95aeffe10ec6ef0bd5310bbf7de40d770c514db7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 7 Apr 2016 16:12:18 +1000 Subject: [PATCH] Unhandled exceptions in zombie survival should not crash the entire server. (Thanks goodlyay) --- Games/ZombieSurvival/ZombieGame.Core.cs | 15 +++++++++++++++ Games/ZombieSurvival/ZombieGame.cs | 4 ---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index c59ad1df2..bff8d6fa2 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -27,6 +27,21 @@ namespace MCGalaxy.Games { public sealed partial class ZombieGame { void MainLoop() { + // Make sure that in the worst case, we do not crash the entire server. + try { + MainLoopCore(); + } catch (Exception ex) { + Server.ErrorLog(ex); + Player.GlobalMessage("&cZombie survival disabled due to an error."); + try { + ResetState(); + } catch (Exception ex2) { + Server.ErrorLog(ex2); + } + } + } + + void MainLoopCore() { if (Status == ZombieGameStatus.NotStarted) return; if (!initialChangeLevel) { ChooseNextLevel(); diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index fb9d43e91..95a7901d6 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -215,10 +215,6 @@ namespace MCGalaxy.Games { LastLevelName = ""; CurLevelName = ""; CurLevel = null; - foreach (Player pl in online) { - pl.Game.RatedMap = false; - pl.Game.PledgeSurvive = false; - } } void UpdatePlayerStatus(Player p) {