static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { //drop the error to log file and exit using (var sw = new StreamWriter(Path.Combine(Bot.RootDirectory, "error.log"), true)) { var e = (eventArgs.ExceptionObject as Exception); sw.WriteLine(e.Message); sw.WriteLine(e.StackTrace); if (eventArgs.IsTerminating) { Environment.Exit(5); } } }; //get the version of the bot and set the window title Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; Console.Title = $"Werewolf Moderator {version}"; //Initialize the TCP connections TCP.Initialize(); //Let the nodes reconnect Thread.Sleep(1000); //start up the bot new Thread(Bot.Initialize).Start(); new Thread(NodeMonitor).Start(); //now pause the main thread to let everything else run Thread.Sleep(-1); }
static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { //drop the error to log file and exit using (var sw = new StreamWriter(Path.Combine(Bot.RootDirectory, "..\\Logs\\error.log"), true)) { var e = (eventArgs.ExceptionObject as Exception); sw.WriteLine(DateTime.Now); sw.WriteLine(e.Message); sw.WriteLine(e.StackTrace + "\n"); if (eventArgs.IsTerminating) { Environment.Exit(5); } } }; #endif //get the version of the bot and set the window title Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; Console.Title = $"Werewolf Moderator {version}"; var updateid = ""; //attempt to get id from update if (args.Length > 0) { updateid = args[0]; } //Initialize the TCP connections TCP.Initialize(); //Let the nodes reconnect Thread.Sleep(1000); //initialize EF before we start receiving using (var db = new WWContext()) { var count = db.GlobalBans.Count(); } //start up the bot new Thread(() => Bot.Initialize(updateid)).Start(); new Thread(NodeMonitor).Start(); //new Thread(CpuMonitor).Start(); new Thread(UpdateHandler.SpamDetection).Start(); new Thread(UpdateHandler.BanMonitor).Start(); //new Thread(MessageMonitor).Start(); _timer = new System.Timers.Timer(); _timer.Elapsed += new ElapsedEventHandler(TimerOnTick); _timer.Interval = 1000; _timer.Enabled = true; //now pause the main thread to let everything else run Thread.Sleep(-1); }
private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { var e = eventArgs.ExceptionObject as Exception; Console.WriteLine(DateTime.UtcNow); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace + "\n"); if (eventArgs.IsTerminating) { Environment.Exit(5); } }; //get the version of the bot and set the window title var assembly = Assembly.GetExecutingAssembly(); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); var version = fvi.FileVersion; Console.Title = $"Werewolf Moderator {version}"; //Make sure another instance isn't already running if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) { Environment.Exit(2); } var updateid = ""; //attempt to get id from update if (args.Length > 0) { updateid = args[0]; } //Initialize the TCP connections TCP.Initialize(); //Let the nodes reconnect Thread.Sleep(1000); //initialize EF before we start receiving using (var db = new WWContext()) { var count = db.GlobalBans.Count(); } //start up the bot Task.Run(() => Bot.Initialize(updateid)); Task.Run(() => NodeMonitor()); Task.Run(() => UpdateHandler.SpamDetection()); Task.Run(() => UpdateHandler.BanMonitor()); _timer = new Timer(); _timer.Elapsed += TimerOnTick; _timer.Interval = 1000; _timer.Enabled = true; //now pause the main thread to let everything else run Thread.Sleep(-1); }
static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { //drop the error to log file and exit using (var sw = new StreamWriter(Path.Combine(Bot.RootDirectory, "..\\Logs\\error.log"), true)) { var e = (eventArgs.ExceptionObject as Exception); sw.WriteLine(DateTime.UtcNow); sw.WriteLine(e.Message); sw.WriteLine(e.StackTrace + "\n"); if (eventArgs.IsTerminating) { Environment.Exit(5); } } }; #endif //get the version of the bot and set the window title Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; Console.Title = $"Werewolf Moderator {version}"; //Make sure another instance isn't already running if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) { Environment.Exit(2); } var updateid = ""; //attempt to get id from update if (args.Length > 0) { updateid = args[0]; } //initialize analytics #if BETA || DEBUG var aToken = Config.Config.GetBotApiKey(); #else var aToken = Helpers.RegHelper.GetRegValue("BotanReleaseAPI"); #endif Analytics = new BotanIO.Api.Botan(aToken); XsollaLink = Helpers.RegHelper.GetRegValue("XsollaLink"); XsollaApiId = Helpers.RegHelper.GetRegValue("XsollaApiId"); XsollaApiKey = Helpers.RegHelper.GetRegValue("XsollaApiKey"); try { xsollaProjId = int.Parse(Helpers.RegHelper.GetRegValue("XsollaProjId")); } catch { xsollaProjId = 0; } xsollaClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{XsollaApiId}:{XsollaApiKey}"))); //Initialize the TCP connections TCP.Initialize(); //Let the nodes reconnect Thread.Sleep(1000); //initialize EF before we start receiving using (var db = new WWContext()) { var count = db.GlobalBans.Count(); } //start up the bot new Thread(() => Bot.Initialize(updateid)).Start(); new Thread(NodeMonitor).Start(); //new Thread(CpuMonitor).Start(); new Thread(UpdateHandler.SpamDetection).Start(); new Thread(UpdateHandler.BanMonitor).Start(); //new Thread(MessageMonitor).Start(); _timer = new System.Timers.Timer(); _timer.Elapsed += new ElapsedEventHandler(TimerOnTick); _timer.Interval = 1000; _timer.Enabled = true; //now pause the main thread to let everything else run Thread.Sleep(-1); }
//internal static BotanIO.Api.Botan Analytics; static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { //drop the error to log file and exit using (var sw = new StreamWriter(Path.Combine(Bot.RootDirectory, "..\\Logs\\error.log"), true)) { var e = (eventArgs.ExceptionObject as Exception); sw.WriteLine(DateTime.UtcNow); sw.WriteLine(e.Message); sw.WriteLine(e.StackTrace + "\n"); if (eventArgs.IsTerminating) { Environment.Exit(5); } } }; //get the version of the bot and set the window title Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; Console.Title = $"Werewolf Moderator {version}"; //Make sure another instance isn't already running if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) { Environment.Exit(2); } var updateid = ""; //attempt to get id from update if (args.Length > 0) { updateid = args[0]; } //initialize analytics #if BETA || DEBUG //var aToken = Helpers.RegHelper.GetRegValue("BotanBetaAPI"); #else //var aToken = Helpers.RegHelper.GetRegValue("BotanReleaseAPI"); #endif //Analytics = new BotanIO.Api.Botan(aToken); //Initialize the TCP connections TCP.Initialize(); //Let the nodes reconnect Thread.Sleep(1000); //initialize EF before we start receiving using (var db = new WWContext()) { var count = db.GlobalBans.Count(); } //start up the bot new Thread(() => Bot.Initialize(updateid)).Start(); new Thread(NodeMonitor).Start(); /* //new Thread(CpuMonitor).Start(); * new Thread(UpdateHandler.SpamDetection).Start(); * new Thread(UpdateHandler.BanMonitor).Start(); * //new Thread(MessageMonitor).Start(); * _timer = new System.Timers.Timer(); * _timer.Elapsed += new ElapsedEventHandler(TimerOnTick); * _timer.Interval = 1000; * _timer.Enabled = true;*/ var nodecount = 1; while (true) { if (Bot.Nodes.Count(x => !x.ShuttingDown) < nodecount) { NewNode(); Thread.Sleep(5000); } else if (Bot.Nodes.Count(x => !x.ShuttingDown) > nodecount) { Bot.Nodes?.FirstOrDefault(x => x.Games.Count == 0)?.ShutDown(true); } Thread.Sleep(2000); } //now pause the main thread to let everything else run Thread.Sleep(-1); }