public DecalManager() { var decalElements = new Dictionary <string, XElement>(); foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.Decals)) { XDocument doc = XMLExtensions.TryLoadXml(configFile); if (doc == null) { continue; } bool allowOverriding = false; var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); allowOverriding = true; } foreach (XElement sourceElement in mainElement.Elements()) { var element = sourceElement.IsOverride() ? sourceElement.FirstElement() : sourceElement; string name = element.Name.ToString().ToLowerInvariant(); if (decalElements.ContainsKey(name)) { if (allowOverriding || sourceElement.IsOverride()) { DebugConsole.NewMessage($"Overriding the existing decal prefab '{name}' using the file '{configFile}'", Color.Yellow); decalElements.Remove(name); } else { DebugConsole.ThrowError($"Error in '{configFile}': Duplicate decal prefab '{name}' found in '{configFile}'! Each decal prefab must have a unique name. " + "Use <override></override> tags to override prefabs."); continue; } } decalElements.Add(name, element); } } //prefabs = decalElements.ToDictionary(d => d.Key, d => new DecalPrefab(d.Value)); prefabs = new Dictionary <string, DecalPrefab>(); foreach (var kvp in decalElements) { prefabs.Add(kvp.Key, new DecalPrefab(kvp.Value)); } }
private static void Load() { list = new List <RuinStructure>(); XDocument doc = XMLExtensions.TryLoadXml(ConfigFile); if (doc == null || doc.Root == null) { return; } foreach (XElement element in doc.Root.Elements()) { new RuinStructure(element); } }
private static void Load() { list = new List <RuinStructure>(); foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.RuinConfig)) { XDocument doc = XMLExtensions.TryLoadXml(configFile); if (doc == null || doc.Root == null) { continue; } foreach (XElement element in doc.Root.Elements()) { new RuinStructure(element); } } }
private static void LoadAll() { paramsList = new List <RuinGenerationParams>(); foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.RuinConfig)) { XDocument doc = XMLExtensions.TryLoadXml(configFile); if (doc?.Root == null) { continue; } var newParams = new RuinGenerationParams(doc.Root) { filePath = configFile }; paramsList.Add(newParams); } }
public void LoadPrefabsFromFile(ContentFile configFile) { var particleElements = new Dictionary <string, XElement>(); XDocument doc = XMLExtensions.TryLoadXml(configFile.Path); if (doc == null) { return; } bool allowOverriding = false; var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); allowOverriding = true; } foreach (XElement sourceElement in mainElement.Elements()) { var element = sourceElement.IsOverride() ? sourceElement.FirstElement() : sourceElement; string name = element.Name.ToString().ToLowerInvariant(); if (Prefabs.ContainsKey(name) || particleElements.ContainsKey(name)) { if (allowOverriding || sourceElement.IsOverride()) { DebugConsole.NewMessage($"Overriding the existing particle prefab '{name}' using the file '{configFile.Path}'", Color.Yellow); } else { DebugConsole.ThrowError($"Error in '{configFile.Path}': Duplicate particle prefab '{name}' found in '{configFile.Path}'! Each particle prefab must have a unique name. " + "Use <override></override> tags to override prefabs."); continue; } } particleElements.Add(name, element); } foreach (var kvp in particleElements) { Prefabs.Add(new ParticlePrefab(kvp.Value, configFile), allowOverriding); } }
public static void LoadAll(string file) { if (!File.Exists(file)) { return; } XDocument doc = XMLExtensions.TryLoadXml(file); if (doc == null || doc.Root == null) { return; } foreach (XElement element in doc.Root.Elements()) { List.Add(new PermissionPreset(element)); } }
public static void Init() { Tutorials = new List <Tutorial>(); foreach (string file in GameMain.Instance.GetFilesOfType(ContentType.Tutorials)) { XDocument doc = XMLExtensions.TryLoadXml(file); if (doc?.Root == null) { continue; } foreach (XElement element in doc.Root.Elements()) { Tutorial newTutorial = Load(element); if (newTutorial != null) { Tutorials.Add(newTutorial); } } } }
public void LoadPrefabs() { XDocument doc = XMLExtensions.TryLoadXml(ConfigFile); if (doc == null || doc.Root == null) { return; } prefabs = new Dictionary <string, ParticlePrefab>(); foreach (XElement element in doc.Root.Elements()) { if (prefabs.ContainsKey(element.Name.ToString())) { DebugConsole.ThrowError("Error in " + ConfigFile + "! Each particle prefab must have a unique name."); continue; } prefabs.Add(element.Name.ToString(), new ParticlePrefab(element)); } }
public DecalManager() { prefabs = new Dictionary <string, DecalPrefab>(); foreach (string configFile in GameMain.Instance.GetFilesOfType(ContentType.Decals)) { XDocument doc = XMLExtensions.TryLoadXml(configFile); if (doc == null || doc.Root == null) { continue; } foreach (XElement element in doc.Root.Elements()) { if (prefabs.ContainsKey(element.Name.ToString())) { DebugConsole.ThrowError("Error in " + configFile + "! Each decal prefab must have a unique name."); continue; } prefabs.Add(element.Name.ToString(), new DecalPrefab(element)); } } }
public void LoadPrefabs() { prefabs = new Dictionary <string, ParticlePrefab>(); foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Particles)) { XDocument doc = XMLExtensions.TryLoadXml(configFile); if (doc == null || doc.Root == null) { continue; } foreach (XElement element in doc.Root.Elements()) { if (prefabs.ContainsKey(element.Name.ToString())) { DebugConsole.ThrowError("Error in " + configFile + "! Each particle prefab must have a unique name."); continue; } prefabs.Add(element.Name.ToString(), new ParticlePrefab(element)); } } }
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); #if CLIENT if (autoRestart) { GameMain.NetLobbyScreen.SetAutoRestart(autoRestart, AutoRestartInterval); } #endif subSelectionMode = SelectionMode.Manual; Enum.TryParse <SelectionMode>(doc.Root.GetAttributeString("SubSelection", "Manual"), out subSelectionMode); Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote; modeSelectionMode = SelectionMode.Manual; Enum.TryParse <SelectionMode>(doc.Root.GetAttributeString("ModeSelection", "Manual"), out modeSelectionMode); Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote; var traitorsEnabled = TraitorsEnabled; Enum.TryParse <YesNoMaybe>(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled); TraitorsEnabled = traitorsEnabled; GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled); if (GameMain.NetLobbyScreen != null #if CLIENT && GameMain.NetLobbyScreen.ServerMessage != null #endif ) { GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", ""); } #if CLIENT showLogButton.Visible = SaveServerLogs; #endif List <string> monsterNames = Directory.GetDirectories("Content/Characters").ToList(); for (int i = 0; i < monsterNames.Count; i++) { monsterNames[i] = monsterNames[i].Replace("Content/Characters", "").Replace("/", "").Replace("\\", ""); } monsterEnabled = new Dictionary <string, bool>(); foreach (string s in monsterNames) { monsterEnabled.Add(s, true); } extraCargo = new Dictionary <string, int>(); }
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); } } }
public void LoadClientPermissions() { clientPermissions.Clear(); int Errorcount = 0; if (!File.Exists(NilmodClientPermissionsFile)) { if (File.Exists(VanillaClientPermissionsFile)) { LoadVanillaClientPermissions(); } else if (File.Exists("Data/clientpermissions.txt")) { LoadClientPermissionsOld("Data/clientpermissions.txt"); } SaveClientPermissions(); return; } XDocument doc = XMLExtensions.TryLoadXml(NilmodClientPermissionsFile); //load defaultpermission XElement Xdefaultperms = doc.Root.Element("None"); defaultpermission = new SavedClientPermission("", "", ClientPermissions.None, new List <DebugConsole.Command>()); if (Xdefaultperms != null) { string permissionsStr = Xdefaultperms.GetAttributeString("permissions", ""); ClientPermissions permissions; if (!Enum.TryParse(permissionsStr, out permissions)) { DebugConsole.ThrowError("Error in " + NilmodClientPermissionsFile + " - \"" + permissionsStr + "\" is not a valid client permission."); DebugConsole.ThrowError("Valid permissions are: Kick, Ban, EndRound, SelectSub, SelectMode, ManageCampaign, ConsoleCommands."); Errorcount += 1; } List <DebugConsole.Command> permittedCommands = new List <DebugConsole.Command>(); if (permissions.HasFlag(ClientPermissions.ConsoleCommands)) { foreach (XElement commandElement in Xdefaultperms.Elements()) { if (commandElement.Name.ToString().ToLowerInvariant() != "command") { continue; } string commandName = commandElement.GetAttributeString("name", ""); DebugConsole.Command command = DebugConsole.FindCommand(commandName); if (command == null) { DebugConsole.ThrowError("Error in " + NilmodClientPermissionsFile + " - \"" + commandName + "\" is not a valid console command."); continue; } permittedCommands.Add(command); } } defaultpermission = new SavedClientPermission("", "", permissions, permittedCommands); defaultpermission.AllowInGamePM = Xdefaultperms.GetAttributeBool("AllowInGamePM", false); defaultpermission.GlobalChatSend = Xdefaultperms.GetAttributeBool("GlobalChatSend", false); defaultpermission.GlobalChatReceive = Xdefaultperms.GetAttributeBool("GlobalChatReceive", false); defaultpermission.BypassSkillRequirements = Xdefaultperms.GetAttributeBool("BypassSkillRequirements", false); defaultpermission.IgnoreJobMinimum = Xdefaultperms.GetAttributeBool("IgnoreJobMinimum", false); defaultpermission.HideJoin = Xdefaultperms.GetAttributeBool("HideJoin", false); defaultpermission.AccessDeathChatAlive = Xdefaultperms.GetAttributeBool("AccessDeathChatAlive", false); defaultpermission.AdminChannelSend = Xdefaultperms.GetAttributeBool("AdminChannelSend", true); } else { defaultpermission.AdminChannelSend = true; } foreach (XElement clientElement in doc.Root.Elements()) { if (clientElement.Name != "Client") { continue; } string clientName = clientElement.GetAttributeString("name", ""); string clientIP = clientElement.GetAttributeString("ip", ""); if (string.IsNullOrWhiteSpace(clientName) || string.IsNullOrWhiteSpace(clientIP)) { DebugConsole.ThrowError("Error in " + NilmodClientPermissionsFile + " - all clients must have a name and an IP address."); Errorcount += 1; continue; } string permissionsStr = clientElement.GetAttributeString("permissions", ""); ClientPermissions permissions; if (!Enum.TryParse(permissionsStr, out permissions)) { DebugConsole.ThrowError("Error in " + NilmodClientPermissionsFile + " - \"" + permissionsStr + "\" is not a valid client permission."); DebugConsole.ThrowError("Valid permissions are: Kick, Ban, EndRound, SelectSub, SelectMode, ManageCampaign, ConsoleCommands."); permissions = ClientPermissions.None; Errorcount += 1; } List <DebugConsole.Command> permittedCommands = new List <DebugConsole.Command>(); if (permissions.HasFlag(ClientPermissions.ConsoleCommands)) { foreach (XElement commandElement in clientElement.Elements()) { if (commandElement.Name.ToString().ToLowerInvariant() != "command") { continue; } string commandName = commandElement.GetAttributeString("name", ""); DebugConsole.Command command = DebugConsole.FindCommand(commandName); if (command == null) { DebugConsole.ThrowError("Error in " + NilmodClientPermissionsFile + " - \"" + commandName + "\" is not a valid console command."); Errorcount += 1; } permittedCommands.Add(command); } } SavedClientPermission newsavedpermission = new SavedClientPermission(clientName, clientIP, permissions, permittedCommands); //Nilmod slots newsavedpermission.OwnerSlot = clientElement.GetAttributeBool("OwnerSlot", false); newsavedpermission.AdministratorSlot = clientElement.GetAttributeBool("AdministratorSlot", false); newsavedpermission.TrustedSlot = clientElement.GetAttributeBool("TrustedSlot", false); newsavedpermission.AllowInGamePM = Xdefaultperms.GetAttributeBool("AllowInGamePM", false); newsavedpermission.GlobalChatSend = clientElement.GetAttributeBool("GlobalChatSend", false); newsavedpermission.GlobalChatReceive = clientElement.GetAttributeBool("GlobalChatReceive", false); newsavedpermission.KarmaImmunity = clientElement.GetAttributeBool("KarmaImmunity", false); newsavedpermission.BypassSkillRequirements = clientElement.GetAttributeBool("BypassSkillRequirements", false); newsavedpermission.PrioritizeJob = clientElement.GetAttributeBool("PrioritizeJob", false); newsavedpermission.IgnoreJobMinimum = clientElement.GetAttributeBool("IgnoreJobMinimum", false); newsavedpermission.KickImmunity = clientElement.GetAttributeBool("KickImmunity", false); newsavedpermission.BanImmunity = clientElement.GetAttributeBool("BanImmunity", false); newsavedpermission.HideJoin = clientElement.GetAttributeBool("HideJoin", false); newsavedpermission.AccessDeathChatAlive = clientElement.GetAttributeBool("AccessDeathChatAlive", false); newsavedpermission.AdminPrivateMessage = clientElement.GetAttributeBool("AdminPrivateMessage", false); newsavedpermission.AdminChannelSend = clientElement.GetAttributeBool("AdminChannelSend", true); newsavedpermission.AdminChannelReceive = clientElement.GetAttributeBool("AdminChannelReceive", false); newsavedpermission.SendServerConsoleInfo = clientElement.GetAttributeBool("SendServerConsoleInfo", false); newsavedpermission.CanBroadcast = clientElement.GetAttributeBool("CanBroadcast", false); clientPermissions.Add(newsavedpermission); } if (Errorcount == 0) { SaveClientPermissions(); } }
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); #if CLIENT if (autoRestart) { GameMain.NetLobbyScreen.SetAutoRestart(autoRestart, AutoRestartInterval); } #endif subSelectionMode = SelectionMode.Manual; Enum.TryParse(doc.Root.GetAttributeString("SubSelection", "Manual"), out subSelectionMode); Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote; modeSelectionMode = SelectionMode.Manual; Enum.TryParse(doc.Root.GetAttributeString("ModeSelection", "Manual"), out modeSelectionMode); Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote; var traitorsEnabled = TraitorsEnabled; Enum.TryParse(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled); TraitorsEnabled = traitorsEnabled; GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled); //"65-90", "97-122", "48-59" = upper and lower case english alphabet and numbers string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", new string[] { "32-33", "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(Pair <int, int> .Create(min, max)); } } AllowedRandomMissionTypes = doc.Root.GetAttributeStringArray( "AllowedRandomMissionTypes", MissionPrefab.MissionTypes.ToArray()).ToList(); if (GameMain.NetLobbyScreen != null #if CLIENT && GameMain.NetLobbyScreen.ServerMessage != null #endif ) { #if SERVER GameMain.NetLobbyScreen.ServerName = doc.Root.GetAttributeString("name", ""); GameMain.NetLobbyScreen.SelectedModeName = GameMode; GameMain.NetLobbyScreen.MissionTypeName = MissionType; #endif GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", ""); } #if CLIENT showLogButton.Visible = SaveServerLogs; #endif List <string> monsterNames = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character); 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); } } extraCargo = new Dictionary <ItemPrefab, int>(); 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.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); }
public void LoadClientPermissions() { ClientPermissions.Clear(); if (!File.Exists(ClientPermissionsFile)) { if (File.Exists("Data/clientpermissions.txt")) { LoadClientPermissionsOld("Data/clientpermissions.txt"); } return; } XDocument doc = XMLExtensions.TryLoadXml(ClientPermissionsFile); foreach (XElement clientElement in doc.Root.Elements()) { string clientName = clientElement.GetAttributeString("name", ""); string clientIP = clientElement.GetAttributeString("ip", ""); string steamIdStr = clientElement.GetAttributeString("steamid", ""); if (string.IsNullOrWhiteSpace(clientName)) { DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - all clients must have a name and an IP address."); continue; } if (string.IsNullOrWhiteSpace(clientIP) && string.IsNullOrWhiteSpace(steamIdStr)) { DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - all clients must have an IP address or a Steam ID."); continue; } ClientPermissions permissions = Networking.ClientPermissions.None; List <DebugConsole.Command> permittedCommands = new List <DebugConsole.Command>(); if (clientElement.Attribute("preset") == null) { string permissionsStr = clientElement.GetAttributeString("permissions", ""); if (permissionsStr.ToLowerInvariant() == "all") { foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) { permissions |= permission; } } else if (!Enum.TryParse(permissionsStr, out permissions)) { DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + permissionsStr + "\" is not a valid client permission."); continue; } if (permissions.HasFlag(Networking.ClientPermissions.ConsoleCommands)) { foreach (XElement commandElement in clientElement.Elements()) { if (commandElement.Name.ToString().ToLowerInvariant() != "command") { continue; } string commandName = commandElement.GetAttributeString("name", ""); DebugConsole.Command command = DebugConsole.FindCommand(commandName); if (command == null) { DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + commandName + "\" is not a valid console command."); continue; } permittedCommands.Add(command); } } } else { string presetName = clientElement.GetAttributeString("preset", ""); PermissionPreset preset = PermissionPreset.List.Find(p => p.Name == presetName); if (preset == null) { DebugConsole.ThrowError("Failed to restore saved permissions to the client \"" + clientName + "\". Permission preset \"" + presetName + "\" not found."); return; } else { permissions = preset.Permissions; permittedCommands = preset.PermittedCommands.ToList(); } } if (!string.IsNullOrEmpty(steamIdStr)) { if (ulong.TryParse(steamIdStr, out ulong steamID)) { ClientPermissions.Add(new SavedClientPermission(clientName, steamID, permissions, permittedCommands)); } else { DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + steamIdStr + "\" is not a valid Steam ID."); continue; } } else { ClientPermissions.Add(new SavedClientPermission(clientName, clientIP, permissions, permittedCommands)); } } }
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); #if SERVER AutoRestart = doc.Root.GetAttributeBool("autorestart", true); #endif #if CLIENT AutoRestart = doc.Root.GetAttributeBool("autorestart", false); if (autoRestart) { GameMain.NetLobbyScreen.SetAutoRestart(autoRestart, AutoRestartInterval); } #endif subSelectionMode = SelectionMode.Manual; Enum.TryParse(doc.Root.GetAttributeString("SubSelection", "Manual"), out subSelectionMode); Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote; modeSelectionMode = SelectionMode.Manual; Enum.TryParse(doc.Root.GetAttributeString("ModeSelection", "Manual"), out modeSelectionMode); Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote; var traitorsEnabled = TraitorsEnabled; Enum.TryParse(doc.Root.GetAttributeString("TraitorsEnabled", "No"), out traitorsEnabled); TraitorsEnabled = traitorsEnabled; GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled); AllowedRandomMissionTypes = doc.Root.GetAttributeStringArray( "AllowedRandomMissionTypes", MissionPrefab.MissionTypes.ToArray()).ToList(); if (GameMain.NetLobbyScreen != null #if CLIENT && GameMain.NetLobbyScreen.ServerMessage != null #endif ) { #if SERVER GameMain.NetLobbyScreen.ServerName = doc.Root.GetAttributeString("name", ""); GameMain.NetLobbyScreen.SelectedModeName = GameMode; GameMain.NetLobbyScreen.MissionTypeName = MissionType; #endif GameMain.NetLobbyScreen.ServerMessageText = doc.Root.GetAttributeString("ServerMessage", ""); } #if CLIENT showLogButton.Visible = SaveServerLogs; #endif List <string> monsterNames = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character); 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); } } extraCargo = new Dictionary <ItemPrefab, int>(); AutoBanTime = doc.Root.GetAttributeFloat("autobantime", 60); MaxAutoBanTime = doc.Root.GetAttributeFloat("maxautobantime", 360); }