Ejemplo n.º 1
0
        public ServerGame()
            : base(120)
        {
            screens = new Dictionary <string, GameScreen>();

            ConfigSection serverSection = Program.Config.GetSection("Server");

            int maxPlayers = 32;

            if (serverSection == null)
            {
                DashCMD.WriteError("[server.cfg - ServerGame] Section 'Server' is missing!");
            }
            else
            {
                maxPlayers = serverSection.GetInteger("max-players") ?? 32;

                ConfigSection socketSection = serverSection.GetSection("Socket");

                if (socketSection == null)
                {
                    DashCMD.WriteError("[server.cfg - ServerGame] Section 'Socket' is missing!");
                }
                else
                {
                    string ip   = socketSection.GetString("host-ip") ?? "127.0.0.1";
                    int    port = socketSection.GetInteger("host-port") ?? 12123;

                    if (!NetHelper.TryParseIP(ip, out HostIP))
                    {
                        DashCMD.WriteError("[server.cfg - ServerGame] Socket.host-ip is invalid!");
                    }
                }
            }

            if (!AOSServer.Initialize(maxPlayers, new IPEndPoint(HostIP, HostPort)))
            {
                DashCMD.WriteError("Failed to initialize server!");
                DashCMD.StopListening();
                return;
            }

            server = AOSServer.Instance;
            InitializeDebugging();

            AddScreen(new MatchScreen(this));

            SwitchScreen("Match");
        }
Ejemplo n.º 2
0
        void InitializeCMD()
        {
            if (DashCMD.IsCommandDefined("time"))
            {
                return;
            }

            DashCMD.SetCVar <float>("time_autoshift", 0);

            //DashCMD.AddCommand("saveworld", "Saves the current world to file", "saveworld <filename>",
            //    (args) =>
            //    {
            //        if (args.Length != 1)
            //            DashCMD.ShowSyntax("saveworld");
            //        else
            //        {
            //            string fileName = args[0];
            //            WorldIO.Save(fileName, new WorldDescription(Terrain));
            //            DashCMD.WriteImportant("Saved world: {0}.aosw", fileName);
            //        }
            //    });

            DashCMD.AddCommand("time", "Changes the time of day", "time [0-24]",
                               (args) =>
            {
                if (args.Length == 0)
                {
                    DashCMD.WriteLine("Current Time: {0}", timeOfDay);
                }
                else
                {
                    try
                    {
                        float newTime = float.Parse(args[0]);
                        newTime       = MathHelper.Clamp(newTime, 0, 24);

                        timeOfDay = newTime;
                    }
                    catch (Exception)
                    {
                        DashCMD.WriteError("Invalid time.");
                    }
                }
            });
        }