public override async Task Initialize(TcpClient client) { await base.Initialize(client); this.addressToClientBuildMap = this.accountService.GetClientBuildFromAddress(this.Address, this.Port); if (this.addressToClientBuildMap is null) { this.logger.LogWarning($"Could not find client build for {this.Address}:{this.Port - 1}."); this.Build = ClientBuild.Vanilla; } else { this.Build = this.addressToClientBuildMap.ClientBuild; } this.logger.LogDebug($"{this.ClientInfo} - connected"); ServerPacketBase <Opcode> message = this.Build switch { ClientBuild.Vanilla or ClientBuild.TBC => SMSG_AUTH_CHALLENGE.VanillaTBC(), ClientBuild.WotLK => SMSG_AUTH_CHALLENGE.WotLK(), _ => throw new NotImplementedException($"SMSG_AUTH_CHALLENGE(build: {this.Build})"), }; await Send(message.Get()); this.logger.LogTrace($"{this.ClientInfo} - Sent {message.Opcode}"); await HandleConnection(); }
private byte[] Encode(ServerPacketBase <Opcode> message) { var data = message.Get(); var index = 0; var header = new byte[4]; // TODO: Fix for TBC... //if (message.Opcode == Opcode.SMSG_UPDATE_OBJECT && data.Length > 98) //{ // var uncompressed = data.Length; // message.Opcode = Opcode.SMSG_COMPRESSED_UPDATE_OBJECT; // data = Compression.Compress(data); // data = new PacketWriter().WriteUInt32((uint)uncompressed).WriteBytes(data).Build(); //} var newSize = data.Length + 2; //if (newSize > 0x7FFF) //{ // header[index++] = (byte)(0x80 | (0xFF & (newSize >> 16))); //} header[index++] = (byte)(0xFF & (newSize >> 8)); header[index++] = (byte)(0xFF & newSize); header[index++] = (byte)(0xFF & (int)message.Opcode); header[index] = (byte)(0xFF & ((int)message.Opcode >> 8)); header = this.HeaderCrypt.Encrypt(header); return(header.Concat(data).ToArray()); }