示例#1
0
        public EntryBookPageDetails(BaseEntryBook book)
            : base(0x66)
        {
            EnsureCapacity(256);

            m_Stream.Write(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);

                foreach (byte[] buffer in page.Lines.Select(line => Utility.UTF8.GetBytes(line)))
                {
                    m_Stream.Write(buffer, 0, buffer.Length);
                    m_Stream.Write((byte)0);
                }
            }
        }
        public EntryBookHeader(Mobile from, BaseEntryBook book) : base(0xD4)
        {
            string title  = book.Title == null ? "" : book.Title;
            string author = book.Author == null ? "" : book.Author;

            byte[] titleBuffer  = Encoding.UTF8.GetBytes(title);
            byte[] authorBuffer = Encoding.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
        }
        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 = Encoding.UTF8.GetBytes(page.Lines[j]);

                    m_Stream.Write(buffer, 0, buffer.Length);
                    m_Stream.Write((byte)0);
                }
            }
        }
        public static void ContentChange(NetState state, PacketReader pvSrc)
        {
            // need to deal with actual books
            string entryText = String.Empty;
            Mobile from      = state.Mobile;

            int serial = pvSrc.ReadInt32();

            BaseEntryBook book = World.FindItem(serial) as BaseEntryBook;

            if (book == null)
            {
                // try it as a basebook
                BaseBook basebook = World.FindItem(serial) as BaseBook;
                if (basebook == null)
                {
                    // didnt find that either
                    return;
                }
                else
                {
                    // do the base book content change
                    BaseContentChange(basebook, state, pvSrc);
                    return;
                }
            }
            // get the number of available pages in the book
            int pageCount = pvSrc.ReadUInt16();

            if (pageCount > 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.Pages[i].Lines.Length; j++)
                {
                    sb.Append(book.Pages[i].Lines[j]);
                }
            }
            // send the book text off to be processed by invoking the callback if it is a textentry book
            XmlTextEntryBook tebook = book as XmlTextEntryBook;

            if (tebook != null && tebook.m_bookcallback != null)
            {
                tebook.m_bookcallback(state.Mobile, tebook.m_args, sb.ToString());
            }
        }
		public EntryBookHeader( Mobile from, BaseEntryBook book ) : base ( 0xD4 )
		{
			string title = book.Title == null ? "" : book.Title;
			string author = book.Author == null ? "" : book.Author;

			byte[] titleBuffer = Encoding.UTF8.GetBytes( title );
			byte[] authorBuffer = Encoding.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
		}
		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 = Encoding.UTF8.GetBytes( page.Lines[j] );

					m_Stream.Write( buffer, 0, buffer.Length );
					m_Stream.Write( (byte) 0 );
				}
			}
		}
		public EntryBookPageDetails(BaseEntryBook book)
			: base(0x66)
		{
			EnsureCapacity(256);

			m_Stream.Write(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);

				foreach (byte[] buffer in page.Lines.Select(line => Utility.UTF8.GetBytes(line)))
				{
					m_Stream.Write(buffer, 0, buffer.Length);
					m_Stream.Write((byte)0);
				}
			}
		}