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": DccChat chat = new DccChat(this, _ExternalIpAdress, e); _DccConnections.Add(chat); ThreadPool.QueueUserWorkItem(new WaitCallback(chat.InitWork)); break; case "SEND": if (e.Data.MessageArray.Length > 6 && (FilterMarker(e.Data.MessageArray[6]) != "T")) { long session = -1; 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 { DccSend send = new DccSend(this, _ExternalIpAdress, e); _DccConnections.Add(send); ThreadPool.QueueUserWorkItem(new WaitCallback(send.InitWork)); } break; case "RESUME": foreach(DccConnection dc in _DccConnections) { if((dc is DccSend) && (((DccSend)dc).TryResume(e))) { return; } } SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG Invalid DCC RESUME"); break; case "ACCEPT": foreach(DccConnection dc in _DccConnections) { if((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 char[] { '\"' }))) { long offset = 0; 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); } else { Irc.SendMessage(SendType.CtcpRequest, e.Data.Nick, "ERRMSG DCC File not seekable"); } } } return(false); }
/// <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) { bool okIP = Int64.TryParse(e.Data.MessageArray[3], out long ip); bool okPo = Int32.TryParse(FilterMarker(e.Data.MessageArray[4]), out int port); // port 0 = passive if ((e.Data.MessageArray[2] == "chat") && okIP && okPo) { 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; } else { 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 DccSend(IrcFeatures irc, IPAddress externalIpAdress, CtcpEventArgs e) { /* Remote Request */ Irc = irc; _DirectionUp = false; User = e.Data.Nick; if (e.Data.MessageArray.Length > 4) { long filesize = 0; if (e.Data.MessageArray.Length > 5) { bool okFs = Int64.TryParse(FilterMarker(e.Data.MessageArray[5]), out filesize); _Filesize = filesize; _Filename = e.Data.MessageArray[2].Trim('"'); } if (Int64.TryParse(e.Data.MessageArray[3], out long ip) && Int32.TryParse(e.Data.MessageArray[4], out int port)) // port 0 = passive { 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) : base () { this.Irc = irc; this.ExternalIPAdress = externalIpAdress; this.User = e.Data.Nick; long ip; int port; if (e.Data.MessageArray.Length > 4) { bool okIP = long.TryParse(e.Data.MessageArray[3], out ip); bool okPo = int.TryParse(FilterMarker(e.Data.MessageArray[4]), out port); // port 0 = passive if((e.Data.MessageArray[2]=="chat") && okIP && okPo) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); if (e.Data.MessageArray.Length > 5 && e.Data.MessageArray[5] != "T") { this.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; } else { 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"); } this.isValid = false; }
internal DccSend(IrcFeatures irc, IPAddress externalIpAdress, CtcpEventArgs e) : base() { /* Remote Request */ this.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); _Filesize = filesize; _Filename = e.Data.MessageArray[2].Trim(new char[] {'\"'}); } if (okIP && okPo) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); DccSendRequestEvent(new DccSendRequestEventArgs(this, e.Data.MessageArray[2], filesize)); return; } else { 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"); } }
internal DccSend(IrcFeatures irc, IPAddress externalIpAdress, CtcpEventArgs e) : base() { /* Remote Request */ this.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); _Filesize = filesize; _Filename = e.Data.MessageArray[2].Trim(new char[] { '\"' }); } if (okIP && okPo) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); DccSendRequestEvent(new DccSendRequestEventArgs(this, e.Data.MessageArray[2], filesize)); return; } else { 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"); } }
private void CtcpClientInfoDelegate(CtcpEventArgs e) { string clientInfo = "CLIENTINFO"; foreach (KeyValuePair <string, CtcpDelegate> kvp in _CtcpDelegates) { clientInfo = clientInfo + " " + kvp.Key.ToUpper(); } SendMessage(SendType.CtcpReply, e.Data.Nick, clientInfo); }
internal bool SetRemote(CtcpEventArgs e) { // port 0 = passive if (Int64.TryParse(e.Data.MessageArray[3], out long ip) && Int32.TryParse(e.Data.MessageArray[4], out int port)) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); return(true); } return(false); }
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! } }
/// <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"); } }
internal bool TryAccept(CtcpEventArgs e) { if (User == e.Data.Nick) { if ((e.Data.MessageArray.Length > 4) && (_Filename == e.Data.MessageArray[2].Trim(new char[] { '\"' }))) { return(this.AcceptRequest(null, 0)); } } return(false); }
private void CtcpRequestsHandler(object sender, CtcpEventArgs e) { if (_CtcpDelegates.ContainsKey(e.CtcpCommand)) { _CtcpDelegates[e.CtcpCommand].Invoke(e); } else { /* No CTCP Handler for this Command */ } RemoveInvalidDccConnections(); }
internal bool SetRemote(CtcpEventArgs e) { long ip; 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 (okIP && okPo) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); return(true); } return(false); }
public static void irc_OnCtcpRequest(object sender, CtcpEventArgs e) { switch (e.CtcpCommand) { case "VERSION": irc.SendMessage(SendType.CtcpReply, e.Data.Nick, "\rVERSION" + " Bot version: r" + Revision.bot_revision + "-trunk"); break; case "TIME": irc.SendMessage(SendType.CtcpReply, e.Data.Nick, "\rtime \r" + DateTime.Now); break; } }
void ClientOnOnCtcpReply(object sender, CtcpEventArgs ctcpEventArgs) { try{ var strTime = ctcpEventArgs.CtcpParameter; var semicolonIdx = strTime.IndexOf(':'); var timeStr = strTime.Substring(semicolonIdx - 2, 5); var hourStr = timeStr.Substring(0, 2); var hour = int.Parse(hourStr); var diff = hour - DateTime.Now.Hour; var userNick = ctcpEventArgs.Data.Nick; var userChannel = _activeCtcp.Where(usr => usr.Nick.Equals(userNick)).ToList()[0].Channel; _usersToGreet.Add(new User(userNick, userChannel, diff)); } catch (Exception e){ int g = 5; } }
private void CtcpUrlDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "URL " + ((CtcpUrl == null)?"http://www.google.com":CtcpUrl)); }
private void CtcpUserInfoDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "USERINFO " + ((CtcpUserInfo == null)?"No user info given.":CtcpUserInfo)); }
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 CtcpVersionDelegate(CtcpEventArgs e) => SendMessage(SendType.CtcpReply, e.Data.Nick, "VERSION " + (CtcpVersion ?? VersionString));
internal bool TryAccept(CtcpEventArgs e) { if (User == e.Data.Nick) { if ((e.Data.MessageArray.Length > 4) && (_Filename == e.Data.MessageArray[2].Trim(new char[] {'\"'}))) { return this.AcceptRequest(null, 0); } } return false; }
/// <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 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": DccChat chat = new DccChat(this, _ExternalIpAdress, e); _DccConnections.Add(chat); ThreadPool.QueueUserWorkItem(new WaitCallback(chat.InitWork)); break; case "SEND": if (e.Data.MessageArray.Length > 6 && (FilterMarker(e.Data.MessageArray[6]) != "T")) { long session = -1; 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 { DccSend send = new DccSend(this, _ExternalIpAdress, e); _DccConnections.Add(send); ThreadPool.QueueUserWorkItem(new WaitCallback(send.InitWork)); } break; case "RESUME": foreach (DccConnection dc in _DccConnections) { if ((dc is DccSend) && (((DccSend)dc).TryResume(e))) { return; } } SendMessage(SendType.CtcpReply, e.Data.Nick, "ERRMSG Invalid DCC RESUME"); break; case "ACCEPT": foreach (DccConnection dc in _DccConnections) { if ((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; } } }
private void _OnCtcpRequest(object sender, CtcpEventArgs e) { Session.AddTextToChat(_NetworkChat, String.Format( _("{0} [{1}] requested CTCP {2} from {3}: {4}"), e.Data.Nick, e.Data.Ident+"@"+e.Data.Host, e.CtcpCommand, _IrcClient.Nickname, e.CtcpParameter)); }
private void CtcpUserInfoDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "USERINFO " + ((CtcpUserInfo==null)?"No user info given.":CtcpUserInfo)); }
private void CtcpVersionDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "VERSION " + ((CtcpVersion==null)?VersionString:CtcpVersion)); }
private void CtcpUrlDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "URL " + ((CtcpUrl==null)?"http://www.google.com":CtcpUrl)); }
private void CtcpTimeDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "TIME " + DateTime.Now.ToString("r")); }
private void CtcpSourceDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "SOURCE " + ((CtcpSource==null)?"http://smartirc4net.meebey.net":CtcpSource)); }
private void CtcpSourceDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "SOURCE " + ((CtcpSource == null)?"http://smartirc4net.meebey.net":CtcpSource)); }
private void CtcpUserInfoDelegate(CtcpEventArgs e) => SendMessage(SendType.CtcpReply, e.Data.Nick, "USERINFO " + (CtcpUserInfo ?? "No user info given."));
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 _OnCtcpRequest(object sender, CtcpEventArgs e) { Session.AddTextToChat(_NetworkChat, String.Format( // TRANSLATOR: {0}: nickname, {1}: ident@host, // {2}: CTCP command, {3}: own nickname, {4}: CTCP parameter // example: // meebey [[email protected]] requested CTCP VERSION from meebey: _("{0} [{1}] requested CTCP {2} from {3}: {4}"), e.Data.Nick, e.Data.Ident+"@"+e.Data.Host, e.CtcpCommand, _IrcClient.Nickname, e.CtcpParameter ) ); }
private void CtcpClientInfoDelegate(CtcpEventArgs e) { string clientInfo = "CLIENTINFO"; foreach(KeyValuePair<string, CtcpDelegate> kvp in _CtcpDelegates) { clientInfo = clientInfo+" "+kvp.Key.ToUpper(); } SendMessage(SendType.CtcpReply, e.Data.Nick, clientInfo); }
private void _OnCtcpReply(object sender, CtcpEventArgs e) { ChatModel chat = GetChat(e.Data); if (chat == null) { chat = _NetworkChat; } if (e.CtcpCommand == "PING") { try { long timestamp = Int64.Parse(e.CtcpParameter); if (!(timestamp >= 0)) { return; } DateTime sent = DateTime.FromFileTime(timestamp); string duration = DateTime.Now.Subtract(sent).TotalSeconds.ToString(); Session.AddTextToChat(chat, String.Format( _("CTCP PING reply from {0}: {1} seconds"), e.Data.Nick, duration)); } catch (FormatException) { } } else { Session.AddTextToChat(chat, String.Format( _("CTCP {0} reply from {1}: {2}"), e.CtcpCommand, e.Data.Nick, e.CtcpParameter)); } }
private void CtcpSourceDelegate(CtcpEventArgs e) => SendMessage(SendType.CtcpReply, e.Data.Nick, "SOURCE " + (CtcpSource ?? "http://smartirc4net.meebey.net"));
internal bool SetRemote(CtcpEventArgs e) { long ip; 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 (okIP && okPo) { RemoteEndPoint = new IPEndPoint(IPAddress.Parse(DccIntToHost(ip)), port); return true; } return false; }
private void CtcpUrlDelegate(CtcpEventArgs e) => SendMessage(SendType.CtcpReply, e.Data.Nick, "URL " + (CtcpUrl ?? "http://www.google.com"));
internal bool TryResume(CtcpEventArgs e) { if (User == e.Data.Nick) { if ((e.Data.MessageArray.Length > 4) && (_Filename == e.Data.MessageArray[2].Trim(new char[] {'\"'}))) { long offset = 0; 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; } else { Irc.SendMessage(SendType.CtcpRequest, e.Data.Nick, "ERRMSG DCC File not seekable"); } } } return false; }
internal bool TryAccept(CtcpEventArgs e) => User == e.Data.Nick && e.Data.MessageArray.Length > 4 && _Filename == e.Data.MessageArray[2].Trim('"') && AcceptRequest(null, 0);
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:"-") + ") " ); }
void ClientOnCtcpRequest(object sender, CtcpEventArgs e) { _events.Enqueue(new IrcEvent { Type = IrcEvent.EventType.CtcpRequest, Event = e }); _waitHandle.Set(); }
private void CtcpVersionDelegate(CtcpEventArgs e) { SendMessage(SendType.CtcpReply, e.Data.Nick, "VERSION " + ((CtcpVersion == null)?VersionString:CtcpVersion)); }