Ejemplo n.º 1
0
        public override List <byte[]> PacketReceived(byte[] packet)
        {
            List <byte[]> list       = new List <byte[]>();
            uint          packetType = ecoServerProtocol.getPacketType(this._header);

            if ((ulong)ecoServerProtocol.getPacketType(this._header) == 35328uL)
            {
                int num = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 0));
                ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 2));
                SessionAPI.Update((long)num);
                this.AppendResponse(list, 35456, 0, null);
            }
            else
            {
                if ((ulong)ecoServerProtocol.getPacketType(this._header) == 1uL)
                {
                    this.AppendResponse(list, 129, 0, null);
                    if (this._owner != null)
                    {
                        this._owner.ReportMessage(this._owner, this, this._header, packet);
                    }
                }
                else
                {
                    if ((ulong)ecoServerProtocol.getPacketType(this._header) == 35343uL)
                    {
                        if (this._owner != null)
                        {
                            this._owner.ReportMessage(this._owner, this, this._header, packet);
                        }
                    }
                    else
                    {
                        if ((ulong)ecoServerProtocol.getPacketType(this._header) == 35329uL)
                        {
                            if (this._owner != null)
                            {
                                this._owner.ReportMessage(this._owner, this, this._header, packet);
                            }
                        }
                        else
                        {
                            if ((ulong)packetType == 35330uL)
                            {
                                Common.WriteLine("    Logout from ecoClient", new string[0]);
                                int num2 = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(packet, 0));
                                int num3 = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(packet, 2));
                                SessionAPI.Logout((long)num2, (long)num3);
                                this.AppendResponse(list, 35458, 0, null);
                            }
                            else
                            {
                                if ((ulong)ecoServerProtocol.getPacketType(this._header) == 35471uL)
                                {
                                    if (this._owner != null)
                                    {
                                        this._owner.ReportMessage(this._owner, this, this._header, packet);
                                    }
                                }
                                else
                                {
                                    if ((ulong)packetType == 35331uL)
                                    {
                                        if (this._owner != null)
                                        {
                                            this._owner.ReportMessage(this._owner, this, this._header, packet);
                                        }
                                    }
                                    else
                                    {
                                        if ((ulong)packetType == 35332uL)
                                        {
                                            if (this._owner != null)
                                            {
                                                this._owner.ReportMessage(this._owner, this, this._header, packet);
                                            }
                                        }
                                        else
                                        {
                                            if ((ulong)packetType != 384uL)
                                            {
                                                if ((ulong)packetType == 385uL)
                                                {
                                                    if (this._owner != null)
                                                    {
                                                        this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                    }
                                                }
                                                else
                                                {
                                                    if ((ulong)packetType == 259uL)
                                                    {
                                                        if (this._owner != null)
                                                        {
                                                            this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if ((ulong)packetType == 35456uL)
                                                        {
                                                            int num4 = (int)this._receiveBuffer[0];
                                                            if (num4 > 0 && this._owner != null)
                                                            {
                                                                this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if ((ulong)packetType == 35457uL)
                                                            {
                                                                if (this._owner != null)
                                                                {
                                                                    this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if ((ulong)packetType == 35459uL)
                                                                {
                                                                    Common.WriteLine("    Request ack from ecoServer", new string[0]);
                                                                    int num5 = (int)this._receiveBuffer[0];
                                                                    int num6 = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 1));
                                                                    if (num5 != 0 && (num6 == 4 || num6 == 32 || num6 == 2) && this._owner != null)
                                                                    {
                                                                        this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if ((ulong)packetType == 35458uL)
                                                                    {
                                                                        Common.WriteLine("    Logout ack from ecoServer", new string[0]);
                                                                    }
                                                                    else
                                                                    {
                                                                        if ((ulong)packetType == 35460uL)
                                                                        {
                                                                            Common.WriteLine("    Message ack from ecoServer", new string[0]);
                                                                        }
                                                                        else
                                                                        {
                                                                            if ((ulong)packetType == 35333uL)
                                                                            {
                                                                                Common.WriteLine("    Error Message from ecoServer", new string[0]);
                                                                                this.AppendResponse(list, 35461, 0, null);
                                                                                int num7 = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 0));
                                                                                ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 2));
                                                                                if (num7 == 1 && this._owner != null)
                                                                                {
                                                                                    this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                if ((ulong)packetType == 386uL)
                                                                                {
                                                                                    if (this._owner != null)
                                                                                    {
                                                                                        this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                                                    }
                                                                                }
                                                                                else
                                                                                {
                                                                                    if ((ulong)packetType == 32uL)
                                                                                    {
                                                                                        int startIndex = 0;
                                                                                        int num8       = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(packet, startIndex));
                                                                                        base.setKicked(true);
                                                                                        Common.WriteLine("    Be kicked: uid={0}", new string[]
                                                                                        {
                                                                                            num8.ToString()
                                                                                        });
                                                                                        ClientAPI.OnClosed(this, -2);
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if ((ulong)packetType == 48uL)
                                                                                        {
                                                                                            int startIndex2 = 0;
                                                                                            int num9        = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(packet, startIndex2));
                                                                                            base.setServiceWillDown(true);
                                                                                            Common.WriteLine("    Service will be down: uid={0}", new string[]
                                                                                            {
                                                                                                num9.ToString()
                                                                                            });
                                                                                            ClientAPI.OnClosed(this, -2);
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if ((ulong)packetType == 260uL)
                                                                                            {
                                                                                                if (this._owner != null)
                                                                                                {
                                                                                                    this._owner.ReportMessage(this._owner, this, this._header, packet);
                                                                                                }
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if ((ulong)packetType == 258uL)
                                                                                                {
                                                                                                    this.AppendResponse(list, 386, 0, null);
                                                                                                    if (this._vid >= 0L)
                                                                                                    {
                                                                                                        int num10 = (int)ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 0));
                                                                                                        ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 2));
                                                                                                        ecoServerProtocol.swap16((ushort)BitConverter.ToInt16(this._receiveBuffer, 4));
                                                                                                        if (num10 > 0)
                                                                                                        {
                                                                                                            this.ReceiveDataset(ref this._sqlContext, packet);
                                                                                                        }
                                                                                                        else
                                                                                                        {
                                                                                                            this.ReceiveDataset(ref this._dsContext, packet);
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 2
0
        private void OnSocketReceived(SocketAsyncEventArgs e)
        {
            bool   flag   = false;
            bool   flag2  = true;
            Socket socket = e.AcceptSocket;

            if (e.LastOperation == SocketAsyncOperation.Receive)
            {
                socket = (e.UserToken as Socket);
            }
            C connection = base.GetConnection(socket);

            lock (this._lockServer)
            {
                if (e.SocketError != SocketError.Success || e.BytesTransferred == 0 || !socket.Connected)
                {
                    if (connection != null)
                    {
                        base.RemoveConnection(socket);
                    }
                    ServicesAPI.OnDisconnected(socket);
                    if (e.LastOperation == SocketAsyncOperation.Receive)
                    {
                        if (socket.Connected)
                        {
                            socket.Shutdown(SocketShutdown.Both);
                            socket.Disconnect(false);
                        }
                        socket.Close();
                        e.AcceptSocket = null;
                        e.UserToken    = null;
                        e.Completed   -= new EventHandler <SocketAsyncEventArgs>(this.IO_Completed);
                        this._receiveSocketArgs.Enqueue(e);
                    }
                    Common.WriteLine(this._threadName + ": connection down: " + this._connected, new string[0]);
                    return;
                }
                this._speedMeter.Received(e.BytesTransferred);
                if (connection != null)
                {
                    BufferState bufferState = new BufferState();
                    bufferState._ctx    = connection;
                    bufferState._buffer = e.Buffer;
                    if (bufferState._buffer != null)
                    {
                        Interlocked.Increment(ref this._totalRequests);
                        SessionAPI.Update(connection._uid);
                        int           num  = 0;
                        List <byte[]> list = connection.ReceivedBuffer(bufferState, e.BytesTransferred, ref num);
                        if (list != null)
                        {
                            flag2 = false;
                            foreach (byte[] current in list)
                            {
                                if (!socket.Connected)
                                {
                                    break;
                                }
                                this.StartSend(connection, current);
                            }
                        }
                    }
                }
            }
            if (!flag2)
            {
                if (e.LastOperation == SocketAsyncOperation.Receive)
                {
                    flag = true;
                    lock (this._lockServer)
                    {
                        if (socket.Connected)
                        {
                            flag = socket.ReceiveAsync(e);
                        }
                        else
                        {
                            ServicesAPI.OnDisconnected(socket);
                            if (connection != null)
                            {
                                base.RemoveConnection(socket);
                            }
                            e.AcceptSocket = null;
                            e.UserToken    = null;
                            e.Completed   -= new EventHandler <SocketAsyncEventArgs>(this.IO_Completed);
                            this._receiveSocketArgs.Enqueue(e);
                        }
                    }
                    if (!flag)
                    {
                        this.OnSocketReceived(e);
                    }
                }
                return;
            }
            if (connection != null)
            {
                base.RemoveConnection(socket);
            }
            ServicesAPI.OnDisconnected(socket);
            lock (this._lockServer)
            {
                if (socket.Connected)
                {
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Disconnect(false);
                }
                socket.Close();
            }
            if (e.LastOperation == SocketAsyncOperation.Receive)
            {
                e.AcceptSocket = null;
                e.UserToken    = null;
                e.Completed   -= new EventHandler <SocketAsyncEventArgs>(this.IO_Completed);
                this._receiveSocketArgs.Enqueue(e);
            }
            Common.WriteLine("Receive Processing Error", new string[0]);
        }