Exemple #1
0
        internal static void LoadConfig_impl(string trinity_config_file)
        {
            lock (config_load_lock)
            {
                if (!File.Exists(trinity_config_file))
                {
                    //TODO log warning
                    return;
                }

                var config = XmlConfiguration.Load(trinity_config_file);

                s_clusterConfigurations.Clear();
                s_localConfigurationSection.Clear();

                if (config.RootConfigVersion == ConfigurationConstants.Values.LEGACYVER)
                {
                    LoadConfigLegacy(trinity_config_file);
                }
                else if (config.RootConfigVersion == ConfigurationConstants.Values.CURRENTVER)
                {
                    LoadConfigCurrrentVer(config);
                }
                else
                {
                    throw new TrinityConfigException("Unrecognized " + ConfigurationConstants.Attrs.CONFIG_VERSION);
                }

                ApplyConfigurationSettings(GetLocalConfiguration());

                is_config_loaded = true;
            }
        }
Exemple #2
0
        public void Migrate(IDependencyContainer container, string basePath)
        {
            IHost host = container.Resolve <IHost>();

            ITranslationCollection translationsLocator = container.Resolve <ITranslationCollection>();

            ConfigurationContext toContext =
                new ConfigurationContext(host.WorkingDirectory, "Rocket.Unturned.Translations");

            translationsLocator.Load(toContext, new Dictionary <string, string>());

            ILogger          logger           = container.Resolve <ILogger>();
            XmlConfiguration xmlConfiguration = (XmlConfiguration)container.Resolve <IConfiguration>("xml");

            xmlConfiguration.ConfigurationRoot = "Translations";

            ConfigurationContext fromContext = new ConfigurationContext(basePath, "Rocket.en.translation");

            if (!xmlConfiguration.Exists(fromContext))
            {
                logger.LogError(
                    "Translations migration failed: Rocket.en.translation.xml was not found in: " + basePath);
                return;
            }

            xmlConfiguration.Load(fromContext);

            JArray translations = (JArray)((JsonNetConfigurationSection)xmlConfiguration["Translation"]).Node;

            foreach (JToken translation in translations)
            {
                JToken id    = translation["@Id"];
                JToken value = translation["@Value"];

                translationsLocator.Set(id.Value <string>(), value.Value <string>());
            }

            translationsLocator.Save();
        }
        internal static void LoadTrinityConfig(string trinity_config_file, bool forceLoad = false)
        {
            lock (config_load_lock)
            {
                if (is_config_loaded && !forceLoad)
                {
                    return;
                }
                if (!File.Exists(trinity_config_file))
                {
                    return;
                }

                var config = XmlConfiguration.Load(trinity_config_file);

                s_clusterConfigurations.Clear();
                s_localConfigurationSection.Clear();

                if (config.RootConfigVersion == ConfigurationConstants.Tags.LEGACYVER)
                {
                    LoadConfigLegacy(trinity_config_file);
                }
                else if (config.RootConfigVersion == ConfigurationConstants.Tags.CURRENTVER)
                {
                    s_localConfigurationSection = new ConfigurationSection(config.LocalSection);
                    var clusterSections = config.ClusterSections;
                    foreach (var clusterSection in clusterSections)
                    {
                        if (clusterSection.Attribute(ConfigurationConstants.Attrs.ID) != null)
                        {
                            s_clusterConfigurations.Add(clusterSection.Attribute(ConfigurationConstants.Attrs.ID).Value, new ClusterConfig(clusterSection));
                        }
                    }

                    s_current_cluster_config = new ClusterConfig(clusterSections.FirstOrDefault(
                                                                     _ => _.Attribute(ConfigurationConstants.Attrs.ID) == null) ??
                                                                 new XElement(ConfigurationConstants.Tags.CLUSTER));

                    s_clusterConfigurations.Add(ConfigurationConstants.Tags.DEFAULT_CLUSTER, s_current_cluster_config);
                }
                else
                {
                    throw new TrinityConfigException("Unrecognized " + ConfigurationConstants.Attrs.CONFIG_VERSION);
                }
                //LOCAL override CLUSTER
                var entries        = new Network.ServerInfo();
                var server_entries = s_current_cluster_config.GetMyServerInfo();
                var proxy_entries  = s_current_cluster_config.GetMyProxyInfo();
                if (proxy_entries != null)
                {
                    entries.Merge(proxy_entries);
                }
                if (server_entries != null)
                {
                    entries.Merge(server_entries);
                }

                foreach (var entry in s_localConfigurationSection)
                {
                    entries[entry.Key] = entry.Value;
                }

                ApplyConfigurationSettings(entries);

                is_config_loaded = true;
            }
        }
Exemple #4
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();
        }