Ejemplo n.º 1
0
        public static void RevertGame() //Reset game bools/stats and stop timers
        {
            _world.gameMode = GameMode.NULL;
            task_.Stop();
            isOn     = false;
            instance = null;
            _world   = null;

            foreach (Player p in ZombiePlayers)
            {
                p.iName                   = p.Name;
                p.Model                   = "steve";
                p.IsInfected              = false;
                p.Info.DisplayedName      = p.Oldname;
                p.IsPlayingZombieSurvival = false;
                p.Message("You are no longer playing zombie survival.");
            }
        }
Ejemplo n.º 2
0
        private static void GameHandler(Player player, Command cmd)
        {
            string GameMode = cmd.Next();
            string Option   = cmd.Next();
            World  world    = player.World;

            if (PropHunt.StartMode != Game.StartMode.None)
            {
                player.Message("&cThere is already a game running!");
                return;
            }

            if (GameMode == null)
            {
                CdGame.PrintUsage(player);
                return;
            }
            if (GameMode.ToLower() == "zombie")
            {
                if (Option.ToLower() == "start")
                {
                    ZombieSurvival game = new ZombieSurvival(player.World); //move to world
                    game.Start();
                    return;
                }
                else if (Option.ToLower() == "stop")
                {
                    ZombieSurvival.Stop(player);
                    Server.Message("{0} &cended the game of zombie survival in the world {1}", player.ClassyName,
                                   world.ClassyName);
                    return;
                }
            }
            if (GameMode.ToLower() == "minefield")
            {
                if (Option == null)
                {
                    player.Message("&cYou must choose an option! &astart/stop");
                    return;
                }
                else if (Option.ToLower() == "start")
                {
                    if (WorldManager.FindWorldExact("Minefield") != null)
                    {
                        player.Message("&WA game of Minefield is currently running and must first be stopped");
                        return;
                    }
                    else
                    {
                        MineField.GetInstance();
                        MineField.Start(player);
                        return;
                    }
                }
                else if (Option.ToLower() == "stop")
                {
                    if (WorldManager.FindWorldExact("Minefield") == null)
                    {
                        player.Message("&WA game of Minefield is currently not running");
                        return;
                    }
                    MineField.Stop(player, false);
                    return;
                }
            }
            if (GameMode.ToLower() == "prophunt")
            {
                if (Option == null)
                {
                    player.Message("&cYou must choose an option! &astart/stop");
                    return;
                }
                if (Option.ToLower() == "start")
                {
                    PropHunt game = new PropHunt(player.World); //move to world
                    game.Start();
                }
            }
            else
            {
                CdGame.PrintUsage(player);
                return;
            }
        }
Ejemplo n.º 3
0
        /// <summary> Starts the server:
        /// Creates Console pseudoplayer, loads the world list, starts listening for incoming connections,
        /// sets up scheduled tasks and starts the scheduler, starts the heartbeat, and connects to IRC.
        /// Raises Server.Starting and Server.Started events.
        /// May throw an exception on hard failure. </summary>
        /// <returns> True if server started normally, false on soft failure. </returns>
        /// <exception cref="System.InvalidOperationException"> Server is already running, or server/library have not been initailized. </exception>
        public static bool StartServer()
        {
            if( IsRunning ) {
                throw new InvalidOperationException( "Server is already running" );
            }
            if( !libraryInitialized || !serverInitialized ) {
                throw new InvalidOperationException( "Server.InitLibrary and Server.InitServer must be called before Server.StartServer" );
            }

            StartTime = DateTime.UtcNow;
            cpuUsageStartingOffset = Process.GetCurrentProcess().TotalProcessorTime;
            Players = new Player[0];

            RaiseEvent( Starting );

            if( ConfigKey.BackupDataOnStartup.Enabled() ) {
                BackupData();
            }

            Player.Console = new Player( ConfigKey.ConsoleName.GetString() );
            Player.AutoRank = new Player( "(AutoRank)" );

            if( ConfigKey.BlockDBEnabled.Enabled() ) BlockDB.Init();

            // try to load the world list
            if( !WorldManager.LoadWorldList() ) return false;
            WorldManager.SaveWorldList();

            // open the port
            Port = ConfigKey.Port.GetInt();
            InternalIP = IPAddress.Parse( ConfigKey.IP.GetString() );

            try {
                listener = new TcpListener( InternalIP, Port );
                listener.Start();

            } catch( Exception ex ) {
                // if the port is unavailable, try next one
                Logger.Log( LogType.Error,
                            "Could not start listening on port {0}, stopping. ({1})",
                            Port, ex.Message );
                if( !ConfigKey.IP.IsDefault() ) {
                    Logger.Log( LogType.Warning,
                                "Do not use the \"Designated IP\" setting unless you have multiple NICs or IPs." );
                }
                return false;
            }

            InternalIP = ((IPEndPoint)listener.LocalEndpoint).Address;
            ExternalIP = CheckExternalIP();

            if( ExternalIP == null ) {
                Logger.Log( LogType.SystemActivity,
                            "Server.Run: now accepting connections on port {0}", Port );
            } else {
                Logger.Log( LogType.SystemActivity,
                            "Server.Run: now accepting connections at {0}:{1}",
                            ExternalIP, Port );
            }

            // list loaded worlds
            WorldManager.UpdateWorldList();
            Logger.Log( LogType.SystemActivity,
                        "All available worlds: {0}",
                        WorldManager.Worlds.JoinToString( ", ", w => w.Name ) );

            Logger.Log( LogType.SystemActivity,
                        "Main world: {0}; default rank: {1}",
                        WorldManager.MainWorld.Name, RankManager.DefaultRank.Name );

            // Check for incoming connections (every 250ms)
            checkConnectionsTask = Scheduler.NewTask( CheckConnections ).RunForever( CheckConnectionsInterval );

            // Check for idles (every 30s)
            checkIdlesTask = Scheduler.NewTask( CheckIdles ).RunForever( CheckIdlesInterval );

            // Monitor CPU usage (every 30s)
            try {
                MonitorProcessorUsage( null );
                Scheduler.NewTask( MonitorProcessorUsage ).RunForever( MonitorProcessorUsageInterval,
                                                                       MonitorProcessorUsageInterval );
            } catch( Exception ex ) {
                Logger.Log( LogType.Error,
                            "Server.StartServer: Could not start monitoring CPU use: {0}", ex );
            }

            PlayerDB.StartSaveTask();

            // Announcements
            if( ConfigKey.AnnouncementInterval.GetInt() > 0 ) {
                TimeSpan announcementInterval = TimeSpan.FromMinutes( ConfigKey.AnnouncementInterval.GetInt() );
                Scheduler.NewTask( ShowRandomAnnouncement ).RunForever( announcementInterval );
            }

            // garbage collection
            gcTask = Scheduler.NewTask( DoGC ).RunForever( GCInterval, TimeSpan.FromSeconds( 45 ) );

            Heartbeat.Start();

            if( ConfigKey.RestartInterval.GetInt() > 0 ) {
                TimeSpan restartIn = TimeSpan.FromSeconds( ConfigKey.RestartInterval.GetInt() );
                Shutdown( new ShutdownParams( ShutdownReason.Restarting, restartIn, true, true ), false );
                ChatTimer.Start( restartIn, "Automatic Server Restart", Player.Console.Name );
            }

            if( ConfigKey.IRCBotEnabled.Enabled() ) IRC.Start();

            Scheduler.NewTask( AutoRankManager.TaskCallback ).RunForever( AutoRankManager.TickInterval );

            // start the main loop - server is now connectible
            Scheduler.Start();
            PortalHandler.GetInstance();
            MessageBlockHandler.GetInstance();
            Doors.DoorHandler.GetInstance();

            IsRunning = true;
            RaiseEvent( Started );
            if (ConfigKey.GCKey.Enabled())
            {

                GlobalChat.Init();
                GlobalChat.Start();
            }
            if (!ConfigKey.IsNormal.Enabled())
            {
                ZombieSurvival game = new ZombieSurvival(WorldManager.MainWorld);//move to world
                game.Start();
            }
            return true;
        }
Ejemplo n.º 4
0
        //Reset game bools/stats and stop timers
        public static void RevertGame()
        {
            _world.gameMode = GameMode.NULL;
            task_.Stop();
            isOn = false;
            instance = null;
            _world = null;

            foreach (Player p in ZombiePlayers)
            {
                p.iName = p.Name;
                p.ZombieHead = false;
                p.Info.isInfected = false;
                p.Info.DisplayedName = p.Info.oldname;
                p.Info.isPlayingZombieSurvival = false;
                p.Message("You are no longer playing zombie survival.");
            }
        }