package common.packet;

import java.io.IOException;

import common.network.ILoginHandler;
import common.network.IPlayer;
import common.network.Packet;
import common.network.PacketBuffer;

public class LPacketPasswordResponse implements Packet<ILoginHandler>
{
    private String user;
    private String access;
    private String password;

    public LPacketPasswordResponse()
    {
    }

    public LPacketPasswordResponse(String userIn, String accessIn, String passwordIn)
    {
        this.user = userIn;
        this.access = accessIn;
        this.password = passwordIn;
    }

    /**
     * Reads the raw packet data from the data stream.
     */
    public void readPacketData(PacketBuffer buf) throws IOException
    {
        this.user = buf.readStringFromBuffer(IPlayer.MAX_USER_LENGTH);
        this.access = buf.readStringFromBuffer(IPlayer.MAX_PASS_LENGTH);
        this.password = buf.readStringFromBuffer(IPlayer.MAX_PASS_LENGTH);
    }

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

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

    public String getUser()
    {
        return this.user;
    }

    public String getAccess()
    {
        return this.access;
    }

    public String getPassword()
    {
        return this.password;
    }
}
