Example #1
0
        /// <summary>
        /// Decodes the machine information straight from login.
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public static MachineInformation Decode(IByteBuffer buffer)
        {
            buffer.ReadByte();
            int  architecture = buffer.ReadByte();
            bool x64          = buffer.ReadBoolean();
            int  build        = buffer.ReadByte();
            int  vendor       = buffer.ReadByte();

            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            buffer.ReadByte();
            IByteBufferExtensions.ReadString(buffer);
            IByteBufferExtensions.ReadString(buffer);
            IByteBufferExtensions.ReadString(buffer);
            IByteBufferExtensions.ReadString(buffer);
            buffer.ReadByte();
            buffer.ReadUnsignedShort();
            IByteBufferExtensions.ReadString(buffer);
            IByteBufferExtensions.ReadString(buffer);
            buffer.ReadByte();
            buffer.ReadByte();
            return(new MachineInformation(architecture, x64, build, vendor));
        }
        /// <summary>
        /// Decodes the login.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="input"></param>
        /// <param name="output"></param>
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output)
        {
            if (!input.IsReadable())
            {
                return;
            }

            LoginType type = Login.GetLoginType(input.ReadByte());

            if (type == LoginType.NONE)
            {
                return;
            }

            int size = input.ReadUnsignedShort();

            if (size != input.ReadableBytes)
            {
                return;
            }

            int version = input.ReadInt();
            int id      = input.ReadByte();//RSA is disabled.

            if (id != 1)
            {
                return;
            }
            input.ReadByte();
            int[] clientKeys = new int[4];
            for (int index = 0; index < clientKeys.Length; index++)
            {
                clientKeys[index] = input.ReadInt();
            }
            input.SkipBytes(8);
            string      password = IByteBufferExtensions.ReadString(input);
            IByteBuffer buffer   = IByteBufferExtensions.DecipherWithXTEA(input, clientKeys);
            string      username = IByteBufferExtensions.ReadString(buffer);

            buffer.ReadByte();
            buffer.ReadUnsignedShort();
            buffer.ReadUnsignedShort();
            buffer.SkipBytes(24);
            string token = IByteBufferExtensions.ReadString(buffer);

            buffer.ReadInt();
            var machineInformation = MachineInformation.Decode(buffer);

            buffer.ReadInt();
            buffer.ReadInt();
            buffer.ReadInt();
            buffer.ReadInt();
            buffer.ReadByte();
            int[] crc = new int[CacheManager.GetCache().GetTypeCount()];
            for (int index = 0; index < crc.Length; index++)
            {
                crc[index] = buffer.ReadInt();
            }
            int[] serverKeys = new int[4];
            for (int index = 0; index < serverKeys.Length; index++)
            {
                serverKeys[index] = clientKeys[index] + 50;
            }
            var decoder    = new Rand(clientKeys);
            var encoder    = new Rand(serverKeys);
            var isaacGroup = new IsaacRandGroup(decoder, encoder);

            output.Add(new LoginRequest(version, username, password, token, crc, isaacGroup, machineInformation));
        }
Example #3
0
 /// <summary>
 /// Gets a string from the buffer.
 /// </summary>
 /// <returns></returns>
 public string GetString()
 {
     CheckByteAccess();
     return(IByteBufferExtensions.ReadString(buffer));
 }