package common.packet;

import java.io.IOException;

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

public class CPacketBook implements Packet<IPlayer>
{
    private String[] pages;

    public CPacketBook()
    {
    }

    public CPacketBook(String[] pages)
    {
        this.pages = pages;
    }
    
    public void readPacketData(PacketBuffer buf) throws IOException
    {
        int pages = (int)buf.readByte();
        if(pages > 50) {
        	this.pages = new String[0];
        	return;
        }
        this.pages = new String[pages];
        for(int z = 0; z < pages; z++) {
        	this.pages[z] = buf.readStringFromBuffer(1024);
        }
    }
    
    public void writePacketData(PacketBuffer buf) throws IOException
    {
        buf.writeByte(this.pages.length);
        for(int z = 0; z < this.pages.length; z++) {
        	buf.writeString(this.pages[z]);
        }
    }
    
    public void processPacket(IPlayer handler)
    {
    	handler.processBook(this);
    }

    public String[] getPages()
    {
        return this.pages;
    }
}
