public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new SimpleMessagesException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting("SimpleMessages", "Enabled"); if (!_enabled) throw new SimpleMessagesException(String.Format("{0} has been disabled", Name)); Int32 _interval; try { _interval = Convert.ToInt32(_ini.GetSetting("SimpleMessages", "Interval", "60")); } catch { _interval = 60; } _prefix = _ini.GetSetting("SimpleMessages", "Prefix"); _repeat = _ini.GetBoolSetting("SimpleMessages", "Repeat"); var _random = _ini.GetBoolSetting("SimpleMessages", "Random"); _messages = _ini.EnumSection("Messages"); if (_random) { var rnd = new Random(); _messages = _messages.OrderBy(x => rnd.Next()).ToArray(); } _timer = new Timer {Interval = (_interval*1000)}; _timer.Elapsed += _timer_Elapsed; _timer.Enabled = true; }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new WebRconException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting(Name, "Enabled"); if (!_enabled) throw new WebRconException(String.Format("{0} has been disabled", Name)); var port = _ini.GetSetting(Name, "Port"); try { _port = Convert.ToInt32(port); } catch (Exception ex) { throw new WebRconException(String.Format("Invalid port: {0}", ex.Message)); } _password = _ini.GetSetting(Name, "Password"); if (_password == "") { _password = Utils.GetRandomString(); } #if DEBUG _serverurl = String.Format("http://localhost:{0}/", _port); #else _serverurl = String.Format("http://*:{0}/", _port); #endif _webServer = new WebServer(HttpRequest, _serverurl); _webServer.Run(); AppConsole.Log(String.Format("Started HTTP server at {0}. Password: {1}", _serverurl, _password), ConsoleColor.Cyan); _port++; _socketServer = new WebSocketServer(_port); _socketServer.AddWebSocketService("/rcon", () => new SocketBehavior(_api, _password)); _socketServer.Start(); LoadHtdocsFiles(); }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; IniParser _ini; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new PlayerCheckException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting(Name, "Enabled"); if (!_enabled) throw new PlayerCheckException(String.Format("{0} has been disabled", Name)); _checkip = _ini.GetBoolSetting(Name, "CheckIP"); _kickMessage = _ini.GetSetting(Name, "KickMessage"); if (_ini.GetSetting(Name, "Mode") == "white") { _mode = Mode.Whitelist; } var settings = new DriverSettings() { Api = api, Ini = _ini, PluginPath = dllpath }; _driver = Base.GetDriver(_ini); _driver.SetConfig(settings); api.OnBeMessageReceivedEvent += onBEMessageReceivedEvent; }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new $safeprojectname$Exception(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting(Name, "Enabled"); if (!_enabled) throw new $safeprojectname$Exception(String.Format("{0} has been disabled", Name)); }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new BEFilterMonitorException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting(Name, "Enabled"); if (!_enabled) throw new BEFilterMonitorException(String.Format("{0} has been disabled", Name)); _worker = new Thread(FilterMonitor); _worker.Start(); }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new LoggerException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting("Logger", "Enabled"); if (!_enabled) { throw new LoggerException(String.Format("{0} has been disabled", Name)); } _path = _ini.GetSetting("Logger", "Path"); if (_path == "") _path = _defaultLogPath; if (!Directory.Exists(_path)) { try { Directory.CreateDirectory(_path); } catch { throw new LoggerException(String.Format("Log path \"{0}\" does not exist.", _path)); } } OpenLogs(); _api.OnBeMessageReceivedEvent += _be_MessageEventHandler; }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new ScheduledTasksException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting("ScheduledTasks", "Enabled"); if (!_enabled) throw new ScheduledTasksException(String.Format("{0} has been disabled", Name)); _debug = _ini.GetBoolSetting("ScheduledTasks", "Debug"); _schedule = _ini.GetSetting("ScheduledTasks", "Schedule"); if (_schedule == "") throw new ScheduledTasksException(String.Format("{0} has been disabled. No schedule defined.", Name)); if (!Path.IsPathRooted(_schedule)) { _schedule = Path.Combine(_dllpath, _schedule); } var ext = Path.GetExtension(_schedule); if (ext == ".json") { Task.LoadFromJSON(_schedule); } if (_debug) { var i = 0; AppConsole.Log("---------------", ConsoleColor.DarkMagenta); AppConsole.Log("Scheduled Tasks", ConsoleColor.DarkMagenta); AppConsole.Log("---------------", ConsoleColor.DarkMagenta); foreach (var t in Task.Tasks) { i++; AppConsole.Log(String.Format("Task {0}", i), ConsoleColor.DarkMagenta); AppConsole.Log(String.Format("Running in about {0}", t.TimeSpan.Humanize(2, true)), ConsoleColor.DarkMagenta); if (t.Loop != 1) { AppConsole.Log(String.Format("Repeating every {0}, {1} times", t.Interval.Humanize(2, true), t.Loop), ConsoleColor.DarkMagenta); } AppConsole.Log(String.Format("Command: {0} {1}", t.Command.Type, t.Command.Parameters), ConsoleColor.DarkMagenta); AppConsole.Log(""); } } if (Task.Tasks.Count == 0) { throw new ScheduledTasksException(String.Format("{0} has been disabled. No tasks found.", Name)); } _worker = new Thread(TaskMonitor); _worker.Start(); }
public static void LoadTasks(IniParser ini) { var _i = -1; while (true) { var now = DateTime.Now; _i++; var command = ini.GetSetting("Tasks", String.Format("Command{0}", _i)); if (String.IsNullOrWhiteSpace(command)) { if (_i == 0) continue; else { AppConsole.Log("Finished loading tasks", ConsoleColor.DarkMagenta); break; } } Command cmd; DateTime nextRun; var interval = TimeSpan.FromDays(1); var loop = 1; try { cmd = new Command(command); } catch (CommandException ex) { AppConsole.Log(String.Format("Error loading task {0}: {1}", _i, ex.Message), ConsoleColor.Red); continue; } var time = ini.GetSetting("Tasks", String.Format("Time{0}", _i)); if (!String.IsNullOrWhiteSpace(time)) { try { var h = Convert.ToDouble(time.Substring(0, 2)); var m = Convert.ToDouble(time.Substring(2, 2)); nextRun = DateTime.Today; nextRun = nextRun.AddHours(h); nextRun = nextRun.AddMinutes(m); if (now > nextRun) { nextRun = nextRun.Add(interval); } } catch (Exception ex) { AppConsole.Log(String.Format("Error loading task: Bad String Time {0}", ex.Message), ConsoleColor.Red); continue; } } else { try { interval = TimeSpan.FromSeconds(Convert.ToInt32(ini.GetSetting("Tasks", String.Format("Interval{0}", _i)))); } catch (Exception ex) { AppConsole.Log(String.Format("Error loading task: Bad String Interval {0}", ex.Message), ConsoleColor.Red); continue; } TimeSpan delay; try { delay = TimeSpan.FromSeconds(Convert.ToDouble(ini.GetSetting("Tasks", String.Format("Delay{0}", _i), "0"))); } catch { delay = new TimeSpan(); } loop = (ini.GetBoolSetting("Tasks", String.Format("Repeat{0}", _i))) ? -1 : 1; nextRun = now.Add(delay); nextRun = nextRun.Add(interval); } var task = new Task() { _command = cmd, _nextRun = nextRun, _loop = loop, _interval = interval }; _tasks.Add(task); } AppConsole.Log(String.Format("Added {0} tasks", _tasks.Count), ConsoleColor.DarkMagenta); }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new WebLoggerException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting("WebLogger", "Enabled"); if (!_enabled) throw new WebLoggerException(String.Format("{0} has been disabled", Name)); var url = _ini.GetSetting("WebLogger", "URL"); if (!Uri.TryCreate(url, UriKind.Absolute, out _uri)) { throw new WebLoggerException(String.Format("Error parsing url: {0}", url)); } _worker = new Thread(ProcessQueue); _worker.Start(); _api.OnBeMessageReceivedEvent += MessageEventHandler; }
public void Init(IApi api, string dllpath) { _api = api; _dllpath = dllpath; try { _ini = new IniParser(_configPath); } catch (Exception ex) { throw new RestartMessagesException(String.Format("Error loading config: {0}", ex.Message)); } _enabled = _ini.GetBoolSetting(Name, "Enabled"); if (!_enabled) throw new RestartMessagesException(String.Format("{0} has been disabled", Name)); _debug = _ini.GetBoolSetting("RestartMessages", "Debug"); try { _runtime = DateTime.Now.AddHours(Convert.ToInt16(_ini.GetSetting("RestartMessages", "ServerRuntime").Trim())); } catch (Exception ex) { throw new RestartMessagesException(String.Format("Could not parse ServerRuntime: {0}", ex.Message)); } try { var intervals = _ini.GetSetting("RestartMessages", "Interval"); foreach (var i in intervals.Split(',')) { _intervals.Add(_runtime.AddMinutes(-1 * Convert.ToInt16(i))); } _intervals.Sort(); if (_intervals.Count == 0) { throw new RestartMessagesException("Not intervals have been set"); } } catch (Exception ex) { throw new RestartMessagesException(String.Format("Could not parse Interval: {0}", ex.Message)); } try { _repeat = Convert.ToInt16(_ini.GetSetting("RestartMessages", "Repeat").Trim()); } catch (Exception ex) { throw new RestartMessagesException(String.Format("Could not parse Repeat: {0}", ex.Message)); } try { _message = _ini.GetSetting("RestartMessages", "Message").Trim(); } catch (Exception ex) { throw new RestartMessagesException(String.Format("Could not parse Message: {0}", ex.Message)); } _worker = new Thread(TaskMonitor); _worker.Start(); }