Example #1
0
 /// <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;
 }
Example #2
0
        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");
            }
        }
Example #3
0
        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");
            }
        }
Example #4
0
 /// <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;
 }
Example #5
0
        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");
            }
        }
Example #6
0
 public static void Initialise(){
     Client=new IrcFeatures{AutoRejoin=true,AutoRejoinOnKick=true};
     Client.Connect("irc.mibbit.net",8888);//TODO
     Client.Login("somebot","somebot");
     Client.RfcJoin("bravefrontier");
     Client.OnReadLine+=Test;
     Client.SendMessage(Message,"somebody","test");
     Client.Listen();
 }
Example #7
0
 /// <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) : base()
 {
     this.Irc = irc;
     this.ExternalIPAdress = externalIpAdress;
     this.User = user;
     
     if(passive) {
         irc.SendMessage(SendType.CtcpRequest, user, "DCC CHAT chat " + HostToDccInt(externalIpAdress).ToString() + " 0 " + session, priority);
         this.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).ToString() + " " + LocalEndPoint.Port, priority);
     } 
     
 }
Example #8
0
        /// <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).ToString() + " 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).ToString() + " " + LocalEndPoint.Port, priority);
            }
        }
Example #9
0
 internal DccSend(IrcFeatures irc, string user, IPAddress externalIpAdress, Stream file, string filename, long filesize, DccSpeed speed, bool passive, Priority priority) : base()
 {
     this.Irc = irc;
     _DirectionUp = true;
     _File = file;
     _Filesize = filesize;
     _Filename = filename;
     _Speed = speed;
     User = user;
     
     if(passive) {
         irc.SendMessage(SendType.CtcpRequest, user, "DCC SEND \"" + filename + "\" " + HostToDccInt(externalIpAdress).ToString() + " 0 " + filesize + " " + session, 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).ToString() + " " + LocalEndPoint.Port + " " + filesize, priority);
     }
 }
Example #10
0
        internal DccSend(IrcFeatures irc, string user, IPAddress externalIpAdress, Stream file, string filename, long filesize, DccSpeed speed, bool passive, Priority priority)
        {
            Irc          = irc;
            _DirectionUp = true;
            _File        = file;
            _Filesize    = filesize;
            _Filename    = filename;
            _Speed       = speed;
            User         = user;

            if (passive)
            {
                irc.SendMessage(SendType.CtcpRequest, user, "DCC SEND \"" + filename + "\" " + HostToDccInt(externalIpAdress).ToString() + " 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).ToString() + " " + LocalEndPoint.Port + " " + filesize, priority);
            }
        }
Example #11
0
        public IrcProtocolManager(Session session)
            : base(session)
        {
            Trace.Call(session);

            _IrcClient = new IrcFeatures();
            _IrcClient.AutoRetry = true;
            // keep retrying to connect forever
            _IrcClient.AutoRetryLimit = 0;
            _IrcClient.AutoRetryDelay = 120;
            _IrcClient.AutoReconnect = true;
            _IrcClient.AutoRelogin = true;
            _IrcClient.AutoRejoin = true;
            // HACK: SmartIrc4net <= 0.4.5.1 is not resetting the nickname list
            // after disconnect. This causes random nicks to be used when there
            // are many reconnects like when the network connection goes flaky,
            // see: http://projects.qnetp.net/issues/show/163
            _IrcClient.AutoNickHandling = false;
            _IrcClient.ActiveChannelSyncing = true;
            _IrcClient.CtcpVersion      = Engine.VersionString;
            _IrcClient.SendDelay        = 250;
            _IrcClient.OnRawMessage     += new IrcEventHandler(_OnRawMessage);
            _IrcClient.OnChannelMessage += new IrcEventHandler(_OnChannelMessage);
            _IrcClient.OnChannelAction  += new ActionEventHandler(_OnChannelAction);
            _IrcClient.OnChannelNotice  += new IrcEventHandler(_OnChannelNotice);
            _IrcClient.OnChannelActiveSynced += new IrcEventHandler(_OnChannelActiveSynced);
            _IrcClient.OnQueryMessage   += new IrcEventHandler(_OnQueryMessage);
            _IrcClient.OnQueryAction    += new ActionEventHandler(_OnQueryAction);
            _IrcClient.OnQueryNotice    += new IrcEventHandler(_OnQueryNotice);
            _IrcClient.OnJoin           += new JoinEventHandler(_OnJoin);
            _IrcClient.OnNames          += new NamesEventHandler(_OnNames);
            _IrcClient.OnPart           += new PartEventHandler(_OnPart);
            _IrcClient.OnKick           += new KickEventHandler(_OnKick);
            _IrcClient.OnNickChange     += new NickChangeEventHandler(_OnNickChange);
            _IrcClient.OnOp             += new OpEventHandler(_OnOp);
            _IrcClient.OnDeop           += new DeopEventHandler(_OnDeop);
            _IrcClient.OnVoice          += new VoiceEventHandler(_OnVoice);
            _IrcClient.OnDevoice        += new DevoiceEventHandler(_OnDevoice);
            _IrcClient.OnModeChange     += new IrcEventHandler(_OnModeChange);
            _IrcClient.OnTopic          += new TopicEventHandler(_OnTopic);
            _IrcClient.OnTopicChange    += new TopicChangeEventHandler(_OnTopicChange);
            _IrcClient.OnQuit           += new QuitEventHandler(_OnQuit);
            _IrcClient.OnRegistered     += new EventHandler(_OnRegistered);
            _IrcClient.OnDisconnected   += new EventHandler(_OnDisconnected);
            _IrcClient.OnAutoConnectError += OnAutoConnectError;
            _IrcClient.OnAway           += new AwayEventHandler(_OnAway);
            _IrcClient.OnUnAway         += new IrcEventHandler(_OnUnAway);
            _IrcClient.OnNowAway        += new IrcEventHandler(_OnNowAway);
            _IrcClient.OnCtcpRequest    += new CtcpEventHandler(_OnCtcpRequest);
            _IrcClient.OnCtcpReply      += new CtcpEventHandler(_OnCtcpReply);
            _IrcClient.OnWho            += OnWho;
            _IrcClient.OnInvite         += OnInvite;
            _IrcClient.OnReadLine       += OnReadLine;
            _IrcClient.OnWriteLine      += OnWriteLine;

            _IrcClient.CtcpUserInfo = (string) Session.UserConfig["Connection/Realname"];
            // disabled as we don't use / support DCC yet
            _IrcClient.CtcpDelegates.Remove("dcc");
            // finger we handle ourself, no little helga here!
            _IrcClient.CtcpDelegates["finger"] = delegate(CtcpEventArgs e) {
                _IrcClient.SendMessage(
                    SendType.CtcpReply, e.Data.Nick,
                    String.Format("{0} {1}",
                        e.CtcpCommand,
                        _IrcClient.CtcpUserInfo
                    )
                );
            };
            // time we handle ourself
            _IrcClient.CtcpDelegates["time"] = delegate(CtcpEventArgs e) {
                _IrcClient.SendMessage(
                    SendType.CtcpReply, e.Data.Nick,
                    String.Format("{0} {1}",
                        e.CtcpCommand,
                        DateTime.Now.ToString(
                            "ddd MMM dd HH:mm:ss yyyy",
                            DateTimeFormatInfo.InvariantInfo
                        )
                    )
                );
            };
        }