internal DccSend(IrcFeatures irc, IPAddress externalIpAdress, CtcpEventArgs e) { /* Remote Request */ Irc = irc; directionUp = false; User = e.Data.Nick; if (e.Data.MessageArray.Length > 4) { long ip, filesize = 0; int port = 0; bool okIP = long.TryParse(e.Data.MessageArray[3], out ip); bool okPo = int.TryParse(e.Data.MessageArray[4], out port); // port 0 = passive if (e.Data.MessageArray.Length > 5) { bool okFs = long.TryParse(FilterMarker(e.Data.MessageArray[5]), out filesize); this.filesize = filesize; filename = e.Data.MessageArray[2].Trim(new[] { '\"' }); } if (okIP && okPo) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); DccSendRequestEvent(new DccSendRequestEventArgs(this, e.Data.MessageArray[2], filesize)); return; } irc.SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG DCC Send Parameter Error"); } else { irc.SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG DCC Send not enough parameters"); } }
/// <summary> /// Constructor of a DCC Chat for a Incoming DCC Chat Request /// </summary> /// <param name="irc">IrcFeature Class</param> /// <param name="externalIpAdress">Our externally reachable IP Adress</param> /// <param name="e">The Ctcp Event which initiated this constructor</param> internal DccChat(IrcFeatures irc, IPAddress externalIpAdress, CtcpEventArgs e) { Irc = irc; ExternalIPAdress = externalIpAdress; User = e.Data.Nick; if (e.Data.MessageArray.Length > 4) { long ip; bool okIP = long.TryParse(e.Data.MessageArray[3], out ip); int port; bool okPort = int.TryParse(FilterMarker(e.Data.MessageArray[4]), out port); // port 0 = passive if ((e.Data.MessageArray[2] == "chat") && okIP && okPort) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); if (e.Data.MessageArray.Length > 5 && e.Data.MessageArray[5] != "T") { AcceptRequest(); // Since we initated the Request, we accept DCC return; // No OnDccChatRequestEvent Event! (we know that we want a connection) } DccChatRequestEvent(new DccEventArgs(this)); return; } irc.SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG DCC Chat Parameter Error"); } else { irc.SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG DCC Chat not enough parameters"); } IsValid = false; }
internal bool TryAccept(CtcpEventArgs e) { if (User == e.Data.Nick) { if ((e.Data.MessageArray.Length > 4) && (filename == e.Data.MessageArray[2].Trim(new[] { '\"' }))) { return AcceptRequest(null, 0); } } return false; }
internal bool SetRemote(CtcpEventArgs e) { long ip; int port; bool okIP = long.TryParse(e.Data.MessageArray[3], out ip); bool okPo = int.TryParse(e.Data.MessageArray[4], out port); // port 0 = passive if (okIP && okPo) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); return true; } return false; }
private void CtcpVersionDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "VERSION " + (CtcpVersion ?? VersionString)); }
private void CtcpUserInfoDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "USERINFO " + (CtcpUserInfo ?? "No user info given.")); }
private void CtcpClientInfoDelegate(CtcpEventArgs e) { string clientInfo = ctcpDelegates.Aggregate("CLIENTINFO", (current, kvp) => current + " " + kvp.Key.ToUpper()); SendMessage(SendType.CtcpReply, e.Data.Nick, clientInfo); }
internal void HandleOnCtcpReply(object sender, CtcpEventArgs e) { if (OnCtcpReply != null) OnCtcpReply(this, e); }
private void CtcpSourceDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "SOURCE " + (CtcpSource ?? "https://github.com/FreeApophis/sharpIRC")); }
/// <summary> /// This is the correct Rfc Ping Delegate, which is not used because all other clients do not use the PING According to RfC /// </summary> /// <param name="e"></param> private void CtcpRfcPingDelegate(CtcpEventArgs e) { if (e.Data.Message.Length > 7) { SendMessage(SendType.CtcpReply, e.Data.Nick, "PONG " + e.Data.Message.Substring(6, (e.Data.Message.Length - 7))); } else { SendMessage(SendType.CtcpReply, e.Data.Nick, "PONG"); } }
private void CtcpRequestsHandler(object sender, CtcpEventArgs e) { if (ctcpDelegates.ContainsKey(e.CtcpCommand)) { ctcpDelegates[e.CtcpCommand].Invoke(e); } RemoveInvalidDccConnections(); }
private void CtcpPingDelegate(CtcpEventArgs e) { if (e.Data.Message.Length > 7) { SendMessage(SendType.CtcpReply, e.Data.Nick, "PING " + e.Data.Message.Substring(6, (e.Data.Message.Length - 7))); } else { SendMessage(SendType.CtcpReply, e.Data.Nick, "PING"); //according to RFC, it should be PONG! } }
private void CtcpFingerDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "FINGER Don't touch little Helga there! "); //SendMessage(SendType.CtcpReply, e.Data.Nick, "FINGER " + this.Realname + " (" + this.Email + ") Idle " + this.Idle + " seconds (" + ((string.IsNullOrEmpty(this.Reason)) ? this.Reason : "-") + ") "); }
private void CtcpDccDelegate(CtcpEventArgs e) { if (e.Data.MessageArray.Length < 2) { SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG DCC missing parameters"); } else { switch (e.Data.MessageArray[1]) { case "CHAT": var chat = new DccChat(this, ExternalIpAdress, e); dccConnections.Add(chat); ThreadPool.QueueUserWorkItem(chat.InitWork); break; case "SEND": if (e.Data.MessageArray.Length > 6 && (FilterMarker(e.Data.MessageArray[6]) != "T")) { long session; long.TryParse(FilterMarker(e.Data.MessageArray[6]), out session); foreach (DccConnection dc in dccConnections) { if (dc.IsSession(session)) { ((DccSend)dc).SetRemote(e); ((DccSend)dc).AcceptRequest(null, 0); return; } } SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG Invalid passive DCC"); } else { var send = new DccSend(this, ExternalIpAdress, e); dccConnections.Add(send); ThreadPool.QueueUserWorkItem(send.InitWork); } break; case "RESUME": if (dccConnections.Any(dc => (dc is DccSend) && (((DccSend)dc).TryResume(e)))) { return; } SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG Invalid DCC RESUME"); break; case "ACCEPT": if (dccConnections.Any(dc => (dc is DccSend) && (((DccSend)dc).TryAccept(e)))) { return; } SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG Invalid DCC ACCEPT"); break; case "XMIT": SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG DCC XMIT not implemented"); break; default: SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG DCC " + e.CtcpParameter + " unavailable"); break; } } }
internal bool TryResume(CtcpEventArgs e) { if (User == e.Data.Nick) { if ((e.Data.MessageArray.Length > 4) && (filename == e.Data.MessageArray[2].Trim(new[] { '\"' }))) { long offset; long.TryParse(FilterMarker(e.Data.MessageArray[4]), out offset); if (file.CanSeek) { if (e.Data.MessageArray.Length > 5) { Irc.SendMessage(SendType.CtcpRequest, e.Data.Nick, "DCC ACCEPT " + e.Data.MessageArray[2] + " " + e.Data.MessageArray[3] + " " + e.Data.MessageArray[4] + " " + FilterMarker(e.Data.MessageArray[5])); } else { Irc.SendMessage(SendType.CtcpRequest, e.Data.Nick, "DCC ACCEPT " + e.Data.MessageArray[2] + " " + e.Data.MessageArray[3] + " " + FilterMarker(e.Data.MessageArray[4])); } file.Seek(offset, SeekOrigin.Begin); sentBytes = offset; return true; } Irc.SendMessage(SendType.CtcpRequest, e.Data.Nick, "ERRMSG DCC File not seekable"); } } return false; }
private void CtcpTimeDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "TIME " + DateTime.Now.ToString("r")); }
private void CtcpUrlDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "URL " + (CtcpUrl ?? "http://www.google.com")); }
internal void HandleOnCtcpRequest(object sender, CtcpEventArgs e) { if (OnCtcpRequest != null) OnCtcpRequest(this, e); }
public void PluginsOnCtcpRequest(object sender, CtcpEventArgs e) { OnCtcpRequest(this, e); }