Wrapper class for handling all kinds of Dcc events / actions. TODO: Maybe make it possible to have more than one transfer for the same file? TODO: Fileserver
        public DccReceiveClient(Dcc dcc, IrcUser user, Socket sock, IPEndPoint addr, FileInfo file, long totalSize,
								TimeSpan timeout)
            : base(dcc, user, sock, file, 0, totalSize)
        {
            m_remoteAddr = addr;
            // m_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 10000)
            m_timeoutTimer = new Timer((int)timeout.TotalMilliseconds);
            m_timeoutTimer.Elapsed += OnTimeout;
            m_timeoutTimer.AutoReset = false;
            m_timeoutTimer.Start();
        }
        public IrcClient(Encoding encoding)
        {
            Reset();
            m_Users = new Dictionary<string, IrcUser>(StringComparer.InvariantCultureIgnoreCase);
            m_unbanTimers = new Dictionary<string, UnbanTimer>();

            m_me = new IrcUser(this);
            m_client = new Client(this);
            m_CommandHandler = new IrcCommandHandler(this);
            m_dcc = new Dcc.Dcc(this);
            protHandler = new IrcProtocolHandler(this, encoding);
        }
 public DccClient(Dcc dcc, IrcUser user, Socket sock)
     : this(dcc, user)
 {
     m_sock = sock;
 }
        protected override void DoTransfer()
        {
            var buf = new byte[8192];
            int n   = 0;

            try
            {
                n = m_fstream.Read(buf, 0, buf.Length);
            }
            catch (Exception ex)
            {
                Dcc.TransferFailedNotify(this, ex);
                Shutdown();
                return;
            }

            if (n > 0)
            {
                try
                {
                    m_sock.BeginSend(buf, 0, n, SocketFlags.None, new AsyncCallback(OnSend), null);
                }
                catch (Exception ex)
                {
                    Dcc.TransferFailedNotify(this, ex);
                    Shutdown();
                }
            }

            else
            {
                Dcc.TransferDoneNotify(this);
            }
        }
Beispiel #5
0
        internal void Accept(long pos)
        {
            if (m_closed)
            {
                return;
            }

            m_accepted = true;
            m_startPos = pos;
            if (!m_sock.Connected)
            {
                try
                {
                    m_sock.BeginConnect(m_remoteAddr, OnConnect, null);
                    return;
                }
                catch (Exception e)
                {
                    Dcc.TransferFailedNotify(this, e);
                    Shutdown();
                    return;
                }
            }
            AfterConnect();
        }
 public DccClient(Dcc dcc, IrcUser user)
 {
     m_dcc = dcc;
     m_user = user;
     m_startTime = DateTime.Now;
     m_closed = false;
 }
 public DccTransferClient(Dcc dcc, IrcUser user, FileInfo file, long startPos, long totalLength) : base(dcc, user)
 {
     m_file        = file;
     m_startPos    = startPos;
     m_totalLength = totalLength;
     Dcc.AddTransferClient(this);
 }
Beispiel #8
0
        private void OnReceive(IAsyncResult ar)
        {
            if (m_closed)
            {
                return;
            }

            try
            {
                var buf = (byte[])ar.AsyncState;
                int n   = m_sock.EndReceive(ar);
                if (n < 1)
                {
                    throw new Exception("Connection has been closed remotewise.");
                }
                m_fstream.Write(buf, 0, n);
                OnBytesTransfered(n);
            }
            catch (Exception e)
            {
                Dcc.TransferFailedNotify(this, e);
                Shutdown();
                return;
            }
            Transfer();
        }
Beispiel #9
0
 public DccClient(Dcc dcc, IrcUser user)
 {
     m_dcc       = dcc;
     m_user      = user;
     m_startTime = DateTime.Now;
     m_closed    = false;
 }
Beispiel #10
0
 protected override void Cleanup()
 {
     if (m_fstream != null)
     {
         m_fstream.Close();
     }
     Dcc.RemoveTransferClient(this);
 }
 public DccTransferClient(Dcc dcc, IrcUser user, FileInfo file, long startPos, long totalLength)
     : base(dcc, user)
 {
     m_file = file;
     m_startPos = startPos;
     m_totalLength = totalLength;
     Dcc.AddTransferClient(this);
 }
Beispiel #12
0
 public DccReceiveClient(Dcc dcc, IrcUser user, Socket sock, IPEndPoint addr, FileInfo file, long totalSize,
                         TimeSpan timeout)
     : base(dcc, user, sock, file, 0, totalSize)
 {
     m_remoteAddr = addr;
     // m_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 10000)
     m_timeoutTimer           = new Timer((int)timeout.TotalMilliseconds);
     m_timeoutTimer.Elapsed  += OnTimeout;
     m_timeoutTimer.AutoReset = false;
     m_timeoutTimer.Start();
 }
Beispiel #13
0
 private void OnTimeout(object sender, ElapsedEventArgs info)
 {
     if (!m_accepted)
     {
         Dcc.ReceiveTimeoutNotify(this);
         Shutdown();
     }
     else
     {
         m_timeoutTimer.Close();
     }
 }
Beispiel #14
0
        public IrcClient(Encoding encoding)
        {
            Reset();
            m_Users       = new Dictionary <string, IrcUser>(StringComparer.InvariantCultureIgnoreCase);
            m_unbanTimers = new Dictionary <string, UnbanTimer>();

            m_me             = new IrcUser(this);
            m_client         = new Client(this);
            m_CommandHandler = new IrcCommandHandler(this);
            m_dcc            = new Dcc.Dcc(this);
            protHandler      = new IrcProtocolHandler(this, encoding);
        }
Beispiel #15
0
 internal override void Start()
 {
     try
     {
         m_fstream          = m_file.OpenRead();
         m_fstream.Position = StartPosition;
     }
     catch (Exception ex)
     {
         Dcc.TransferFailedNotify(this, ex);
         Shutdown();
         return;
     }
     Dcc.TransferEstablishedNotify(this);
     Transfer();
 }
Beispiel #16
0
 private void OnConnnect(IAsyncResult ar)
 {
     if (m_closed)
     {
         return;
     }
     try
     {
         m_sock.EndConnect(ar);
     }
     catch (Exception e)
     {
         Dcc.ChatFailedNotify(this, e);
         Dcc.RemoveChatClient(this);
         return;
     }
     AfterConnect();
 }
Beispiel #17
0
        private void OnConnect(IAsyncResult ar)
        {
            if (m_closed)
            {
                return;
            }

            try
            {
                m_sock.EndConnect(ar);
            }
            catch (Exception e)
            {
                Dcc.TransferFailedNotify(this, e);
                Shutdown();
                return;
            }
            AfterConnect();
        }
Beispiel #18
0
        private void OnSend(IAsyncResult ar)
        {
            if (m_closed)
            {
                return;
            }

            try
            {
                int n = m_sock.EndSend(ar);
                OnBytesTransfered(n);
            }
            catch (Exception ex)
            {
                Dcc.TransferFailedNotify(this, ex);
                Shutdown();
            }
            Transfer();
        }
Beispiel #19
0
 protected override void DoTransfer()
 {
     try
     {
         var buf = new byte[4096];
         if ((m_bytesTransfered + StartPosition) < TotalLength && m_sock.Connected)
         {
             m_sock.BeginReceive(buf, 0, buf.Length, SocketFlags.None, new AsyncCallback(OnReceive), buf);
             return;
         }
     }
     catch (Exception e)
     {
         Dcc.TransferFailedNotify(this, e);
         Shutdown();
         return;
     }
     Dcc.TransferDoneNotify(this);
 }
Beispiel #20
0
 private void AfterConnect()
 {
     if (m_closed)
     {
         return;
     }
     try
     {
         m_fstream          = new FileStream(m_file.FullName, FileMode.Append, FileAccess.Write, FileShare.Read);
         m_fstream.Position = StartPosition;
     }
     catch (Exception e)
     {
         Dcc.TransferFailedNotify(this, e);
         Shutdown();
         return;
     }
     Dcc.TransferEstablishedNotify(this);
     Transfer();
 }
Beispiel #21
0
        private void OnReceive(IAsyncResult ar)
        {
            if (m_closed)
            {
                return;
            }
            var buf = (byte[])ar.AsyncState;
            int n   = 0;

            try
            {
                n = m_sock.EndReceive(ar);
            }
            catch
            {
                n = -1;
            }

            if (n < 1)
            {
                Shutdown();
                return;
            }

            else if (n > 0)
            {
                string   text  = IrcClient.Encoding.GetString(buf, 0, n);
                string[] lines = Regex.Split(text, @"\n|(\r\n?)");
                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i].Trim();
                    if (line.Length <= 0)
                    {
                        continue;
                    }
                    Dcc.ChatMessageReceivedNotify(this, new StringStream(line));
                }
            }

            Receive();
        }
Beispiel #22
0
 internal override void Start()
 {
     if (!m_sock.Connected)
     {
         try
         {
             m_sock.BeginConnect(m_remoteEndPoint, OnConnnect, null);
         }
         catch (Exception e)
         {
             Dcc.ChatFailedNotify(this, e);
             return;
         }
         Dcc.AddChatClient(this);
     }
     else
     {
         m_remoteEndPoint = (IPEndPoint)m_sock.RemoteEndPoint;
         Dcc.AddChatClient(this);
         AfterConnect();
     }
 }
Beispiel #23
0
 public DccClient(Dcc dcc, IrcUser user, Socket sock) : this(dcc, user)
 {
     m_sock = sock;
 }
 public DccSendClient(Dcc dcc, IrcUser user, FileInfo file, TimeSpan timeout, int port)
     : base(dcc, user, file, 0, file.Length)
 {
     m_listener = new DccListener(this, timeout, port);
 }
 public DccReceiveClient(Dcc dcc, IrcUser user, Socket sock, IPEndPoint addr, FileInfo file, long totalSize)
     : base(dcc, user, sock, file, 0, totalSize)
 {
     m_remoteAddr = addr;
     Accept(0);
 }
Beispiel #26
0
 internal DccChatClient(Dcc dcc, IrcUser user, TimeSpan timeout, int port) : base(dcc, user)
 {
     m_listener = new DccListener(this, timeout, port);
 }
Beispiel #27
0
 protected override void Cleanup()
 {
     Dcc.ChatClosedNotify(this);
     Dcc.RemoveChatClient(this);
 }
Beispiel #28
0
 public DccReceiveClient(Dcc dcc, IrcUser user, Socket sock, IPEndPoint addr, FileInfo file, long totalSize) :
     base(dcc, user, sock, file, 0, totalSize)
 {
     m_remoteAddr = addr;
     Accept(0);
 }
Beispiel #29
0
 internal DccChatClient(Dcc dcc, IrcUser user, IPEndPoint ep) : base(dcc, user)
 {
     m_remoteEndPoint = ep;
     Start();
 }
Beispiel #30
0
 private void AfterConnect()
 {
     Dcc.ChatEstablishedNotify(this);
     Receive();
 }
Beispiel #31
0
 public DccSendClient(Dcc dcc, IrcUser user, FileInfo file, TimeSpan timeout, int port) : base(dcc, user, file, 0, file.Length)
 {
     m_listener = new DccListener(this, timeout, port);
 }
Beispiel #32
0
 internal DccChatClient(Dcc dcc, IrcUser user, TimeSpan timeout, int port)
     : base(dcc, user)
 {
     m_listener = new DccListener(this, timeout, port);
 }
Beispiel #33
0
 internal DccChatClient(Dcc dcc, IrcUser user, IPEndPoint ep)
     : base(dcc, user)
 {
     m_remoteEndPoint = ep;
     Start();
 }
Beispiel #34
0
 protected void OnBytesTransfered(int n)
 {
     m_bytesTransfered += n;
     Dcc.BytesTransferredNotify(this, n);
 }