Наследование: System.EventArgs
Пример #1
0
        private void DataReceived(IAsyncResult res)
        {
            Receiving = false;
            try
            {
                SocketError err = SocketError.Success;
                if(disposed)
                    return;
                int received = ((Socket)res.AsyncState).EndReceive(res, out err);
                if (received <= 0 || err != SocketError.Success)
                {
                    this.Disconnect();
                    return;
                }
                DataEventArgs data = new DataEventArgs(this, buffer, received);
                this.onDataReceived(this, data);
            }
            catch (Exception ex)
            {
                #if DEBUG
 #if DEBUG
 Console.WriteLine(ex.ToString()); 
#endif 
#endif
                this.Disconnect();
            }
        }
Пример #2
0
 private void DataReceived(IAsyncResult res)
 {
     try
     {
         SocketError err = SocketError.Success;
         int received = 0;
         if (((Socket)res.AsyncState).Connected) received = ((Socket)res.AsyncState).EndReceive(res, out err);
         if (received <= 0 || err != SocketError.Success)
         {
             this.Disconnect();
             return;
         }
         DataEventArgs data = new DataEventArgs(this, buffer, received);
         this.onDataReceived(this, data);
     }
     catch
     {
         this.Disconnect();
     }
 }
Пример #3
0
 public int Receive(byte[] data, int offset, int count)
 {
     try
     {
         int received = this.Sock.Receive(data, offset, count, SocketFlags.None);
         if (received <= 0)
         {
             this.Disconnect();
             return -1;
         }
         DataEventArgs dargs = new DataEventArgs(this, data, received);
         //this.onDataReceived(this, dargs);
         return received;
     }
     catch
     {
         this.Disconnect();
         return -1;
     }
 }
Пример #4
0
        public bool Send(byte[] buff, int offset, int count)
        {
            try
            {
                if (this.Sock != null)
                {
                    if (this.Sock.Send(buff, offset, count, SocketFlags.None) <= 0)
                    {
                        this.Disconnect();
                        return false;
                    }
                    DataEventArgs data = new DataEventArgs(this, buff, count);
                    this.onDataSent(this, data);
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                #if DEBUG
 #if DEBUG
 Console.WriteLine(ex.ToString()); 
#endif 
#endif
                this.Disconnect();
                return false;
            }
        }
Пример #5
0
        private void DataSent(IAsyncResult res)
        {
            try
            {
                int sent = ((Socket)res.AsyncState).EndSend(res);
                if (sent < 0)
                {
                    this.Sock.Shutdown(SocketShutdown.Both);
                    this.Sock.Close();
                    return;
                }
                DataEventArgs data = new DataEventArgs(this, new byte[0] {}, sent);
                this.onDataSent(this, data);
            }
            catch (Exception ex) {
#if DEBUG
 Console.WriteLine(ex.ToString()); 
#endif 
            }
        }
Пример #6
0
 public void SendAsync(byte[] buff, int offset, int count)
 {
     try
     {
         if (this.Sock != null && this.Sock.Connected)
         {
             DataEventArgs data = new DataEventArgs(this, buff, count);
             this.onDataSent(this, data);
             this.Sock.BeginSend(buff, offset, count, SocketFlags.None, new AsyncCallback(DataSent), this.Sock);
         }
     }
     catch
     {
         this.Disconnect();
     }
 }
Пример #7
0
 void RemoteClient_onDataReceived(object sender, DataEventArgs e)
 {
     Client.Client.SendAsync(e.Buffer, e.Offset, e.Count);
     RemoteClient.ReceiveAsync();
 }
Пример #8
0
 //All stats data is "Server" bandwidth stats, meaning clientside totals not counted.
 void Client_onDataSent(object sender, DataEventArgs e)
 {
     //Technically we are sending data from the remote server to the client, so it's being "received"
     this.Stats.AddBytes(e.Count, ByteType.Received);
     this.Stats.AddPacket(PacketType.Received);
 }
Пример #9
0
 void Client_onDataSent(object sender, DataEventArgs e)
 {
     this.Stats.AddBytes(e.Count, ByteType.Sent);
     this.Stats.AddPacket(PacketType.Sent);
 }
Пример #10
0
 void RemoteClient_onDataReceived(object sender, DataEventArgs e)
 {
     e.Request = this.ModifiedReq;
     try
     {
         foreach (DataHandler f in Plugins)
             f.OnServerDataReceived(this, e);
         //craft headers & shit.
         byte[] outputdata = se.ProcessOutputData(e.Buffer, e.Offset, e.Count);
         byte[] datatosend = new byte[outputdata.Length + 4];
         Buffer.BlockCopy(outputdata, 0, datatosend, 4, outputdata.Length);
         Buffer.BlockCopy(BitConverter.GetBytes(outputdata.Length), 0, datatosend, 0, 4);
         //send outputdata's length first.
         Client.Client.Send(datatosend);
         if(!RemoteClient.Receiving)
             RemoteClient.ReceiveAsync();
         if (!Client.Client.Receiving)
             Client.Client.ReceiveAsync();
     }
     catch
     {
         //Client.Client.Disconnect();
         RemoteClient.Disconnect();
     }
 }
Пример #11
0
 void Client_onDataReceived(object sender, DataEventArgs e)
 {
     e.Request = this.ModifiedReq;
     //this should be packet header.
     try
     {
         int torecv = BitConverter.ToInt32(e.Buffer, e.Offset);
         byte[] newbuff = new byte[torecv];
         int recv = Client.Client.Receive(newbuff, 0, newbuff.Length);
         if (recv == torecv)
         {
             //yey
             //process packet.
             byte[] output = se.ProcessInputData(newbuff, 0, recv);
             e.Buffer = output;
             e.Offset = 0;
             e.Count = output.Length;
             //receive full packet.
             foreach (DataHandler f in Plugins)
                 if (f.Enabled)
                     f.OnClientDataReceived(this, e);
             RemoteClient.SendAsync(e.Buffer, e.Offset, e.Count);
             if (!Client.Client.Receiving)
                 Client.Client.ReceiveAsync();
             if (!RemoteClient.Receiving)
                 RemoteClient.ReceiveAsync();
         }
         else
         {
             throw new Exception();
         }
     }
     catch
     {
         //disconnect.
         Client.Client.Disconnect();
         RemoteClient.Disconnect();
     }
 }
Пример #12
0
        void RemoteClient_onDataReceived(object sender, DataEventArgs e)
        {
            e.Request = this.ModifiedReq;
            try
            {
                foreach (DataHandler f in Plugins)
                    if (f.Enabled)
                        f.OnServerDataReceived(this, e);
                //craft headers & shit.
                byte[] outputdata = se.ProcessOutputData(e.Buffer, e.Offset, e.Count);
                //send outputdata's length firs.t
                Client.Client.Send(BitConverter.GetBytes(outputdata.Length));
                e.Buffer = outputdata;
                e.Offset = 0;
                e.Count = outputdata.Length;
                //ok now send data.
                Client.Client.Send(e.Buffer, e.Offset, e.Count);
                if(!RemoteClient.Receiving)
                    RemoteClient.ReceiveAsync();
                if (!Client.Client.Receiving)
                    Client.Client.ReceiveAsync();

            }
            catch
            {
                Client.Client.Disconnect();
                RemoteClient.Disconnect();
            }
        }
Пример #13
0
 /// <summary>
 /// Allows you to grab/modify data before it's sent to the end user.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public abstract void OnServerDataReceived(object sender, DataEventArgs e);
Пример #14
0
 /// <summary>
 /// Allows you to grab/modify data before it's sent to the client.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public abstract void OnClientDataReceived(object sender, DataEventArgs e);
Пример #15
0
        public int Receive(byte[] data, int offset, int count)
        {
            try
            {
                int received = this.Sock.Receive(data, offset, count, SocketFlags.None);
                if (received <= 0)
                {
                    this.Disconnect();
                    return -1;
                }
                DataEventArgs dargs = new DataEventArgs(this, data, received);
                //this.onDataReceived(this, dargs);
                return received;
            }
            catch (Exception ex)
            {
                #if DEBUG
  Console.WriteLine(ex.ToString()); 
#endif 
                this.Disconnect();
                return -1;
            }
        }
Пример #16
0
 void Client_onDataReceived(object sender, DataEventArgs e)
 {
     this.Stats.AddBytes(e.Count, ByteType.Received);
     this.Stats.AddPacket(PacketType.Received);
 }
Пример #17
0
 void Client_onDataReceived(object sender, DataEventArgs e)
 {
     e.Request = this.ModifiedReq;
     //this should be packet header.
     try
     {
         int packetsize = BitConverter.ToInt32(e.Buffer, 0);
         byte[] newbuff = new byte[packetsize];
         //yey
         //process packet.
         byte[] output = se.ProcessInputData(e.Buffer, 4, packetsize);
         e.Buffer = null;
         e.Buffer = output;
         e.Offset = 0;
         e.Count = output.Length;
         //receive full packet.
         foreach (DataHandler f in Plugins)
             f.OnClientDataReceived(this, e);
         RemoteClient.SendAsync(e.Buffer, e.Offset, e.Count);
         if (!Client.Client.Receiving)
             Client.Client.ReceiveAsync();
         if (!RemoteClient.Receiving)
             RemoteClient.ReceiveAsync();
     }
     catch
     {
         //disconnect.
         Client.Client.Disconnect();
         RemoteClient.Disconnect();
     }
 }
Пример #18
0
 void Client_onDataReceived(object sender, DataEventArgs e)
 {
     //Technically we are receiving data from the client and sending it to the remote server, so it's being "sent"
     this.Stats.AddBytes(e.Count, ByteType.Sent);
     this.Stats.AddPacket(PacketType.Sent);
 }
Пример #19
0
 private void DataSent(IAsyncResult res)
 {
     try
     {
         int sent = ((Socket)res.AsyncState).EndSend(res);
         if (sent < 0)
         {
             this.Sock.Shutdown(SocketShutdown.Both);
             this.Sock.Close();
             return;
         }
         DataEventArgs data = new DataEventArgs(this, new byte[0] {}, sent);
         this.onDataSent(this, data);
     }
     catch { this.Disconnect(); }
 }
Пример #20
0
        void Client_onDataReceived(object sender, DataEventArgs e)
        {
            e.Request = this.ModifiedReq;
            foreach (DataHandler f in Plugins)
                if(f.Enabled)
                    f.OnClientDataReceived(this, e);

            RemoteClient.Send(e.Buffer, e.Offset, e.Count);
            if (!Client.Client.Receiving)
                Client.Client.ReceiveAsync();
            if (!RemoteClient.Receiving)
                RemoteClient.ReceiveAsync();
        }
Пример #21
0
 public bool Send(byte[] buff, int offset, int count)
 {
     try
     {
         if (this.Sock != null)
         {
             if (this.Sock.Send(buff, offset, count, SocketFlags.None) <= 0)
             {
                 this.Disconnect();
                 return false;
             }
             DataEventArgs data = new DataEventArgs(this, buff, count);
             this.onDataSent(this, data);
             return true;
         }
         return false;
     }
     catch
     {
         this.Disconnect();
         return false;
     }
 }
Пример #22
0
        void Client_onDataReceived(object sender, DataEventArgs e)
        {
            //this should be packet header.
            try
            {
                if (enc.GetAuthType() != AuthTypes.Login && enc.GetAuthType() != AuthTypes.None)
                {
                    //get total number of bytes.
                    int torecv = BitConverter.ToInt32(e.Buffer, 0);
                    byte[] newbuff = new byte[torecv];

                    int recvd = Client.Receive(newbuff, 0, torecv);
                    if (recvd == torecv)
                    {
                        byte[] output = enc.ProcessInputData(newbuff, 0, recvd);
                        //receive full packet.
                        e.Buffer = output;
                        e.Offset = 0;
                        e.Count = output.Length;
                        this.OnDataReceived(this, new Socks5ClientDataArgs(this, e.Buffer, e.Count, e.Offset));
                    }
                }
                else
                {
                    this.OnDataReceived(this, new Socks5ClientDataArgs(this, e.Buffer, e.Count, e.Offset));
                }
            }
            catch
            {
                //disconnect.
                Client.Disconnect();
                throw new Exception();
            }
        }
Пример #23
0
 /// <summary>
 /// Allows you to grab/modify data before it's sent to the end server.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public abstract void OnDataSent(object sender, DataEventArgs e);