/// <summary> /// Exception handler /// </summary> /// <param name="ex">Exception pointer</param> public static void HandleException(Exception ex) { try { if (!string.IsNullOrEmpty(Configuration.System.DebugChan)) { IRC.DeliverMessage("DEBUG Exception: " + ex.Message + " st: " + ex.StackTrace.Replace(Environment.NewLine, ""), Configuration.System.DebugChan); } if (ex.InnerException != null) { Syslog.ErrorLog("DEBUG Exception: " + ex.Message + ex.Source + ex.StackTrace + "\n\nThread name: " + Thread.CurrentThread.Name + "\n\nInner: " + ex.InnerException); } else { Syslog.ErrorLog("DEBUG Exception: " + ex.Message + ex.Source + ex.StackTrace + "\n\nThread name: " + Thread.CurrentThread.Name); } } catch (Exception fail) { // exception happened while we tried to handle another one, ignore that (probably issue with logging) Console.WriteLine(fail.ToString()); } }
private void Exec() { while (this.IsActive && Core.IsRunning) { try { this.Disconnect(); this.Connect(); while (!this.IsWorking && !this.Protocol.IsDisconnected) { // we need to wait for the irc handler to connect to irc Thread.Sleep(100); } // now we can finally join all channels Join(); // then we just sleep while (this.Network.IsConnected) { Thread.Sleep(2000); } // in case we got disconnected, we log it and restart the procedure Syslog.WarningLog("Disconnected from irc network on " + Nick); Thread.Sleep(20000); } catch (ThreadAbortException) { Syslog.DebugLog("Terminated primary thread for instance " + Nick); return; } catch (IOException fail) { if (this.IsActive) { Syslog.ErrorLog("Failure of primary thread of instance " + Nick + " attempting to recover"); Core.HandleException(fail); } else { return; } } catch (Exception fail) { Core.HandleException(fail); if (this.IsActive) { Syslog.ErrorLog("Failure of primary thread of instance " + Nick + " attempting to recover"); } else { return; } Thread.Sleep(20000); } } Core.ThreadManager.UnregisterThread(Thread.CurrentThread); }
private void Exec() { try { Thread.Sleep(8000); if (unwritten.PendingRows.Count == 0 && File.Exists(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml")) { File.Delete(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml"); } while (Core.IsRunning) { if (unwritten.PendingRows.Count > 0) { int count; Syslog.WarningLog("Performing recovery of " + unwritten.PendingRows.Count + " MySQL rows"); Recovering = true; List <SerializedRow> rows = new List <SerializedRow>(); lock (unwritten.PendingRows) { count = unwritten.PendingRows.Count; rows.AddRange(unwritten.PendingRows); unwritten.PendingRows.Clear(); } int recovered = 0; foreach (SerializedRow row in rows) { if (InsertRow(row.table, row.row)) { recovered++; } else { Syslog.DebugLog("Failed to recover 1 row", 2); } } Syslog.WarningLog("Recovery finished, recovered " + recovered + " of total " + count); Recovering = false; FlushRows(); Thread.Sleep(200000); if (unwritten.PendingRows.Count == 0 && File.Exists(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml")) { File.Delete(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + "unwrittensql.xml"); } } Thread.Sleep(200); } } catch (Exception fail) { Core.HandleException(fail); Syslog.ErrorLog("Recovery thread for Mysql is down"); } }
/// <summary> /// Part a channel /// </summary> /// <param name="channel">Channel object</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> /// <param name="origin">The channel from which this request was sent</param> public static void PartChannel(Channel channel, string user, string host, string message, string origin = "NULL") { try { if (origin == "NULL") { origin = channel.Name; } if (channel.Name == Configuration.System.DebugChan && (message == Configuration.System.CommandPrefix + "part" || message == Configuration.System.CommandPrefix + "drop")) { IRC.DeliverMessage("Cowardly refusing to part this channel, because I love it :3", channel); return; } if (message == Configuration.System.CommandPrefix + "drop") { if (channel.SystemUsers.IsApproved(user, host, "drop")) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.Network.Transfer("PART " + channel.Name + " :" + "dropped by " + user + " from " + origin); Syslog.Log("Dropped " + channel.Name + " dropped by " + user + " from " + origin); Thread.Sleep(100); try { File.Delete(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + channel.Name + ".xml"); } catch (Exception fail) { Syslog.ErrorLog("Failed to delete configuration file of " + channel.Name); Core.HandleException(fail); } foreach (Module module in ExtensionHandler.ExtensionList) { try { if (module.IsWorking) { module.Hook_ChannelDrop(channel); } } catch (Exception fail) { Syslog.Log("MODULE: exception at Hook_ChannelDrop in " + module.Name, true); Core.HandleException(fail, module.Name); } } lock (Configuration.Channels) { channel.Remove(); } Configuration.Save(); return; } IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); return; } if (message == Configuration.System.CommandPrefix + "part") { if (channel.SystemUsers.IsApproved(user, host, "part")) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.Network.Transfer("PART " + channel.Name + " :" + "removed by " + user + " from " + origin); Syslog.Log("Removed " + channel.Name + " removed by " + user + " from " + origin); Thread.Sleep(100); lock (Configuration.Channels) { channel.Remove(); } channel.SaveConfig(); Configuration.Save(); return; } IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); } } catch (Exception fail) { Core.HandleException(fail); } }
public void ErrorLog(string text) { Syslog.ErrorLog(Name + ": " + text); }