Beispiel #1
0
        private void LoadSettings()
        {
            XDocument doc = null;

            if (File.Exists(SettingsFile))
            {
                doc = XMLExtensions.TryLoadXml(SettingsFile);
            }

            if (doc == null || doc.Root == null)
            {
                doc = new XDocument(new XElement("serversettings"));
            }

            SerializableProperties = SerializableProperty.DeserializeProperties(this, doc.Root);

            AutoRestart = doc.Root.GetAttributeBool("autorestart", false);

            Voting.AllowSubVoting  = SubSelectionMode == SelectionMode.Vote;
            Voting.AllowModeVoting = ModeSelectionMode == SelectionMode.Vote;

            selectedLevelDifficulty = doc.Root.GetAttributeFloat("LevelDifficulty", 20.0f);
            GameMain.NetLobbyScreen.SetLevelDifficulty(selectedLevelDifficulty);

            var traitorsEnabled = TraitorsEnabled;

            Enum.TryParse(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled);
            TraitorsEnabled = traitorsEnabled;
            GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);

            var botSpawnMode = BotSpawnMode.Fill;

            Enum.TryParse(doc.Root.GetAttributeString("BotSpawnMode", "Fill"), out botSpawnMode);
            BotSpawnMode = botSpawnMode;

            //"65-90", "97-122", "48-59" = upper and lower case english alphabet and numbers
            string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", new string[] { "65-90", "97-122", "48-59" });
            foreach (string allowedClientNameCharRange in allowedClientNameCharsStr)
            {
                string[] splitRange = allowedClientNameCharRange.Split('-');
                if (splitRange.Length == 0 || splitRange.Length > 2)
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }

                int min = -1;
                if (!int.TryParse(splitRange[0], out min))
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }
                int max = min;
                if (splitRange.Length == 2)
                {
                    if (!int.TryParse(splitRange[1], out max))
                    {
                        DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                        continue;
                    }
                }

                if (min > -1 && max > -1)
                {
                    AllowedClientNameChars.Add(new Pair <int, int>(min, max));
                }
            }

            AllowedRandomMissionTypes = new List <MissionType>();
            string[] allowedMissionTypeNames = doc.Root.GetAttributeStringArray(
                "AllowedRandomMissionTypes", Enum.GetValues(typeof(MissionType)).Cast <MissionType>().Select(m => m.ToString()).ToArray());
            foreach (string missionTypeName in allowedMissionTypeNames)
            {
                if (Enum.TryParse(missionTypeName, out MissionType missionType))
                {
                    if (missionType == Barotrauma.MissionType.None)
                    {
                        continue;
                    }
                    AllowedRandomMissionTypes.Add(missionType);
                }
            }

            ServerName        = doc.Root.GetAttributeString("name", "");
            ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");

            GameMain.NetLobbyScreen.SelectedModeIdentifier = GameModeIdentifier;
            GameMain.NetLobbyScreen.MissionTypeName        = MissionType;

            GameMain.NetLobbyScreen.SetBotSpawnMode(BotSpawnMode);
            GameMain.NetLobbyScreen.SetBotCount(BotCount);

            List <string> monsterNames = GameMain.Instance.GetFilesOfType(ContentType.Character).ToList();

            for (int i = 0; i < monsterNames.Count; i++)
            {
                monsterNames[i] = Path.GetFileName(Path.GetDirectoryName(monsterNames[i]));
            }
            MonsterEnabled = new Dictionary <string, bool>();
            foreach (string s in monsterNames)
            {
                if (!MonsterEnabled.ContainsKey(s))
                {
                    MonsterEnabled.Add(s, true);
                }
            }

            AutoBanTime    = doc.Root.GetAttributeFloat("autobantime", 60);
            MaxAutoBanTime = doc.Root.GetAttributeFloat("maxautobantime", 360);
        }
        private void LoadSettings()
        {
            XDocument doc = null;

            if (File.Exists(SettingsFile))
            {
                doc = XMLExtensions.TryLoadXml(SettingsFile);
            }

            if (doc == null)
            {
                doc = new XDocument(new XElement("serversettings"));
            }

            SerializableProperties = SerializableProperty.DeserializeProperties(this, doc.Root);

            AutoRestart = doc.Root.GetAttributeBool("autorestart", false);

            Voting.AllowSubVoting  = SubSelectionMode == SelectionMode.Vote;
            Voting.AllowModeVoting = ModeSelectionMode == SelectionMode.Vote;

            selectedLevelDifficulty = doc.Root.GetAttributeFloat("LevelDifficulty", 20.0f);
            GameMain.NetLobbyScreen.SetLevelDifficulty(selectedLevelDifficulty);

            GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);

            string[] defaultAllowedClientNameChars =
                new string[] {
                "32-33",
                "38-46",
                "48-57",
                "65-90",
                "91",
                "93",
                "95-122",
                "192-255",
                "384-591",
                "1024-1279",
                "19968-40959", "13312-19903", "131072-15043983", "15043985-173791", "173824-178207", "178208-183983", "63744-64255", "194560-195103" //CJK
            };

            string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", defaultAllowedClientNameChars);
            if (doc.Root.GetAttributeString("AllowedClientNameChars", "") == "65-90,97-122,48-59")
            {
                allowedClientNameCharsStr = defaultAllowedClientNameChars;
            }

            foreach (string allowedClientNameCharRange in allowedClientNameCharsStr)
            {
                string[] splitRange = allowedClientNameCharRange.Split('-');
                if (splitRange.Length == 0 || splitRange.Length > 2)
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }

                int min = -1;
                if (!int.TryParse(splitRange[0], out min))
                {
                    DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                    continue;
                }
                int max = min;
                if (splitRange.Length == 2)
                {
                    if (!int.TryParse(splitRange[1], out max))
                    {
                        DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
                        continue;
                    }
                }

                if (min > -1 && max > -1)
                {
                    AllowedClientNameChars.Add(new Pair <int, int>(min, max));
                }
            }

            AllowedRandomMissionTypes = new List <MissionType>();
            string[] allowedMissionTypeNames = doc.Root.GetAttributeStringArray(
                "AllowedRandomMissionTypes", Enum.GetValues(typeof(MissionType)).Cast <MissionType>().Select(m => m.ToString()).ToArray());
            foreach (string missionTypeName in allowedMissionTypeNames)
            {
                if (Enum.TryParse(missionTypeName, out MissionType missionType))
                {
                    if (missionType == Barotrauma.MissionType.None)
                    {
                        continue;
                    }
                    AllowedRandomMissionTypes.Add(missionType);
                }
            }

            ServerName = doc.Root.GetAttributeString("name", "");
            if (ServerName.Length > NetConfig.ServerNameMaxLength)
            {
                ServerName = ServerName.Substring(0, NetConfig.ServerNameMaxLength);
            }
            ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");

            GameMain.NetLobbyScreen.SelectedModeIdentifier = GameModeIdentifier;
            //handle Random as the mission type, which is no longer a valid setting
            //MissionType.All offers equivalent functionality
            if (MissionType == "Random")
            {
                MissionType = "All";
            }
            GameMain.NetLobbyScreen.MissionTypeName = MissionType;

            GameMain.NetLobbyScreen.SetBotSpawnMode(BotSpawnMode);
            GameMain.NetLobbyScreen.SetBotCount(BotCount);

            List <string> monsterNames = CharacterPrefab.Prefabs.Select(p => p.Identifier).ToList();

            MonsterEnabled = new Dictionary <string, bool>();
            foreach (string s in monsterNames)
            {
                if (!MonsterEnabled.ContainsKey(s))
                {
                    MonsterEnabled.Add(s, true);
                }
            }
        }