void ServerConnect(Server aServer) { if (!aServer.Enabled) { _log.Error("ServerConnect(" + aServer + ") is not enabled"); return; } IrcConnection connection = _connections.SingleOrDefault(c => c.Server == aServer); if (connection == null) { _log.Info("ServerConnect(" + aServer + ")"); connection = new IrcConnection { Server = aServer, Parser = _parser, Scheduler = Scheduler }; _connections.Add(connection); connection.OnDisconnected += ServerDisconnected; connection.OnNotificationAdded += AddNotification; connection.Start(aServer.ToString()); } else { _log.Error("ServerConnect(" + aServer + ") is already in the list"); } }
void ServerDisconnect(Server aServer) { IrcConnection connection = _connections.SingleOrDefault(c => c.Server == aServer); if (connection != null) { _log.Info("ServerDisconnect(" + aServer + ")"); connection.Disconnect(); } else { _log.Error("ServerDisconnect(" + aServer + ") is not in the list"); } }
void BotDisconnected(object aSender, EventArgs <Packet> aEventArgs) { var download = _botDownloads.SingleOrDefault(c => c.Packet == aEventArgs.Value1); if (download != null) { download.Packet = null; download.OnDisconnected -= BotDisconnected; download.OnNotificationAdded -= AddNotification; _botDownloads.Remove(download); if (!AllowRunning) { return; } try { // if the connection never connected, there will be no file // and if we manually stopped the packet there will be file also // the missing size is negative?! if (download.File != null && download.File.MissingSize <= 0) { // do this here because the bothandler sets the file state FileActions.FinishFile(download.File); } } catch (Exception ex) { _log.Fatal("BotDisconnected()", ex); } try { IrcConnection connection = _connections.SingleOrDefault(c => c.Server == aEventArgs.Value1.Parent.Parent.Parent); if (connection != null) { connection.AddBotToQueue(aEventArgs.Value1.Parent, Settings.Default.CommandWaitTime); } } catch (Exception ex) { _log.Fatal("BotDisconnected() request", ex); } } }
void BotConnect(object aSender, EventArgs <Packet, Int64, IPAddress, int> aEventArgs) { int currentDownloadCount = (from file in Files.All where file.Connected select file).Count(); if (Settings.Default.MaxDownloads > 0 && currentDownloadCount >= Settings.Default.MaxDownloads) { _log.Error("BotConnect(" + aEventArgs.Value1 + ") skipping, because already " + Settings.Default.MaxDownloads + " packets are downloading"); IrcConnection connection = _connections.SingleOrDefault(c => c.Server == aEventArgs.Value1.Parent.Parent.Parent); if (connection != null) { connection.AddBotToQueue(aEventArgs.Value1.Parent, Settings.Default.BotWaitTime); } return; } var download = _botDownloads.SingleOrDefault(c => c.Packet == aEventArgs.Value1); if (download == null) { download = new BotDownload { Files = Files, Packet = aEventArgs.Value1, StartSize = aEventArgs.Value2, IP = aEventArgs.Value3, Port = aEventArgs.Value4, MaxData = aEventArgs.Value1.RealSize - aEventArgs.Value2, Scheduler = Scheduler }; download.OnDisconnected += BotDisconnected; download.OnNotificationAdded += AddNotification; _botDownloads.Add(download); download.Start(aEventArgs.Value3 + ":" + aEventArgs.Value4); } else { // uhh - that should not happen _log.Error("BotConnect(" + aEventArgs.Value1 + ") is already downloading"); } }
void ServerDisconnected(object aSender, EventArgs <Server> aEventArgs) { IrcConnection connection = _connections.SingleOrDefault(c => c.Server == aEventArgs.Value1); if (connection != null) { _log.Info("ServerDisconnected(" + aEventArgs.Value1 + ")"); connection.OnDisconnected -= ServerDisconnected; connection.OnNotificationAdded -= AddNotification; connection.Server = null; connection.Parser = null; _connections.Remove(connection); if (AllowRunning && aEventArgs.Value1.Enabled) { // if the lifetime of a connection was to low, we should sleep some time before try connecting again if (connection.TimeConnected < 10) { _log.Info("ServerReconnect(" + aEventArgs.Value1 + ") in " + Settings.Default.CommandWaitTime + " seconds"); AddFutureJob(typeof(Job.ServerConnect), "ServerConnect." + aEventArgs.Value1, "IrcPlugin", Settings.Default.CommandWaitTime, new JobItem("Server", aEventArgs.Value1), new JobItem("Plugin", this)); } else { _log.Info("ServerReconnect(" + aEventArgs.Value1 + ")"); ServerConnect(aEventArgs.Value1); } } } else { _log.Error("ServerDisconnected(" + aEventArgs.Value1 + ") is not in the list"); } }