internal void FireDCCChatRequest(DCCChat newChat) { if (this.DCCChatRequested != null) { this.DCCChatRequested(this, new DCCChatRequestEventArgs(newChat)); } }
/// <summary> /// Find a DCC chat. /// </summary> /// <param name="ToFind">A DCCChat object to find.</param> /// <returns>The position of the DCCChat object.</returns> public int Find(DCCChat ToFind) { for (int x=0;x<dccs.Count;x++) if ((DCCChat) dccs[x]==ToFind) return x; throw(new ArgumentException("Item not in list.", "ToFind")); }
/// <summary> /// Find a DCC chat. /// </summary> /// <param name="ToFind">A DCCChat object to find.</param> /// <returns>The position of the DCCChat object.</returns> public int Find(DCCChat ToFind) { for (int x = 0; x < dccs.Count; x++) { if ((DCCChat)dccs[x] == ToFind) { return(x); } } throw(new ArgumentException("Item not in list.", "ToFind")); }
/// <summary> /// Request a chat to a user. /// </summary> /// <param name="Nickname">The nick name of the user to chat request.</param> /// <returns>A DCC chat.</returns> public DCCChat RequestChat(string Nickname) { if (parent.Channels.IsOnChannel(Nickname)) { throw(new Exception("Cannot DCC request channels.")); } int Port = FreePort(); DCCChat newChat = new DCCChat(base.CurrentConnection, Nickname, Port, chat); chat.AddDcc(newChat); base.CurrentConnection.SendData(String.Format("NOTICE {0} :DCC Chat ({1}){2}PRIVMSG {0} :\x01{5} CHAT chat {3} {4}\x01{2}", Nickname, parent.LocalIP.ToString(), Environment.NewLine, IRCHost(parent.LocalIP.ToString()), Port.ToString(), "DCC")); return(newChat); }
/// <summary> /// Request a chat to a user. /// </summary> /// <param name="Nickname">The nick name of the user to chat request.</param> /// <returns>A DCC chat.</returns> public DCCChat RequestChat(string Nickname) { if (parent.Channels.IsOnChannel(Nickname)) throw(new Exception("Cannot DCC request channels.")); int Port = FreePort(); DCCChat newChat = new DCCChat(base.CurrentConnection, Nickname, Port, chat); chat.AddDcc(newChat); base.CurrentConnection.SendData(String.Format("NOTICE {0} :DCC Chat ({1}){2}PRIVMSG {0} :\x01{5} CHAT chat {3} {4}\x01{2}", Nickname, parent.LocalIP.ToString(), Environment.NewLine, IRCHost(parent.LocalIP.ToString()), Port.ToString(), "DCC")); return newChat; }
internal DCCChatRequestEventArgs(DCCChat __newchat) { _newchat = __newchat; }
private void ParseCTCP(UserInfo user, MessageReciever Target, string CTCPData, bool blNotice) { CTCPData = CTCPData.Trim(); string strCommand = ""; string strParams = ""; if (CTCPData.IndexOf(" ")>-1) { strCommand = CTCPData.Substring(0, CTCPData.IndexOf(" ")); strParams = CTCPData.Substring(CTCPData.IndexOf(" ") + 1, CTCPData.Length - (CTCPData.IndexOf(" ") + 1)); } else strCommand = CTCPData; if (!blNotice) { #region CtCp Requests switch (strCommand.ToLower()) { case "ping": base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01PING " + strParams + "\x01", false); break; case "version": string clientInfo = "TNets IRC Library v.0.7"; if (this.CtCpVersionNeedsClientInfo != null) clientInfo = this.CtCpVersionNeedsClientInfo(this, new EventArgs()); base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01VERSION " + clientInfo + "\x01", false); break; case "finger": TimeSpan time = (TimeSpan) DateTime.Now.Subtract(base.CurrentConnection.LastActive); string strReadable = ""; #region Calculate readable idle time if (time.TotalSeconds>60) { string strHours = ""; string strMinutes = ""; string strSeconds = ""; if (time.Hours>0) { if (time.Hours>1) strHours = time.Hours.ToString() + " hours "; else strHours = time.Hours.ToString() + " hour "; } if (time.Minutes>0) { if (time.Minutes>1) strMinutes = time.Minutes.ToString() + " minutes "; else strMinutes = time.Minutes.ToString() + " minute "; } if (time.Seconds>0) { if (time.Seconds>1) strSeconds = time.Seconds.ToString() + " seconds "; else strSeconds = time.Seconds.ToString() + " second "; } strReadable = strHours + strMinutes + strSeconds; strReadable = " (" + strReadable.Trim() + ")"; } #endregion base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01" + "FINGER Idle " + Math.Floor(time.TotalSeconds).ToString() + " seconds" + strReadable + "\x01", false); break; case "time": base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01TIME " + mIRCDateTime(DateTime.Now) + "\x01", false); break; case "action": Target.FireRecievedMessage(users.GetUser(user), strParams, true); break; case "dcc": if (Target.GetType() == typeof(User)) { User userTarget = (User) Target; string[] strDccParams = strParams.Split(new char[] {' '}); if (strDccParams.Length>=4) { switch (strDccParams[0].ToLower()) { case "chat": DCCChat newChat = new DCCChat(base.CurrentConnection, long.Parse(strDccParams[2]), int.Parse(strDccParams[3]), user.Nick, dcc.Chats); dcc.Chats.AddDcc(newChat); userTarget.FireDCCChatRequest(newChat); break; case "send": DCCTransfer newTransfer = new DCCTransfer(base.CurrentConnection, long.Parse(strDccParams[2]), int.Parse(strDccParams[3]), user.Nick, strDccParams[1], long.Parse(strDccParams[4]), dcc.Transfer); dcc.Transfer.AddDcc(newTransfer); userTarget.FireDCCTransferRequest(newTransfer); break; case "accept": for (int x=0;x<dcc.Transfer.Count;x++) { if (dcc.Transfer[x].Identifier==int.Parse(strDccParams[2])) { dcc.Transfer[x].ResumeAccepted(long.Parse(strDccParams[3])); break; } } break; case "resume": for (int x=0;x<dcc.Transfer.Count;x++) { if (dcc.Transfer[x].Identifier==int.Parse(strDccParams[2])) { dcc.Transfer[x].ResumeRequested(long.Parse(strDccParams[3])); break; } } break; } } } break; default: Target.FireRecievedCtCpMessage(users.GetUser(user), strCommand, strParams); break; } #endregion } else { #region CtCp Responses switch (strCommand.ToLower()) { case "ping": users.GetUser(user).FireCtCpPingReplied(new TimeSpan(TimeSpan.TicksPerMillisecond * long.Parse(strParams))); break; case "time": users.GetUser(user).FireCtCpTimeReplied(strParams); break; case "finger": users.GetUser(user).FireCtCpFingerReplied(strParams); break; case "version": users.GetUser(user).FireCtCpVersionReplied(strParams); break; default: users.GetUser(user).FireCtCpReplied(strCommand, strParams); break; } #endregion } }
private void ParseCTCP(UserInfo user, MessageReciever Target, string CTCPData, bool blNotice) { CTCPData = CTCPData.Trim(); string strCommand = ""; string strParams = ""; if (CTCPData.IndexOf(" ") > -1) { strCommand = CTCPData.Substring(0, CTCPData.IndexOf(" ")); strParams = CTCPData.Substring(CTCPData.IndexOf(" ") + 1, CTCPData.Length - (CTCPData.IndexOf(" ") + 1)); } else { strCommand = CTCPData; } if (!blNotice) { #region CtCp Requests switch (strCommand.ToLower()) { case "ping": base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01PING " + strParams + "\x01", false); break; case "version": string clientInfo = "TNets IRC Library v.0.7"; if (this.CtCpVersionNeedsClientInfo != null) { clientInfo = this.CtCpVersionNeedsClientInfo(this, new EventArgs()); } base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01VERSION " + clientInfo + "\x01", false); break; case "finger": TimeSpan time = (TimeSpan)DateTime.Now.Subtract(base.CurrentConnection.LastActive); string strReadable = ""; #region Calculate readable idle time if (time.TotalSeconds > 60) { string strHours = ""; string strMinutes = ""; string strSeconds = ""; if (time.Hours > 0) { if (time.Hours > 1) { strHours = time.Hours.ToString() + " hours "; } else { strHours = time.Hours.ToString() + " hour "; } } if (time.Minutes > 0) { if (time.Minutes > 1) { strMinutes = time.Minutes.ToString() + " minutes "; } else { strMinutes = time.Minutes.ToString() + " minute "; } } if (time.Seconds > 0) { if (time.Seconds > 1) { strSeconds = time.Seconds.ToString() + " seconds "; } else { strSeconds = time.Seconds.ToString() + " second "; } } strReadable = strHours + strMinutes + strSeconds; strReadable = " (" + strReadable.Trim() + ")"; } #endregion base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01" + "FINGER Idle " + Math.Floor(time.TotalSeconds).ToString() + " seconds" + strReadable + "\x01", false); break; case "time": base.CurrentConnection.SendData("NOTICE " + user.Nick + " :\x01TIME " + mIRCDateTime(DateTime.Now) + "\x01", false); break; case "action": Target.FireRecievedMessage(users.GetUser(user), strParams, true); break; case "dcc": if (Target.GetType() == typeof(User)) { User userTarget = (User)Target; string[] strDccParams = strParams.Split(new char[] { ' ' }); if (strDccParams.Length >= 4) { switch (strDccParams[0].ToLower()) { case "chat": DCCChat newChat = new DCCChat(base.CurrentConnection, long.Parse(strDccParams[2]), int.Parse(strDccParams[3]), user.Nick, dcc.Chats); dcc.Chats.AddDcc(newChat); userTarget.FireDCCChatRequest(newChat); break; case "send": DCCTransfer newTransfer = new DCCTransfer(base.CurrentConnection, long.Parse(strDccParams[2]), int.Parse(strDccParams[3]), user.Nick, strDccParams[1], long.Parse(strDccParams[4]), dcc.Transfer); dcc.Transfer.AddDcc(newTransfer); userTarget.FireDCCTransferRequest(newTransfer); break; case "accept": for (int x = 0; x < dcc.Transfer.Count; x++) { if (dcc.Transfer[x].Identifier == int.Parse(strDccParams[2])) { dcc.Transfer[x].ResumeAccepted(long.Parse(strDccParams[3])); break; } } break; case "resume": for (int x = 0; x < dcc.Transfer.Count; x++) { if (dcc.Transfer[x].Identifier == int.Parse(strDccParams[2])) { dcc.Transfer[x].ResumeRequested(long.Parse(strDccParams[3])); break; } } break; } } } break; default: Target.FireRecievedCtCpMessage(users.GetUser(user), strCommand, strParams); break; } #endregion } else { #region CtCp Responses switch (strCommand.ToLower()) { case "ping": users.GetUser(user).FireCtCpPingReplied(new TimeSpan(TimeSpan.TicksPerMillisecond * long.Parse(strParams))); break; case "time": users.GetUser(user).FireCtCpTimeReplied(strParams); break; case "finger": users.GetUser(user).FireCtCpFingerReplied(strParams); break; case "version": users.GetUser(user).FireCtCpVersionReplied(strParams); break; default: users.GetUser(user).FireCtCpReplied(strCommand, strParams); break; } #endregion } }
internal void FireDCCChatRequest(DCCChat newChat) { if (this.DCCChatRequested != null) this.DCCChatRequested(this, new DCCChatRequestEventArgs(newChat)); }