Beispiel #1
0
        public void Execute(IRocketPlayer caller, string[] command)
        {
            if (command.Length < 1)
            {
                UnturnedChat.Say(caller, "Invalid use!");
                return;
            }

            RocketPermissions rocketPerms = new RocketPermissions();
            bool var = true;

            if (command.Length == 1)
            {
                foreach (RocketPermissionsGroup group in rocketPerms.Groups)
                {
                    if (group.Priority < 80)
                    {
                        CommandWindow.onCommandWindowInputted.Invoke("p remove " + command[0] + " " + group.DisplayName, ref var);
                    }
                }
                return;
            }
            else
            {
                UnturnedChat.Say(caller, "Invalid use!");
                return;
            }
        }
Beispiel #2
0
        public override async Task DoAsync()
        {
            RocketPermissions rocket = await LoadRocketPermissionsAsync();

            if (rocket == null)
            {
                Console.WriteLine("[~] Could not load Rocket permissions!");
                return;
            }

            Console.WriteLine("[~] Preparing OpenMod permissions");

            PermissionRolesData openMod = new PermissionRolesData {
                Roles = new List <PermissionRoleData>()
            };

            foreach (RocketPermissionsGroup group in rocket.Groups)
            {
                openMod.Roles.Add(await GetRoleFromRocketGroup(group));
            }

            Console.WriteLine("[~] Saving OpenMod permissions");

            await SaveAsync(openMod);
        }
 internal PermissionsMemory()
 {
     _rp        = new RocketPermissions();
     _rp.Groups = new List <RocketPermissionsGroup>()
     {
         new RocketPermissionsGroup(_rp.DefaultGroup, _rp.DefaultGroup, null, new List <string>(), new List <Permission>(), "white")
     };
 }
Beispiel #4
0
        protected async Task <RocketPermissions> LoadRocketPermissionsAsync()
        {
            Console.WriteLine("[~] Loading Rocket permissions");
            FileStream        stream = File.Open("Rocket.Permissions.xml", FileMode.Open);
            RocketPermissions rocket = (RocketPermissions) new XmlSerializer(typeof(RocketPermissions)).Deserialize(stream);

            stream.Close();
            return(rocket);
        }
 internal void DeserializeXML()
 {
     try
     {
         using (StreamReader reader = new StreamReader(_rd))
         {
             _rp = _sr.Deserialize(reader) as RocketPermissions;
         }
     }
     catch (Exception) { }
 }
Beispiel #6
0
        public override async Task DoAsync()
        {
            await LogInfo("Loading user data from the following Rocket sources:" +
                          "\n" + "* Permissions");

            RocketPermissions rocketPermissions = await LoadRocketPermissionsAsync();

            if (rocketPermissions == null)
            {
                await LogInfo("Could not load Rocket permissions");

                return;
            }

            UsersData openMod = new UsersData {
                Users = new List <UserData>()
            };

            await LogInfo("Preparing user data");

            foreach (RocketPermissionsGroup group in rocketPermissions.Groups)
            {
                foreach (string user in group.Members)
                {
                    //TODO: Check what user id actually is
                    if (openMod.Users.All(u => u.Id != user))
                    {
                        openMod.Users.Add(new UserData()
                        {
                            Roles = new HashSet <string>()
                            {
                                group.Id
                            },
                            Type            = "player",
                            Data            = new Dictionary <string, object>(),
                            FirstSeen       = DateTime.Now,
                            LastSeen        = DateTime.Today,
                            Id              = user,
                            LastDisplayName = user,
                            Permissions     = new HashSet <string>()
                        });
                    }
                    else if (openMod.Users.Any(u => u.Id == user))
                    {
                        openMod.Users.FirstOrDefault(u => u.Id == user)?.Roles.Add(group.Id);
                    }
                }
            }

            await LogInfo("Saving user data");
            await SaveAsync(openMod);
        }
Beispiel #7
0
        protected async Task <RocketPermissions> LoadRocketPermissionsAsync()
        {
            await LogInfo("Loading Rocket permissions");

            if (Cache.RocketPermissions != null)
            {
                return(Cache.RocketPermissions);
            }
            RocketPermissions result = await DeserializeRocketAsset <RocketPermissions>("Permissions.Config.xml");

            Cache.RocketPermissions = result;
            return(result);
        }
Beispiel #8
0
        public void Migrate(IDependencyContainer container, string basePath)
        {
            ConfigurationPermissionProvider permissions =
                (ConfigurationPermissionProvider)container.Resolve <IPermissionProvider>("default_permissions");
            ILogger          logger           = container.Resolve <ILogger>();
            XmlConfiguration xmlConfiguration = (XmlConfiguration)container.Resolve <IConfiguration>("xml");

            xmlConfiguration.ConfigurationRoot = null;

            ConfigurationContext context = new ConfigurationContext(basePath, "Permissions.config");

            if (!xmlConfiguration.Exists(context))
            {
                logger.LogError("Permissions migration failed: Permissions.config.xml was not found in: " + basePath);
                return;
            }

            xmlConfiguration.Scheme = typeof(RocketPermissions);
            xmlConfiguration.Load(context);

            //bug: doesn't deserialize correctly.
            RocketPermissions legacyPermissions = xmlConfiguration.Get <RocketPermissions>();

            foreach (RocketPermissionsGroup group in legacyPermissions.Groups)
            {
                PermissionGroup newGroup = new PermissionGroup
                {
                    Name     = group.DisplayName,
                    Id       = group.Id,
                    Priority = 0
                };

                if (!permissions.CreateGroup(newGroup))
                {
                    logger.LogWarning($"Failed to migrate group: {group.DisplayName} (Id: {group.Id})");
                    continue;
                }

                foreach (Permission permission in group.Permissions)
                {
                    permissions.AddPermission(newGroup, permission.Name);
                }
            }

            // restore parent groups
            foreach (RocketPermissionsGroup group in legacyPermissions.Groups)
            {
                if (string.IsNullOrEmpty(group.ParentGroup))
                {
                    continue;
                }

                IPermissionGroup sourceGroup = permissions.GetGroup(group.Id);
                if (sourceGroup == null)
                {
                    continue;
                }

                IPermissionGroup targetGroup = permissions.GetGroup(group.ParentGroup);
                if (targetGroup == null)
                {
                    continue;
                }

                if (legacyPermissions.DefaultGroup.Equals(group.Id))
                {
                    GroupPermissionSection section =
                        permissions.GetConfigSection <GroupPermissionSection>(sourceGroup, false);
                    section.AutoAssign = true;
                    section.Save();
                }

                permissions.AddGroup(sourceGroup, targetGroup);
            }

            //todo migrate players
            permissions.Save();
        }
Beispiel #9
0
        protected override void Load()
        {
            if (Configuration.Instance.Enabled)
            {
                Instance = this;
                XmlSerializer formatter = new XmlSerializer(typeof(RocketPermissions));

                // десериализация
                using (FileStream fs = new FileStream("Permissions.config.xml", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    this.permissions = (RocketPermissions)formatter.Deserialize(fs);
                    fs.Close();
                }

                //Provider.onServerShutdown += OnServerShutdown;

                //cts = new CancellationTokenSource();
                //token = cts.Token;

                path      = $@"Plugins\{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}\Inventories\{SDG.Unturned.Provider.map}";
                pathPages = $@"Plugins\{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}\Data\{SDG.Unturned.Provider.map}";
                pathTemp  = pathPages + @"\Temp";

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                DirectoryInfo directory = new DirectoryInfo(path);
                if (directory.Attributes == FileAttributes.ReadOnly)
                {
                    directory.Attributes &= ~FileAttributes.ReadOnly;
                }

                if (!System.IO.Directory.Exists(pathPages))
                {
                    System.IO.Directory.CreateDirectory(pathPages);
                }
                DirectoryInfo directoryPages = new DirectoryInfo(pathPages);
                if (directory.Attributes == FileAttributes.ReadOnly)
                {
                    directory.Attributes &= ~FileAttributes.ReadOnly;
                }

                if (!System.IO.Directory.Exists(pathTemp))
                {
                    System.IO.Directory.CreateDirectory(pathTemp);
                }
                DirectoryInfo directoryTemp = new DirectoryInfo(pathTemp);
                if (directory.Attributes == FileAttributes.ReadOnly)
                {
                    directory.Attributes &= ~FileAttributes.ReadOnly;
                }

                //LoadInventoryTo(path, pathPages);
                //WatcherAsync(token, path, pathPages, pathTemp);
                Logger.Log("VirtualBoxes by M22 loaded!", ConsoleColor.Cyan);
                foreach (var group in Configuration.Instance.Groups)
                {
                    Console.WriteLine($"{group.GroupID}: {group.BoxLimit}");
                }
            }
            else
            {
                Logger.Log("Plugin is turned off in Configuration, unloading...", ConsoleColor.Cyan);
                UnloadPlugin();
            }
        }