Beispiel #1
0
 public bool TryStartChildServerRelay()
 {
     for (int i = 0; i < CommandLineArgs.Length; i++)
     {
         switch (CommandLineArgs[i].Trim())
         {
         case "-pipes":
             ChildServerRelay.Start(CommandLineArgs[i + 2], CommandLineArgs[i + 1]);
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
        public void StartServer()
        {
            string name            = "Server";
            int    port            = NetConfig.DefaultPort;
            int    queryPort       = NetConfig.DefaultQueryPort;
            bool   publiclyVisible = false;
            string password        = "";
            bool   enableUpnp      = false;

            int    maxPlayers = 10;
            int?   ownerKey   = null;
            UInt64 steamId    = 0;

            XDocument doc = XMLExtensions.TryLoadXml(ServerSettings.SettingsFile);

            if (doc?.Root == null)
            {
                DebugConsole.ThrowError("File \"" + ServerSettings.SettingsFile + "\" not found. Starting the server with default settings.");
            }
            else
            {
                name            = doc.Root.GetAttributeString("name", "Server");
                port            = doc.Root.GetAttributeInt("port", NetConfig.DefaultPort);
                queryPort       = doc.Root.GetAttributeInt("queryport", NetConfig.DefaultQueryPort);
                publiclyVisible = doc.Root.GetAttributeBool("public", false);
                password        = doc.Root.GetAttributeString("password", "");
                enableUpnp      = doc.Root.GetAttributeBool("enableupnp", false);
                maxPlayers      = doc.Root.GetAttributeInt("maxplayers", 10);
                ownerKey        = null;
            }

#if DEBUG
            foreach (string s in CommandLineArgs)
            {
                Console.WriteLine(s);
            }
#endif

            for (int i = 0; i < CommandLineArgs.Length; i++)
            {
                switch (CommandLineArgs[i].Trim())
                {
                case "-name":
                    name = CommandLineArgs[i + 1];
                    i++;
                    break;

                case "-port":
                    int.TryParse(CommandLineArgs[i + 1], out port);
                    i++;
                    break;

                case "-queryport":
                    int.TryParse(CommandLineArgs[i + 1], out queryPort);
                    i++;
                    break;

                case "-public":
                    bool.TryParse(CommandLineArgs[i + 1], out publiclyVisible);
                    i++;
                    break;

                case "-password":
                    password = CommandLineArgs[i + 1];
                    i++;
                    break;

                case "-nopassword":
                    password = "";
                    break;

                case "-upnp":
                case "-enableupnp":
                    bool.TryParse(CommandLineArgs[i + 1], out enableUpnp);
                    i++;
                    break;

                case "-maxplayers":
                    int.TryParse(CommandLineArgs[i + 1], out maxPlayers);
                    i++;
                    break;

                case "-ownerkey":
                    if (int.TryParse(CommandLineArgs[i + 1], out int key))
                    {
                        ownerKey = key;
                    }
                    i++;
                    break;

                case "-steamid":
                    UInt64.TryParse(CommandLineArgs[i + 1], out steamId);
                    i++;
                    break;

                case "-pipes":
                    ChildServerRelay.Start(CommandLineArgs[i + 2], CommandLineArgs[i + 1]);
                    i += 2;
                    break;
                }
            }

            Server = new GameServer(
                name,
                port,
                queryPort,
                publiclyVisible,
                password,
                enableUpnp,
                maxPlayers,
                ownerKey,
                steamId);

            for (int i = 0; i < CommandLineArgs.Length; i++)
            {
                switch (CommandLineArgs[i].Trim())
                {
                case "-playstyle":
                    Enum.TryParse(CommandLineArgs[i + 1], out PlayStyle playStyle);
                    Server.ServerSettings.PlayStyle = playStyle;
                    i++;
                    break;

                case "-banafterwrongpassword":
                    bool.TryParse(CommandLineArgs[i + 1], out bool banAfterWrongPassword);
                    Server.ServerSettings.BanAfterWrongPassword = banAfterWrongPassword;
                    break;

                case "-karma":
                case "-karmaenabled":
                    bool.TryParse(CommandLineArgs[i + 1], out bool karmaEnabled);
                    Server.ServerSettings.KarmaEnabled = karmaEnabled;
                    i++;
                    break;

                case "-karmapreset":
                    string karmaPresetName = CommandLineArgs[i + 1];
                    Server.ServerSettings.KarmaPreset = karmaPresetName;
                    i++;
                    break;
                }
            }
        }