예제 #1
0
        public void ExecuteMigration(string[] args)
        {
            Logger.Log("Adding economy migration job to autoexec.yaml...");
            var openmodDirectory = OpenModInstallerPlugin.Instance.OpenModManager.WorkingDirectory;
            var autoexecYaml     = Path.Combine(openmodDirectory, "autoexec.yaml");

            var dataStore = new YamlDataStore(new DataStoreCreationParameters
            {
                WorkingDirectory = openmodDirectory,
                LogOnChange      = false
            }, null, null);

            if (!AsyncHelper.RunSync(() => dataStore.ExistsAsync("autoexec")))
            {
                var openmodAssembly = typeof(YamlDataStore).Assembly;
                using var autoexecFileStream = openmodAssembly.GetManifestResourceStream("OpenMod.Core.autoexec.yaml");
                using var ms = new MemoryStream();
                autoexecFileStream !.CopyTo(ms);

                ms.Seek(0, SeekOrigin.Begin);
                File.WriteAllBytes(autoexecYaml, ms.ToArray());
            }

            var jobsFile = AsyncHelperEx.RunSync(() => dataStore.LoadAsync <ScheduledJobsFile>("autoexec"));

            if (jobsFile !.Jobs !.Any(d => d.Name?.Equals("OpenMod.Installer.EconomyMigration") ?? false))
            {
                return;
            }

            jobsFile.Jobs.Add(new ScheduledJob
            {
                Name    = "OpenMod.Installer.EconomyMigration",
                Enabled = true,
                Task    = "openmod_command",
                Args    = new Dictionary <string, object>
                {
                    { "commands", new List <string>
                      {
                          "MigrateUconomy"
                      } }
                },
                Schedule = "@single_exec"
            });

            AsyncHelperEx.RunSync(() => dataStore.SaveAsync("autoexec", jobsFile));
        }
        public void ExecuteMigration(string[] args)
        {
            Logger.Log("Importing RocketMod permissions to OpenMod...");

            var rocketPermissionsPath = Path.Combine(ReadWrite.PATH, "Servers", Provider.serverID, "Rocket", "Permissions.config.xml");
            var deserializer          = new XmlSerializer(typeof(RocketPermissions));

            using var stream = new FileStream(rocketPermissionsPath, FileMode.Open);
            var rocketPermissions = (RocketPermissions)deserializer.Deserialize(stream);

            var openmodRoles = new
            {
                Roles = new List <PermissionRoleData>()
            };

            var openmodUsers = new
            {
                Users = new List <UserData>()
            };

            // importing cooldowns is not possible as they are per command in OpenMod and per permissions in RocketMod
            foreach (var group in rocketPermissions.Groups)
            {
                openmodRoles.Roles.Add(new PermissionRoleData
                {
                    Id   = group.Id,
                    Data = new Dictionary <string, object>
                    {
                        { "color", group.Color },
                        { "prefix", group.Prefix },
                        { "suffix", group.Suffix }
                    },
                    DisplayName    = group.DisplayName,
                    IsAutoAssigned = group.Id.Equals(rocketPermissions.DefaultGroup, StringComparison.OrdinalIgnoreCase),
                    Parents        = new HashSet <string> {
                        group.ParentGroup ?? string.Empty
                    },                                                                   // in rocket default id parameter ParentGroup is null
                    Permissions = new HashSet <string>(group.Permissions.Select(c => "RocketMod:" + c.Name)),
                    Priority    = group.Priority
                });

                foreach (var member in group.Members)
                {
                    var userData = openmodUsers.Users.Find(d => d.Id == member);
                    if (userData == null)
                    {
                        userData = new UserData
                        {
                            Data            = new Dictionary <string, object>(),
                            FirstSeen       = DateTime.Now,
                            LastSeen        = DateTime.Now,
                            Id              = member,
                            LastDisplayName = member,
                            Permissions     = new HashSet <string>(),
                            Roles           = new HashSet <string>(),
                            Type            = "player"
                        };

                        openmodUsers.Users.Add(userData);
                    }

                    userData.Roles.Add(group.Id);
                }
            }

            var apiAssembly      = AssemblyHelper.GetAssembly("OpenMod.API");
            var workingDirectory = OpenModInstallerPlugin.Instance.OpenModManager.WorkingDirectory;

            var dataStoreParams = new DataStoreCreationParameters
            {
                ComponentId      = "OpenMod.Core",
                Prefix           = "openmod",
                WorkingDirectory = workingDirectory
            };

            var dataStore = new YamlDataStore(dataStoreParams, null, null);

            AsyncHelperEx.RunSync(() => dataStore.SaveAsync("roles", openmodRoles));
            AsyncHelperEx.RunSync(() => dataStore.SaveAsync("users", openmodUsers));

            Logger.Log($"Imported {openmodRoles.Roles.Count} permission group(s) and {openmodUsers.Users.Count} player(s) from RocketMod's Permission.config.xml to OpenMod.");
        }
예제 #3
0
 public void ExecuteMigration(string[] args)
 {
     AsyncHelperEx.RunSync(() => DownloadPackage(args.Contains("--force") || args.Contains("-f"), args.Contains("-p") || args.Contains("--pre")));
 }