示例#1
0
            /// <summary>Prepares received data to be used by the appropriate packet handler methods.</summary>
            /// <param name="_data">The recieved data.</param>
            private bool HandleData(byte[] _data)
            {
                int _packetLength = 0;

                receivedData.SetBytes(_data);

                if (receivedData.UnreadLength() >= 4)
                {
                    // If client's received data contains a packet
                    _packetLength = receivedData.ReadInt();
                    if (_packetLength <= 0)
                    {
                        // If packet contains no data
                        return(true); // Reset receivedData instance to allow it to be reused
                    }
                }

                while (_packetLength > 0 && _packetLength <= receivedData.UnreadLength())
                {
                    // While packet contains data AND packet data length doesn't exceed the length of the packet we're reading
                    byte[] _packetBytes = receivedData.ReadBytes(_packetLength);
                    ThreadManager.ExecuteOnMainThread(() =>
                    {
                        using (Packet _packet = new Packet(_packetBytes))
                        {
                            ServerPackets _packetId = (ServerPackets)_packet.ReadInt();
                            PacketHandler.PacketHandlers[_packetId](_packet); // Call appropriate method to handle the packet
                        }
                    });

                    _packetLength = 0; // Reset packet length
                    if (receivedData.UnreadLength() >= 4)
                    {
                        // If client's received data contains another packet
                        _packetLength = receivedData.ReadInt();
                        if (_packetLength <= 0)
                        {
                            // If packet contains no data
                            return(true); // Reset receivedData instance to allow it to be reused
                        }
                    }
                }

                if (_packetLength <= 1)
                {
                    return(true); // Reset receivedData instance to allow it to be reused
                }

                return(false);
            }
示例#2
0
            private bool HandleData(byte[] data)
            {
                int packetLength = 0;

                receivedData.SetBytes(data);
                if (receivedData.UnreadLength() >= 4)
                {
                    packetLength = receivedData.ReadInt();
                    if (packetLength <= 0)
                    {
                        return(true);
                    }
                }
                while (packetLength > 0 && packetLength <= receivedData.UnreadLength())
                {
                    byte[] packetBytes = receivedData.ReadBytes(packetLength);
                    ThreadManager.ExecuteOnMainThread(() =>
                    {
                        using (Packet packet = new Packet(packetBytes))
                        {
                            int id = packet.ReadInt();
                            packetHandelers[id](packet);
                        }
                    });
                    packetLength = 0;

                    if (receivedData.UnreadLength() >= 4)
                    {
                        packetLength = receivedData.ReadInt();
                        if (packetLength <= 0)
                        {
                            return(true);
                        }
                    }
                }

                if (packetLength <= 1)
                {
                    return(true);
                }

                return(false);
            }
示例#3
0
            private bool handleData(byte[] data)
            {
                int pLenght = 0;

                recievedData.SetBytes(data);
                if (recievedData.UnreadLength() >= 4)
                {
                    pLenght = recievedData.ReadInt();
                    if (pLenght <= 0)
                    {
                        return(true);
                    }
                }
                while (pLenght > 0 && pLenght <= recievedData.UnreadLength())
                {
                    byte[] pBytes = recievedData.ReadBytes(pLenght);
                    ThreadManager.ExecuteOnMainThread(() => {
                        using (Packet P = new Packet(pBytes)) {
                            int PID = P.ReadInt();
                            Handlers[PID](P);
                        }
                    });
                    pLenght = 0;
                    if (recievedData.UnreadLength() >= 4)
                    {
                        pLenght = recievedData.ReadInt();
                        if (pLenght <= 0)
                        {
                            return(true);
                        }
                    }
                }
                if (pLenght <= 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
示例#4
0
        private bool HandlleData(byte[] data)
        {
            int packetLength = 0;

            receiveData.SetBytes(data);

            if (receiveData.UnreadLength() >= 4)
            {
                packetLength = receiveData.ReadInt();
                if (packetLength <= 0)
                {
                    return(true);
                }
            }
            while (packetLength > 0 && packetLength <= receiveData.UnreadLength())
            {
                byte[] packetBytes = receiveData.ReadBytes(packetLength);
                using (Packet packet = new Packet(packetBytes))
                {
                    int packetId = packet.ReadInt();
                    Client.packetHandlers[packetId](packet);
                }
            }
            packetLength = 0;

            if (receiveData.UnreadLength() >= 4)
            {
                packetLength = receiveData.ReadInt();
                if (packetLength <= 0)
                {
                    return(true);
                }
            }

            if (packetLength <= 1)
            {
                return(true);
            }
            return(false);
        }