static void Main(string[] args) { //set up exception logging. It appears nodes are crashing and I'm not getting any output AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { var ex = eventArgs.ExceptionObject as Exception; using (var sw = new StreamWriter(Path.Combine(RootDirectory, "..\\Logs\\NodeFatalError.log"), true)) { sw.WriteLine($"{DateTime.Now} - {Version} - {ex.Message}"); sw.WriteLine(ex.StackTrace); while (ex.InnerException != null) { ex = ex.InnerException; sw.WriteLine($"{ex.Message}"); sw.WriteLine(ex.StackTrace); } sw.WriteLine("--------------------------------------------------------"); } }; English = XDocument.Load(Path.Combine(LanguageDirectory, "English.xml")); //get api token from registry var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) .OpenSubKey("SOFTWARE\\Werewolf"); #if BETA || DEBUG var aToken = key.GetValue("BotanBetaAPI").ToString(); #else var aToken = key.GetValue("BotanReleaseAPI").ToString(); #endif Analytics = new BotanIO.Api.Botan(aToken); #if DEBUG APIToken = key.GetValue("DebugAPI").ToString(); #elif RELEASE APIToken = key.GetValue("ProductionAPI").ToString(); #elif RELEASE2 APIToken = key.GetValue("ProductionAPI2").ToString(); #elif BETA APIToken = key.GetValue("BetaAPI").ToString(); #endif Bot = new TelegramBotClient(APIToken); Me = Bot.GetMeAsync().Result; do { ClientId = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 22); // Since a GUID is always 128 bits, we can omit the "==" that we know will always be present at the end }while (!ClientId.All(x => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".Contains(x))); new Thread(KeepAlive).Start(); Console.Title = $"{ClientId} - {Version.FileVersion}"; Thread.Sleep(-1); }
static void Main(string[] args) { //set up exception logging. It appears nodes are crashing and I'm not getting any output AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { var ex = eventArgs.ExceptionObject as Exception; using (var sw = new StreamWriter(Path.Combine(RootDirectory, "..\\Logs\\NodeFatalError.log"), true)) { sw.WriteLine($"{DateTime.Now} - {Version} - {ex.Message}"); sw.WriteLine(ex.StackTrace); while (ex.InnerException != null) { ex = ex.InnerException; sw.WriteLine($"{ex.Message}"); sw.WriteLine(ex.StackTrace); } sw.WriteLine("--------------------------------------------------------"); } }; English = XDocument.Load(Path.Combine(LanguageDirectory, "English.xml")); //get api token from registry var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) .OpenSubKey("SOFTWARE\\Werewolf"); #if BETA || DEBUG var aToken = key.GetValue("BotanBetaAPI").ToString(); #else var aToken = key.GetValue("BotanReleaseAPI").ToString(); #endif Analytics = new BotanIO.Api.Botan(aToken); #if DEBUG APIToken = key.GetValue("DebugAPI").ToString(); #elif RELEASE APIToken = key.GetValue("ProductionAPI").ToString(); #elif RELEASE2 APIToken = key.GetValue("ProductionAPI2").ToString(); #elif BETA APIToken = key.GetValue("BetaAPI").ToString(); #endif Bot = new TelegramBotClient(APIToken); Me = Bot.GetMeAsync().Result; ClientId = Guid.NewGuid(); new Thread(KeepAlive).Start(); Console.Title = $"{ClientId} - {Version.FileVersion}"; 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); }