package org.kne.cloud.network.minecraft;

import java.io.IOException;

import org.kne.io.VarDataInputStream;
import org.kne.io.VarDataOutputStream;

public class MinecraftHandShakePacket extends MinecraftPacket {
	int version;
	String addr;
	int port;
	int nextstate;
	public MinecraftHandShakePacket() {
		super(HANDSHAKE_MOTD);
	}
	public MinecraftHandShakePacket( int version, String addr, int port, int nextstate) {
		super(HANDSHAKE_MOTD);
		this.version = version;
		this.addr = addr;
		this.port = port;
		this.nextstate = nextstate;
	}
	public int getVersion() {
		return version;
	}
	@Override
	public String toString() {
		return "MinecraftHandShakePacket [version=" + version + ", addr=" + addr + ", port=" + port + ", nextstate="
				+ nextstate + "]";
	}
	public String getAddr() {
		return addr;
	}
	public int getPort() {
		return port;
	}
	public int getNextstate() {
		return nextstate;
	}
	@Override
	protected void writeToStream(VarDataOutputStream dto) throws IOException {
		super.writeToStream(dto);
		dto.writeVarInt(version);
		dto.writeVarUTF8(addr);
		dto.writeShort(port);
		dto.writeVarInt(nextstate);
	}
	@Override
	protected void readFromStream(VarDataInputStream din) throws IOException {
		super.readFromStream(din);
		version=din.readVarInt();
		addr=din.readVarUTF8();
		port=din.readUnsignedShort();
		nextstate=din.readVarInt();
	}
	
}
