Ejemplo n.º 1
0
        void ChangeWorld(string worldFile, GamemodeType?newGamemode = null)
        {
            // Disable this in the case of a forced world change
            // while the count down is going.
            gameRestarting = false;

            // Reset all the scores
            ResetPlayerScores();

            // Disable client downloading of worlds temporarily
            processNewConnections = false;
            if (World.Terrain != null)
            {
                World.Terrain.OnModified -= Terrain_OnModified;
            }

            // Stop the gamemode
            currentGamemode.Stop();

            // Notify each client we are changing worlds
            channel.FireEventForAllConnections("Client_UnloadWorld");

            // Attempt to load the world
            if (World.LoadFromFile(worldFile))
            {
                // Re-enable client world downloading
                World.Terrain.OnModified += Terrain_OnModified;
                processNewConnections     = true;

                // Start the gamemode
                if (newGamemode.HasValue)
                {
                    SwitchGamemode(newGamemode.Value);
                }
                else
                {
                    currentGamemode.Start();
                }

                channel.FireEventForAllConnections("Client_SwitchGamemode", (byte)currentGamemode.Type);

                // Initiate a download handshake with each client
                foreach (NetConnection conn in server.Connections.Values)
                {
                    if (!handshakeComponent.Initiate(conn))
                    {
                        conn.Disconnect("Failed to initiate handshake!");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void SwitchGamemode(GamemodeType to)
        {
            if (currentGamemode != null)
            {
                currentGamemode.Stop();
            }

            currentGamemode = null;

            NetworkedGamemode gamemode;

            if (gamemodes.TryGetValue(to, out gamemode))
            {
                currentGamemode = gamemode;
                currentGamemode.Start();

                channel.FireEventForAllConnections("Client_SwitchGamemode", (byte)to);
            }
            else
            {
                DashCMD.WriteError("[MatchScreen] Gamemode type '{0}' is not defined!", to);
            }
        }