/// <summary> /// Constructs a new object. /// </summary> /// <param name="version"></param> /// <param name="username"></param> /// <param name="password"></param> /// <param name="token"></param> /// <param name="crc"></param> /// <param name="isaacGroup"></param> /// <param name="machineInformation"></param> public LoginRequest(int version, string username, string password, string token, int[] crc, IsaacRandGroup isaacGroup, MachineInformation machineInformation) { this.version = version; this.username = username; this.password = password; this.token = token; this.crc = crc; this.isaacGroup = isaacGroup; this.machineInformation = machineInformation; }
/// <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)); }