Пример #1
0
        public void WriteSettings(BungeeSettings settings)
        {
            int i = 0;

            while (!FileWriter.IsFileWritable(ConfigYML))
            {
                if (i > 60 * 5)
                {
                    Console.WriteLine("File " + ConfigYML.FullName + " was not writable for 5 minutes, aborting...");
                    return;
                }
                Thread.Sleep(1000);
                i++;
            }

            lock (fileLock)
            {
                //TODO this can cause crash if file is somehow locked
                using (StreamWriter streamWriter = new StreamWriter(ConfigYML.Create()))
                {
                    Serializer serializer = new Serializer();
                    serializer.Serialize(streamWriter, settings);
                }
            }
        }
Пример #2
0
 private void StoreGroupsToConfig(BungeeSettings settings)
 {
     settings.groups = new Dictionary <string, List <string> >();
     foreach (Group group in Groups)
     {
         settings.groups.Add(group.User, new List <string>(group.Groups));
     }
 }
Пример #3
0
 private void StorePermissionsToConfig(BungeeSettings settings)
 {
     settings.permissions = new Dictionary <string, List <string> >();
     foreach (Permission permission in Permissions)
     {
         settings.permissions.Add(permission.Name, new List <string>(permission.PermissionList));
     }
 }
Пример #4
0
        private void LoadServersFromConfig(BungeeSettings settings)
        {
            while (!ServerManager.Initialized)
            {
                Thread.Sleep(500);
            }

            List <NetworkServer> servers = new List <NetworkServer>();

            if (settings.servers == null)
            {
                Servers = new ObservableCollection <NetworkServer>();
                return;
            }

            foreach (var settingsServer in settings.servers)
            {
                string name = settingsServer.Key;
                if (settingsServer.Value.ForkServer)
                {
                    EntityViewModel viewModel =
                        ServerManager.Instance.GetEntityViewModelByUid(settingsServer.Value.ForkServerUid);
                    if (viewModel is ServerViewModel serverViewModel)
                    {
                        NetworkForkServer server = new NetworkForkServer(serverViewModel, settingsServer.Value, name);
                        servers.Add(server);
                    }
                    else
                    {
                        Console.WriteLine("[FATAL] Error finding server with UID " +
                                          settingsServer.Value.ForkServerUid + " for network " + Network.Name);
                        ErrorLogger.Append(new Exception("[FATAL] Error finding server with UID " +
                                                         settingsServer.Value.ForkServerUid + " for network " +
                                                         Network.Name));
                    }
                }
                else
                {
                    NetworkExternalServer server = new NetworkExternalServer(settingsServer.Value, name);
                    servers.Add(server);
                }
            }

            Servers = new ObservableCollection <NetworkServer>(servers);
        }
Пример #5
0
        private void StoreServersToConfig(BungeeSettings settings)
        {
            settings.servers = new Dictionary <string, Logic.Model.Settings.Server>();
            foreach (NetworkServer networkServer in Servers)
            {
                settings.servers.Add(networkServer.Name, networkServer.ProxyServer);
            }

            if (settings.listeners.Count < 1)
            {
                settings.listeners.Add(new Listener());
            }

            settings.listeners[0].priorities = new List <string>();
            foreach (NetworkServer server in Servers)
            {
                settings.listeners[0].priorities.Add(server.Name);
            }
        }
Пример #6
0
        private void InitializeBungeeConfig()
        {
            BungeeSettings bungeeSettings = new BungeeSettings();

            bungeeSettings.groups.Add("md_5", new List <string> {
                "admin"
            });
            bungeeSettings.disabled_commands.Add("disabledcommandhere");
            bungeeSettings.servers.Add("lobby", new Server());
            bungeeSettings.listeners = new List <Listener> {
                new Listener()
            };
            bungeeSettings.listeners[0].priorities.Add("lobby");
            bungeeSettings.permissions.Add("default", new List <string> {
                "bungeecord.command.server", "bungeecord.command.list"
            });
            bungeeSettings.permissions.Add("admin", new List <string> {
                "bungeecord.command.alert", "bungeecord.command.end", "bungeecord.command.ip", "bungeecord.command.reload"
            });

            WriteSettings(bungeeSettings);
        }
Пример #7
0
        private void LoadGroupsFromConfig(BungeeSettings settings)
        {
            while (!ServerManager.Initialized)
            {
                Thread.Sleep(500);
            }

            List <Group> groups = new List <Group>();

            if (settings.groups == null)
            {
                Groups = new ObservableCollection <Group>();
                return;
            }

            foreach (KeyValuePair <string, List <string> > keyValuePair in settings.groups)
            {
                Group g = new Group(keyValuePair.Key, new ObservableCollection <string>(keyValuePair.Value));
                groups.Add(g);
            }

            Groups = new ObservableCollection <Group>(groups);
        }
Пример #8
0
        private void LoadPermissionsFromConfig(BungeeSettings settings)
        {
            while (!ServerManager.Initialized)
            {
                Thread.Sleep(500);
            }

            List <Permission> permissions = new List <Permission>();

            if (settings.permissions == null)
            {
                Permissions = new ObservableCollection <Permission>();
                return;
            }

            foreach (KeyValuePair <string, List <string> > keyValuePair in settings.permissions)
            {
                Permission p = new Permission(keyValuePair.Key, new ObservableCollection <string>(keyValuePair.Value));
                permissions.Add(p);
            }

            Permissions = new ObservableCollection <Permission>(permissions);
        }