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
예제 #1
1
        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();
        }
예제 #2
1
        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);
        }
예제 #3
1
 public DccClient(Dcc dcc, IrcUser user, Socket sock)
     : this(dcc, user)
 {
     m_sock = sock;
 }
예제 #4
0
        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);
            }
        }
예제 #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();
        }
예제 #6
0
 public DccClient(Dcc dcc, IrcUser user)
 {
     m_dcc = dcc;
     m_user = user;
     m_startTime = DateTime.Now;
     m_closed = false;
 }
예제 #7
0
 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);
 }
예제 #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();
        }
예제 #9
0
 public DccClient(Dcc dcc, IrcUser user)
 {
     m_dcc       = dcc;
     m_user      = user;
     m_startTime = DateTime.Now;
     m_closed    = false;
 }
예제 #10
0
 protected override void Cleanup()
 {
     if (m_fstream != null)
     {
         m_fstream.Close();
     }
     Dcc.RemoveTransferClient(this);
 }
예제 #11
0
 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);
 }
예제 #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();
 }
예제 #13
0
 private void OnTimeout(object sender, ElapsedEventArgs info)
 {
     if (!m_accepted)
     {
         Dcc.ReceiveTimeoutNotify(this);
         Shutdown();
     }
     else
     {
         m_timeoutTimer.Close();
     }
 }
예제 #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);
        }
예제 #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();
 }
예제 #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();
 }
예제 #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();
        }
예제 #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();
        }
예제 #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);
 }
예제 #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();
 }
예제 #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();
        }
예제 #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();
     }
 }
예제 #23
0
 public DccClient(Dcc dcc, IrcUser user, Socket sock) : this(dcc, user)
 {
     m_sock = sock;
 }
예제 #24
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);
 }
예제 #25
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);
 }
예제 #26
0
 internal DccChatClient(Dcc dcc, IrcUser user, TimeSpan timeout, int port) : base(dcc, user)
 {
     m_listener = new DccListener(this, timeout, port);
 }
예제 #27
0
 protected override void Cleanup()
 {
     Dcc.ChatClosedNotify(this);
     Dcc.RemoveChatClient(this);
 }
예제 #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);
 }
예제 #29
0
 internal DccChatClient(Dcc dcc, IrcUser user, IPEndPoint ep) : base(dcc, user)
 {
     m_remoteEndPoint = ep;
     Start();
 }
예제 #30
0
 private void AfterConnect()
 {
     Dcc.ChatEstablishedNotify(this);
     Receive();
 }
예제 #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);
 }
예제 #32
0
 internal DccChatClient(Dcc dcc, IrcUser user, TimeSpan timeout, int port)
     : base(dcc, user)
 {
     m_listener = new DccListener(this, timeout, port);
 }
예제 #33
0
 internal DccChatClient(Dcc dcc, IrcUser user, IPEndPoint ep)
     : base(dcc, user)
 {
     m_remoteEndPoint = ep;
     Start();
 }
예제 #34
0
 protected void OnBytesTransfered(int n)
 {
     m_bytesTransfered += n;
     Dcc.BytesTransferredNotify(this, n);
 }