package common.packet;

import java.io.IOException;

import common.network.IHandshakeHandler;
import common.network.Packet;
import common.network.PacketBuffer;

public class HPacketHandshake implements Packet<IHandshakeHandler> {
	private int protocol;

	public HPacketHandshake() {
	}

	public HPacketHandshake(int version) {
		this.protocol = version;
	}

	public void readPacketData(PacketBuffer buf) throws IOException {
		this.protocol = buf.readVarIntFromBuffer();
		int r = buf.readableBytes();
		if(r > 0) {
			this.protocol = 0;
			for(int z = 0; z < r; z++)
				buf.readByte();
		}
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		buf.writeVarIntToBuffer(this.protocol);
	}

	public void processPacket(IHandshakeHandler handler) {
		handler.processHandshake(this);
	}

	public int getProtocolVersion() {
		return this.protocol;
	}
}
