static int Main(string[] args)
        {
            var parser          = new CommandLineParser.CommandLineParser();
            var launchArguments = new LaunchArguments();

            try
            {
                parser.ExtractArgumentAttributes(launchArguments);
                parser.ParseCommandLine(args);
            }
            catch (CommandLineException ex)
            {
                Console.WriteLine(ex.Message);
                parser.ShowUsage();
                return(1);
            }

            if (launchArguments.MaxPlayers > SharedConstants.MaxPlayerLimit)
            {
                Console.WriteLine($"Max players exceeded max limit of {SharedConstants.MaxPlayerLimit}. Value was adjusted.");
                launchArguments.MaxPlayers = SharedConstants.MaxPlayerLimit;
            }

            if (launchArguments.MaxPlayers < 1)
            {
                Console.WriteLine("Player limit can't be lower than 1.");
                parser.ShowUsage();
                return(1);
            }

            ConsoleManager.Initialize();
            ConsoleManager.OnInput += cmd => queuedCommandInputs.Enqueue(cmd);

            Server = new GameServer(launchArguments.ServerName, launchArguments.MaxPlayers, launchArguments.Port, false, launchArguments.Private, !launchArguments.NoSteam, "config");
            Server.Start();

            while (Server.Running)
            {
                while (queuedCommandInputs.Count > 0)
                {
                    Server.ConsoleCommands.HandleMessage(null, queuedCommandInputs.Dequeue());
                }

                if (!Server.Running)
                {
                    continue;
                }

                Server.Update();

                Console.Title = $"{Server.Name} | {Server.Players.Count}/{Server.MaxPlayers}";
                Thread.Sleep(1);
            }

            ConsoleManager.Destroy();
            return(0);
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            Settings.Init("Resources/Data/Buildings.xml", "Resources/Data/Units.xml");

            var server = new GameServer(5555);
            //server.SetGame(new StandardMelee(server, 1));
            server.Start();

            var stopwatch = new Stopwatch();
            stopwatch.Restart();

            while (true)
            {
                var dt = (float) (stopwatch.Elapsed.TotalSeconds*1000);
                stopwatch.Restart();
                server.Update(dt);
                Thread.Sleep(100);
            }
        }