#define BOOKTEXTENTRY using System; using System.IO; using System.Text; using Server; using Server.Network; using Server.Mobiles; using Server.Gumps; namespace Server.Items { public delegate void XmlTextEntryBookCallback( Mobile from, object [] args, string response ); public class XmlTextEntryBook : BaseEntryBook { public XmlTextEntryBookCallback m_bookcallback; public object [] m_args; public XmlTextEntryBook( int itemID, string title, string author, int pageCount, bool writable, XmlTextEntryBookCallback callback, object [] args) : base( itemID, title, author, pageCount, writable ) { m_args = args; m_bookcallback = callback; } public XmlTextEntryBook( Serial serial ) : base( serial ) { } public void FillTextEntryBook(string text) { int pagenum = 0; BookPageInfo [] pages = Pages; int current = 0; // break up the text into single line length pieces while(text != null && current < text.Length) { int lineCount = 8; string[] lines = new string[lineCount]; // place the line on the page for(int i=0;i 20) length = 20; lines[i] = text.Substring(current,length); current += length; } else { // fill up the remaining lines lines[i] = String.Empty; } } if ( pagenum >= PagesCount ) return; Pages[pagenum].Lines = lines; pagenum++; } // empty the remaining contents for(int j=pagenum;j < PagesCount; j++) { if(Pages[j].Lines.Length > 0) for(int i=0;i book.PagesCount ) return; for ( int i = 0; i < pageCount; ++i ) { // get the current page number being read int index = pvSrc.ReadUInt16(); if ( index >= 1 && index <= book.PagesCount ) { --index; int lineCount = pvSrc.ReadUInt16(); if ( lineCount <= 8 ) { string[] lines = new string[lineCount]; for ( int j = 0; j < lineCount; ++j ) { if ( (lines[j] = pvSrc.ReadUTF8StringSafe()).Length >= 80 ) return; } book.Pages[index].Lines = lines; } else { return; } } else { return; } } System.Text.StringBuilder sb = new System.Text.StringBuilder(); // add the book lines to the entry string for ( int i = 0; i < book.PagesCount; ++i ) { for(int j=0;j book.PagesCount) return; for (int i = 0; i < pageCount; ++i) { int index = pvSrc.ReadUInt16(); if (index >= 1 && index <= book.PagesCount) { --index; int lineCount = pvSrc.ReadUInt16(); if (lineCount <= 8) { string[] lines = new string[lineCount]; for (int j = 0; j < lineCount; ++j) if ((lines[j] = pvSrc.ReadUTF8StringSafe()).Length >= 80) return; book.Pages[index].Lines = lines; } else { return; } } else { return; } } } } #endif } #if(BOOKTEXTENTRY) public sealed class EntryBookPageDetails : Packet { public EntryBookPageDetails( BaseEntryBook book ) : base( 0x66 ) { EnsureCapacity( 256 ); m_Stream.Write( (int) book.Serial ); m_Stream.Write( (ushort) book.PagesCount ); for ( int i = 0; i < book.PagesCount; ++i ) { BookPageInfo page = book.Pages[i]; m_Stream.Write( (ushort) (i + 1) ); m_Stream.Write( (ushort) page.Lines.Length ); for ( int j = 0; j < page.Lines.Length; ++j ) { byte[] buffer = Utility.UTF8.GetBytes( page.Lines[j] ); m_Stream.Write( buffer, 0, buffer.Length ); m_Stream.Write( (byte) 0 ); } } } } public sealed class EntryBookHeader : Packet { public EntryBookHeader( Mobile from, BaseEntryBook book ) : base ( 0xD4 ) { string title = book.Title == null ? "" : book.Title; string author = book.Author == null ? "" : book.Author; byte[] titleBuffer = Utility.UTF8.GetBytes( title ); byte[] authorBuffer = Utility.UTF8.GetBytes( author ); EnsureCapacity( 15 + titleBuffer.Length + authorBuffer.Length ); m_Stream.Write( (int) book.Serial ); m_Stream.Write( (bool) true ); m_Stream.Write( (bool) book.Writable && from.InRange( book.GetWorldLocation(), 1 ) ); m_Stream.Write( (ushort) book.PagesCount ); m_Stream.Write( (ushort) (titleBuffer.Length + 1) ); m_Stream.Write( titleBuffer, 0, titleBuffer.Length ); m_Stream.Write( (byte) 0 ); // terminate m_Stream.Write( (ushort) (authorBuffer.Length + 1) ); m_Stream.Write( authorBuffer, 0, authorBuffer.Length ); m_Stream.Write( (byte) 0 ); // terminate } } #endif }