Exemple #1
0
        public static async Task AddServer(CServerConfig serverConfig)
        {
            var client = new CServerConnection();

            XmlRPC_Clients[serverConfig.ServerLogin] = client;
            {
                var connected = await client.CreateConnection(IPAddress.Parse(serverConfig.IPAddress), serverConfig.Port);

                if (connected)
                {
                    CDebug.Log("Connected!");
                }
                else
                {
                    CDebug.ErrorLog("Couldn't connect to : " + serverConfig.IPAddress + ":" + serverConfig.Port);
                }
            }

            for (int i = 0; i < servicesTypeFound.Count; i++)
            {
                var value = servicesTypeFound[i];
                if (value.GetInterfaces().Contains(typeof(IServiceServer)) &&
                    value.GetInterfaces().Contains(typeof(IServiceStartAutomatically)))
                {
                    var s = client.ServerServices[value] = Activator.CreateInstance(value) as CService;
                    ((IServiceServer)s).Service_ServerConnection = client;
                    await((IServiceServer)s).ServerAdded();
                }
            }
            for (int i = 0; i < Plugins.Count; i++)
            {
                await Plugins[i].OnServerAdded(serverConfig.ServerLogin);
            }
        }
Exemple #2
0
    static async Task ReloadAllConfigs()
    {
        var servers_confFolder = CManiaNextControl.RunningPath + "configs";
        var global_confFile    = CManiaNextControl.RunningPath + "nextcontrol.conf";

        // Load global conf first
        {
        }

        CManiaNextControl.ServersConfig = new Dictionary <string, CServerConfig>();
        {
            CDebug.Log(servers_confFolder);

            if (!Directory.Exists(servers_confFolder))
            {
                Directory.CreateDirectory(servers_confFolder);
            }

            foreach (var file in Directory.GetFiles(servers_confFolder))
            {
                if (file.EndsWith(".conf"))
                {
                    CDebug.Log(file.LastIndexOf('.'));

                    string serverLogin = file.Substring(file.LastIndexOf("\\"), file.Length - file.LastIndexOf('.'));
                    var    config      = new CServerConfig(file);

                    if ((await config.GetLiveValue("Enabled", "false")).ToLower() == "false" ||
                        await config.GetLiveValue("Enabled", "false") == "0")
                    {
                        continue;
                    }

                    config.ServerLogin     = serverLogin;
                    config.SuperAdminLogin = await config.GetLiveValue("SuperAdminLogin", "SuperAdmin");

                    config.SuperAdminPassword = await config.GetLiveValue("SuperAdminPassword", "SuperAdmin");

                    config.Port = await config.GetLiveValue("Port", "") == "" ? CNetUtils.TryGetPort(serverLogin) : int.Parse(await config.GetLiveValue("Port"));

                    CManiaNextControl.ServersConfig[serverLogin] = config;
                }
            }
        }
    }