package com.alterdekim.hearthhack.component.processor;

import com.alterdekim.Protocol;
import com.alterdekim.hearthhack.component.TcpConnection;
import com.alterdekim.hearthhack.util.BattleNetPacket;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ChannelSubProcessor extends Processor {

    public ChannelSubProcessor() {
        this.setProcessorId(5);
    }

    @Override
    public void process(BattleNetPacket packet, TcpConnection conn) throws Exception {
        if( packet.getHeader().getMethodId() != 3 ) return;
        Protocol.JoinChannelRequest request = Protocol.JoinChannelRequest.parseFrom(packet.getBody());
        Protocol.JoinChannelResponse response = Protocol.JoinChannelResponse.newBuilder()
                        .setObjectId(request.getObjectId())
                        .build();
        Protocol.Header header = generateResponse(response.getSerializedSize(), packet.getHeader().getToken(), 0, (int) packet.getHeader().getObjectId());
        conn.send(new BattleNetPacket(header, response.toByteArray()));
    }

    @Override
    public String getExportName() {
        return "bnet.protocol.channel.Channel";
    }
}
