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; }
/// <summary> /// Constructor of DCC CHat for local DCC Chat Request to a certain user. /// </summary> /// <param name="irc">IrcFeature Class</param> /// <param name="user">Chat Destination (channels are no valid targets)</param> /// <param name="externalIpAdress">Our externally reachable IP Adress (can be anything if passive)</param> /// <param name="passive">if you have no reachable ports!</param> /// <param name="priority">Non DCC Message Priority</param> internal DccChat(IrcFeatures irc, string user, IPAddress externalIpAdress, bool passive, Priority priority) { Irc = irc; ExternalIPAdress = externalIpAdress; User = user; if (passive) { irc.SendMessage(SendType.CtcpRequest, user, "DCC CHAT chat " + HostToDccInt(externalIpAdress) + " 0 " + SessionID, priority); Disconnect(); } else { DccServer = new TcpListener(new IPEndPoint(IPAddress.Any, 0)); DccServer.Start(); LocalEndPoint = (IPEndPoint)DccServer.LocalEndpoint; irc.SendMessage(SendType.CtcpRequest, user, "DCC CHAT chat " + HostToDccInt(externalIpAdress) + " " + LocalEndPoint.Port, priority); } }
internal DccSend(IrcFeatures irc, string user, IPAddress externalIpAdress, Stream file, string filename, long filesize, DccSpeed speed, bool passive, Priority priority) { Irc = irc; directionUp = true; this.file = file; this.filesize = filesize; this.filename = filename; this.speed = speed; User = user; if (passive) { irc.SendMessage(SendType.CtcpRequest, user, "DCC SEND \"" + filename + "\" " + HostToDccInt(externalIpAdress) + " 0 " + filesize + " " + SessionID, priority); } else { DccServer = new TcpListener(new IPEndPoint(IPAddress.Any, 0)); DccServer.Start(); LocalEndPoint = (IPEndPoint)DccServer.LocalEndpoint; irc.SendMessage(SendType.CtcpRequest, user, "DCC SEND \"" + filename + "\" " + HostToDccInt(externalIpAdress) + " " + LocalEndPoint.Port + " " + filesize, priority); } }