package common.packet;

import java.io.IOException;

import common.network.IClientLoginHandler;
import common.network.Packet;
import common.network.PacketBuffer;

public class RPacketDisconnect implements Packet<IClientLoginHandler>
{
    private String reason;

    public RPacketDisconnect()
    {
    }

    public RPacketDisconnect(String reasonIn)
    {
        this.reason = reasonIn;
    }

    /**
     * Reads the raw packet data from the data stream.
     */
    public void readPacketData(PacketBuffer buf) throws IOException
    {
        this.reason = buf.readStringFromBuffer(8192);
    }

    /**
     * Writes the raw packet data to the data stream.
     */
    public void writePacketData(PacketBuffer buf) throws IOException
    {
        buf.writeString(this.reason);
    }

    /**
     * Passes this Packet on to the NetHandler for processing.
     */
    public void processPacket(IClientLoginHandler handler)
    {
        handler.handleDisconnect(this);
    }

    public String getReason()
    {
        return this.reason;
    }
}
