Esempio n. 1
0
        protected override void Encode(IChannelHandlerContext context, ServerPacket message, IByteBuffer output)
        {
            int encodedOpCode = message.OpCode + _cipher.GetNextValue(); //Encode the opcode.

            message.Buffer.SetByte(0, encodedOpCode);                    //Write the opcode to the first position.
            output.WriteBytes(message.Buffer);                           //Write the buffer from the message to the output.
            message.Buffer.Release();                                    //Release the old packet buffer.
        }
Esempio n. 2
0
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output)
        {
            if (opCode == -1)
            {
                if (input.ReadableBytes > 0)
                {
                    opCode = input.ReadByte();
                    opCode = opCode - _cipher.GetNextValue() & 0xFF;
                    size   = _packetLengths[opCode];
                }
                else
                {
                    return;
                }
            }

            if (size == -1)
            {
                if (input.ReadableBytes > 0)
                {
                    size = input.ReadByte() & 0xFF;
                }
                else
                {
                    return;
                }
            }

            if (size == -2)
            {
                if (input.ReadableBytes > 1)
                {
                    size = input.ReadUnsignedShort();
                }
                else
                {
                    return;
                }
            }

            if (input.ReadableBytes >= size)
            {
                output.Add(new ClientPacket(opCode, size, input.ReadBytes(size)));
                Reset();
            }
        }