void R_SwitchGamemode(NetConnection server, NetBuffer data, ushort numArgs) { DashCMD.WriteStandard("Switching gamemode..."); GamemodeType type = (GamemodeType)data.ReadByte(); if (currentGamemode != null) { currentGamemode.Stop(); } currentGamemode = null; hud.SetGamemode(null); NetworkedGamemode gamemode; if (gamemodes.TryGetValue(type, out gamemode)) { currentGamemode = gamemode; currentGamemode.Start(); hud.SetGamemode(gamemode); leaderboard.SetGamemode(gamemode); objectComponent.HoldInstantiationPackets = false; } else { string message = string.Format("Failed to switch to gamemode '{0}'!", type); DashCMD.WriteError("[MultiplayerScreen] {0}", message); client.Disconnect("Critical client-side error"); Window.SwitchScreen("MainMenu", message); } }
protected override void OnUnload() { // Unhook from the window focus event so we don't // randomly change the camera and input settings outside // of this screen. Window.OnFocusChanged -= Window_OnFocusChanged; // Unhook from component events objectComponent.OnCreatableInstantiated -= ObjectComponent_OnCreatableInstantiated; objectComponent.OnCreatableDestroyed -= ObjectComponent_OnCreatableDestroyed; // Stop the gamemode if (currentGamemode != null) { currentGamemode.Stop(); currentGamemode = null; hud.SetGamemode(null); } // Unload the world UnloadWorld(); // Disable the hud hud.Disable(); // Hide the winner label announcementTime = 0; base.OnUnload(); }