/// <summary> /// Stops logging chat. /// </summary> public void StopLogging() { if (ChatTimer != null) { ChatTimer.Dispose(); ChatTimer = null; } Disconnect(); }
static void Main(string[] args) { DisableConsoleQuickEdit.Go(); Authenticator = new WebAuthenticator(); Settings = new ApplicationSettings(); if (!Settings.Exists()) { FirstTimeSetup(); } Settings = Settings.Load(); GlobalVariables.AppSettings = Settings; ConsoleHelper.WriteLine("Grabbing credentials from database..."); ChatBot = new TwitchChatBot(Authenticator, Settings.AppState, Settings); ConsoleHelper.WriteLine("Connecting to Twitch..."); ChatBot.Start(); ConsoleHelper.WriteLine("Loading chat timers..."); MsgTimer = new ChatTimer(ChatBot, 900000); if (MsgTimer.Count() > 1) { ConsoleHelper.WriteLine($"{MsgTimer.Count()} timers loaded."); } GlobalVariables.GlobalPlaylist.OnSongChanged += OnPlaylistSongChanged; if (Settings.PlaylistLocation != null && Directory.Exists(Settings.PlaylistLocation)) { ConsoleHelper.WriteLine("Loading the playlist..."); GlobalVariables.GlobalPlaylist.LoadFromFolder(Settings.PlaylistLocation); GlobalVariables.GlobalPlaylist.Shuffle(); GlobalVariables.GlobalPlaylist.Play(); } object locker = new object(); List <char> charBuffer = new List <char>(); while (ChatBot.IsConnected) { var key = ConsoleHelper.ReadKey(); } ConsoleHelper.WriteLine("Press any key to exit..."); System.Console.ReadKey(true); }
private void OnChatTimer() { DateTime Now = DateTime.Now; if (LastLogCheck.Day != Now.Day) { LastLogCheck = Now; IsReconnectionRequired = true; } else if (FolderCheck.Elapsed >= FolderCheckTimeout) { string OldSelected = SelectedLogFolder; SelectFolder(); if (OldSelected != SelectedLogFolder) { IsStarting = true; FolderCheck.Stop(); IsReconnectionRequired = true; } else { FolderCheck.Restart(); } } if (IsReconnectionRequired) { IsReconnectionRequired = false; Disconnect(); } if (LogStream == null) { SelectFolder(); TryConnecting(); } if (LogStream != null) { ParseChat(); } ChatTimer?.Change(PollDelay, Timeout.InfiniteTimeSpan); }
public static void Shutdown([NotNull] ShutdownParams shutdownParams, bool waitForShutdown) { if (shutdownParams == null) throw new ArgumentNullException("shutdownParams"); lock (ShutdownLock) { if (!CancelShutdown()) return; shutdownThread = new Thread(ShutdownThread) { Name = "SpACraft.Shutdown" }; if (shutdownParams.Delay >= ChatTimer.MinDuration) { string timerMsg = String.Format("Server {0} ({1})", shutdownParams.Restart ? "restart" : "shutdown", shutdownParams.ReasonString); string nameOnTimer; if (shutdownParams.InitiatedBy == null) { nameOnTimer = Player.Console.Name; } else { nameOnTimer = shutdownParams.InitiatedBy.Name; } shutdownTimer = ChatTimer.Start(shutdownParams.Delay, timerMsg, nameOnTimer); } shutdownThread.Start(shutdownParams); } if (waitForShutdown) { ShutdownWaiter.WaitOne(); } }
public static bool CancelShutdown() { lock (ShutdownLock) { if (shutdownThread != null) { if (IsShuttingDown || shutdownThread.ThreadState != ThreadState.WaitSleepJoin) { return false; } if (shutdownTimer != null) { shutdownTimer.Stop(); shutdownTimer = null; } ShutdownWaiter.Set(); shutdownThread.Abort(); shutdownThread = null; } } return true; }