    001package net.minecraft.network.packet;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.io.DataInputStream;
    006import java.io.DataOutputStream;
    007import java.io.IOException;
    008
    009public class Packet2ClientProtocol extends Packet
    010{
    011    private int protocolVersion;
    012    private String username;
    013    private String serverHost;
    014    private int serverPort;
    015
    016    public Packet2ClientProtocol() {}
    017
    018    @SideOnly(Side.CLIENT)
    019    public Packet2ClientProtocol(int par1, String par2Str, String par3Str, int par4)
    020    {
    021        this.protocolVersion = par1;
    022        this.username = par2Str;
    023        this.serverHost = par3Str;
    024        this.serverPort = par4;
    025    }
    026
    027    /**
    028     * Abstract. Reads the raw packet data from the data stream.
    029     */
    030    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    031    {
    032        this.protocolVersion = par1DataInputStream.readByte();
    033        this.username = readString(par1DataInputStream, 16);
    034        this.serverHost = readString(par1DataInputStream, 255);
    035        this.serverPort = par1DataInputStream.readInt();
    036    }
    037
    038    /**
    039     * Abstract. Writes the raw packet data to the data stream.
    040     */
    041    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    042    {
    043        par1DataOutputStream.writeByte(this.protocolVersion);
    044        writeString(this.username, par1DataOutputStream);
    045        writeString(this.serverHost, par1DataOutputStream);
    046        par1DataOutputStream.writeInt(this.serverPort);
    047    }
    048
    049    /**
    050     * Passes this Packet on to the NetHandler for processing.
    051     */
    052    public void processPacket(NetHandler par1NetHandler)
    053    {
    054        par1NetHandler.handleClientProtocol(this);
    055    }
    056
    057    /**
    058     * Abstract. Return the size of the packet (not counting the header).
    059     */
    060    public int getPacketSize()
    061    {
    062        return 3 + 2 * this.username.length();
    063    }
    064
    065    /**
    066     * Returns the protocol version.
    067     */
    068    public int getProtocolVersion()
    069    {
    070        return this.protocolVersion;
    071    }
    072
    073    /**
    074     * Returns the username.
    075     */
    076    public String getUsername()
    077    {
    078        return this.username;
    079    }
    080}