コード例 #1
0
        public PermissionPreset(XElement element)
        {
            Name        = element.GetAttributeString("name", "");
            Description = element.GetAttributeString("description", "");

            string permissionsStr = element.GetAttributeString("permissions", "");

            if (!Enum.TryParse(permissionsStr, out Permissions))
            {
                DebugConsole.ThrowError("Error in permission preset \"" + Name + "\" - " + permissionsStr + " is not a valid permission!");
            }

            PermittedCommands = new List <DebugConsole.Command>();
            if (Permissions.HasFlag(ClientPermissions.ConsoleCommands))
            {
                foreach (XElement subElement in element.Elements())
                {
                    if (subElement.Name.ToString().ToLowerInvariant() != "command")
                    {
                        continue;
                    }
                    string commandName = subElement.GetAttributeString("name", "");

                    DebugConsole.Command command = DebugConsole.FindCommand(commandName);
                    if (command == null)
                    {
                        DebugConsole.ThrowError("Error in permission preset \"" + Name + "\" - " + commandName + "\" is not a valid console command.");
                        continue;
                    }

                    PermittedCommands.Add(command);
                }
            }
        }
コード例 #2
0
        public void LoadVanillaClientPermissions()
        {
            clientPermissions.Clear();

            if (!File.Exists(VanillaClientPermissionsFile))
            {
                if (File.Exists("Data/clientpermissions.txt"))
                {
                    LoadClientPermissionsOld("Data/clientpermissions.txt");
                }
                return;
            }

            XDocument doc = XMLExtensions.TryLoadXml(VanillaClientPermissionsFile);

            foreach (XElement clientElement in doc.Root.Elements())
            {
                string clientName = clientElement.GetAttributeString("name", "");
                string clientIP   = clientElement.GetAttributeString("ip", "");
                if (string.IsNullOrWhiteSpace(clientName) || string.IsNullOrWhiteSpace(clientIP))
                {
                    DebugConsole.ThrowError("Error in " + VanillaClientPermissionsFile + " - all clients must have a name and an IP address.");
                    continue;
                }

                string            permissionsStr = clientElement.GetAttributeString("permissions", "");
                ClientPermissions permissions;
                if (!Enum.TryParse(permissionsStr, out permissions))
                {
                    DebugConsole.ThrowError("Error in " + VanillaClientPermissionsFile + " - \"" + permissionsStr + "\" is not a valid client permission.");
                    continue;
                }

                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 " + VanillaClientPermissionsFile + " - \"" + commandName + "\" is not a valid console command.");
                            continue;
                        }

                        permittedCommands.Add(command);
                    }
                }

                clientPermissions.Add(new SavedClientPermission(clientName, clientIP, permissions, permittedCommands));
            }
        }
コード例 #3
0
        public PermissionPreset(XElement element)
        {
            string name = element.GetAttributeString("name", "");

            Name        = TextManager.Get("permissionpresetname." + name, true) ?? name;
            Description = TextManager.Get("permissionpresetdescription." + name, true) ?? element.GetAttributeString("description", "");

            string permissionsStr = element.GetAttributeString("permissions", "");

            if (!Enum.TryParse(permissionsStr, out Permissions))
            {
                DebugConsole.ThrowError("Error in permission preset \"" + Name + "\" - " + permissionsStr + " is not a valid permission!");
            }

            PermittedCommands = new List <DebugConsole.Command>();
            if (Permissions.HasFlag(ClientPermissions.ConsoleCommands))
            {
                foreach (XElement subElement in element.Elements())
                {
                    if (!subElement.Name.ToString().Equals("command", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    string commandName = subElement.GetAttributeString("name", "");

                    DebugConsole.Command command = DebugConsole.FindCommand(commandName);
                    if (command == null)
                    {
#if SERVER
                        DebugConsole.ThrowError("Error in permission preset \"" + Name + "\" - " + commandName + "\" is not a valid console command.");
#endif
                        continue;
                    }

                    PermittedCommands.Add(command);
                }
            }
        }
コード例 #4
0
        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));
                }
            }
        }
コード例 #5
0
        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();
            }
        }