Exemplo n.º 1
0
    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();
    }
Exemplo n.º 2
0
        public static async Task OnCharacterEnum(PacketHandlerContext c)
        {
            var account    = c.AccountService.GetAccount(c.Client.Identifier);
            var characters = new List <Character>();

            foreach (var id in account.Characters)
            {
                var character = c.World.CharacterService.GetCharacter(id);
                if (character is null)
                {
                    c.Client.Log($"Could not find character with id {id} from player {account.Identifier}.", LogLevel.Warning);
                    continue;
                }

                characters.Add(character);
            }

            ServerPacketBase <Opcode> characterEnum = c.Client.Build switch
            {
                ClientBuild.Vanilla => new SMSG_CHAR_ENUM_VANILLA(characters),
                ClientBuild.TBC => new SMSG_CHAR_ENUM_TBC(characters),
                _ => throw new NotImplementedException($"OnCharacterEnum(build: {c.Client.Build})"),
            };

            await c.Client.SendPacket(characterEnum);
        }
Exemplo n.º 3
0
    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());
    }
Exemplo n.º 4
0
    public async Task SendPacket(ServerPacketBase <Opcode> message)
    {
        var data = this.Encode(message);

        await this.Send(data);

        this.logger.LogTrace($"{this.ClientInfo} - Sent {message.Opcode}");
        message.Dispose();
    }
Exemplo n.º 5
0
        private void OnPacketReceived(ServerPacketBase packet)
        {
            // If-else of doom
            var type = packet.GetType();

            if (type == typeof(LoginPacket))
            {
                HandlePacket((LoginPacket)packet);
            }
            else if (type == typeof(MessagePacket))
            {
                HandlePacket((MessagePacket)packet);
            }
            else
            {
                throw new ArgumentException("Unkown packet type: " + nameof(packet));
            }
        }
Exemplo n.º 6
0
 private void OnPacketReceived(ServerPacketBase packet)
 {
     HandlePacket((dynamic)packet);
 }
Exemplo n.º 7
0
 public async Task SendMessageAsync(ServerPacketBase packet)
 {
     await _socket?.SendMessageAsync(packet);
 }