Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            ConsoleUtils.TryEnableUnicode();

            int imageTop;

            if (ConsoleImage.RenderFromManifestResource("ConsoleImage.udl", out imageTop) && imageTop >= 0)
            {
                int width = Console.BufferWidth;

                // Show version number in the right corner
                string appVersion = "v" + Game.App.AssemblyVersion;

                int currentCursorTop = Console.CursorTop;
                Console.SetCursorPosition(width - appVersion.Length - 2, imageTop + 1);
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine(appVersion);
                Console.ResetColor();
                Console.CursorTop = currentCursorTop;
            }

            // Process parameters
            int port;

            if (!TryRemoveArg(ref args, "/port:", out port))
            {
                port = 10666;
            }

            string overrideHostname;

            if (!TryRemoveArg(ref args, "/override-hostname:", out overrideHostname))
            {
                overrideHostname = null;
            }

            string name;

            if (!TryRemoveArg(ref args, "/name:", out name) || string.IsNullOrWhiteSpace(name))
            {
                name = "Unnamed server";
            }

            int maxPlayers;

            if (!TryRemoveArg(ref args, "/players:", out maxPlayers))
            {
                maxPlayers = 64;
            }

            string levelName;

            if (!TryRemoveArg(ref args, "/level:", out levelName))
            {
                levelName = "unknown/battle2";
            }

            bool isPrivate  = TryRemoveArg(ref args, "/private");
            bool enableUPnP = TryRemoveArg(ref args, "/upnp");

            // Initialization
            Version v           = Assembly.GetEntryAssembly().GetName().Version;
            byte    neededMajor = (byte)v.Major;
            byte    neededMinor = (byte)v.Minor;
            byte    neededBuild = (byte)v.Build;

            Log.Write(LogType.Info, "Starting server...", true);

            // Start game server
            gameServer = new GameServer();

            if (overrideHostname != null)
            {
                try {
                    gameServer.OverrideHostname(overrideHostname);
                } catch {
                    Log.Write(LogType.Error, "Cannot set override public hostname!");
                }
            }

            gameServer.Run(port, name, maxPlayers, isPrivate, enableUPnP, neededMajor, neededMinor, neededBuild);

            Log.PopIndent();

            gameServer.ChangeLevel(levelName, MultiplayerLevelType.Battle);

            Log.Write(LogType.Info, "Ready!");
            Log.Write(LogType.Info, "");

            // Processing of console commands
            ProcessConsoleCommands();

            // Shutdown
            Log.Write(LogType.Info, "Closing...");

            gameServer.Dispose();
        }