Ejemplo n.º 1
0
        public void Init()
        {
            #region WEBSERVICE
            // SharedLibrary.WebService.Init();
            //WebSvc = new WebService();
            //WebSvc.StartScheduler();
            #endregion

            #region PLUGINS
            SharedLibrary.Plugins.PluginImporter.Load(this);

            foreach (var Plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins)
            {
                try
                {
                    Plugin.OnLoadAsync(this);
                }

                catch (Exception e)
                {
                    Logger.WriteError($"An error occured loading plugin {Plugin.Name}");
                    Logger.WriteDebug($"Exception: {e.Message}");
                    Logger.WriteDebug($"Stack Trace: {e.StackTrace}");
                }
            }
            #endregion

            #region CONFIG
            var Configs = Directory.EnumerateFiles($"{Program.OperatingDirectory}config/servers").Where(x => x.Contains(".cfg"));

            if (Configs.Count() == 0)
            {
                ServerConfigurationGenerator.Generate();
            }

            foreach (var file in Configs)
            {
                var Conf = ServerConfiguration.Read(file);

                Task.Run(async() =>
                {
                    try
                    {
                        var ServerInstance = new IW4MServer(this, Conf);
                        await ServerInstance.Initialize();

                        lock (_servers)
                        {
                            _servers.Add(ServerInstance);
                        }

                        Logger.WriteVerbose($"Now monitoring {ServerInstance.Hostname}");

                        // this way we can keep track of execution time and see if problems arise.
                        var Status = new AsyncStatus(ServerInstance, UPDATE_FREQUENCY);
                        lock (TaskStatuses)
                        {
                            TaskStatuses.Add(Status);
                        }
                    }

                    catch (ServerException e)
                    {
                        Logger.WriteError($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors");
                        if (e.GetType() == typeof(DvarException))
                        {
                            Logger.WriteDebug($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)");
                        }
                        else if (e.GetType() == typeof(NetworkException))
                        {
                            Logger.WriteDebug(e.Message);
                            Logger.WriteDebug($"Internal Exception: {e.Data["internal_exception"]}");
                        }
                    }
                });
            }
            #endregion

            #region COMMANDS
            if (ClientSvc.GetOwners().Result.Count == 0)
            {
                Commands.Add(new COwner());
            }

            Commands.Add(new CQuit());
            Commands.Add(new CKick());
            Commands.Add(new CSay());
            Commands.Add(new CTempBan());
            Commands.Add(new CBan());
            Commands.Add(new CWhoAmI());
            Commands.Add(new CList());
            Commands.Add(new CHelp());
            Commands.Add(new CFastRestart());
            Commands.Add(new CMapRotate());
            Commands.Add(new CSetLevel());
            Commands.Add(new CUsage());
            Commands.Add(new CUptime());
            Commands.Add(new CWarn());
            Commands.Add(new CWarnClear());
            Commands.Add(new CUnban());
            Commands.Add(new CListAdmins());
            Commands.Add(new CLoadMap());
            Commands.Add(new CFindPlayer());
            Commands.Add(new CListRules());
            Commands.Add(new CPrivateMessage());
            Commands.Add(new CReload());
            Commands.Add(new CFlag());
            Commands.Add(new CReport());
            Commands.Add(new CListReports());
            Commands.Add(new CListBanInfo());
            Commands.Add(new CListAlias());
            Commands.Add(new CExecuteRCON());
            Commands.Add(new CPlugins());
            Commands.Add(new CIP());
            Commands.Add(new CMask());
            Commands.Add(new CPruneAdmins());

            foreach (Command C in SharedLibrary.Plugins.PluginImporter.ActiveCommands)
            {
                Commands.Add(C);
            }
            #endregion

            Running = true;
        }