Пример #1
0
 static void LoadHandler([NotNull] Player player, [CanBeNull] string fileName)
 {
     if (!player.CheckIfOp())
     {
         return;
     }
     if (fileName == null)
     {
         player.Message("Load: Filename required.");
         return;
     }
     try {
         player.MessageNow("Loading map, please wait...");
         Map map;
         if (fileName.EndsWith(".dat", StringComparison.OrdinalIgnoreCase))
         {
             map = DatMapConverter.Load(fileName);
         }
         else if (fileName.EndsWith(".lvl", StringComparison.OrdinalIgnoreCase))
         {
             map = LvlMapConverter.Load(fileName);
         }
         else
         {
             player.Message("Load: Unsupported map format.");
             return;
         }
         Server.Players.Message("Player {0} changed map to {1}",
                                player.Name, Path.GetFileName(fileName));
         Server.ChangeMap(map);
     } catch (Exception ex) {
         player.Message("Could not load map: {0}: {1}", ex.GetType().Name, ex.Message);
     }
 }
Пример #2
0
        static int Main()
        {
#if !DEBUG
            try {
#endif
            Console.Title = VersionString;
            Logger.Log("Starting {0}", VersionString);

            // load config
            Config.Load();
            Console.Title = Config.ServerName + " - " + VersionString;

            // prepare to accept players and fire up the heartbeat
            for (byte i = 1; i <= sbyte.MaxValue; i++)
            {
                FreePlayerIDs.Push(i);
            }
            UpdatePlayerList();
            Heartbeat.Start();

            // load player and IP lists
            Bans   = new PlayerNameSet(BansFileName);
            Ops    = new PlayerNameSet(OpsFileName);
            IPBans = new IPAddressSet(IPBanFileName);
            Logger.Log("Server: Tracking {0} bans, {1} ip-bans, and {2} ops.",
                       Bans.Count, IPBans.Count, Ops.Count);
            if (Config.UseWhitelist)
            {
                Whitelist = new PlayerNameSet(WhitelistFileName);
                Logger.Log("Using a whitelist ({0} players): {1}",
                           Whitelist.Count, Whitelist.GetCopy().JoinToString(", "));
            }

            // load or create map
            if (File.Exists(MapFileName))
            {
                Map = LvlMapConverter.Load(MapFileName);
                Logger.Log("Loaded map from {0}", MapFileName);
            }
            else
            {
                Logger.Log("Generating the map...");
                Map = NotchyMapGenerator.Generate(256, 256, 64);
                Map.Save(MapFileName);
            }
            Map.IsActive       = true;
            Player.Console.Map = Map;

            // start listening for incoming connections
            listener = new TcpListener(Config.IP, Config.Port);
            listener.Start();

            // start the scheduler thread
            Thread schedulerThread = new Thread(SchedulerLoop)
            {
                IsBackground = true
            };
            schedulerThread.Start();

            // listen for console input
            while (true)
            {
                string input = Console.ReadLine();
                if (input == null)
                {
                    Shutdown();
                    return(0);
                }
                try {
                    Player.Console.ProcessMessage(input.Trim());
                } catch (Exception ex) {
                    Logger.LogError("Could not process message: {0}", ex);
                }
            }

#if !DEBUG
        }

        catch (Exception ex) {
            Logger.LogError("Server crashed: {0}", ex);
            return(1);
        }
#endif
        }