Inheritance: Item, ISecurable
		public PublishedBook(BaseBook book) : base(book.ItemID, book.Title, book.Author, book.PagesCount, book.Writable)
		{
			// copy book
			Weight = book.Weight;
			Name = book.Name;
			Hue = book.Hue;
			for(int i = 0; i < Pages.Length; i++)
				Pages[i] = book.Pages[i];
			RePublish();
			m_LastPublished = m_FirstPublished;
		}
Beispiel #2
0
		public static bool IsEmpty( BaseBook book )
		{
			foreach ( BookPageInfo page in book.Pages )
			{
				foreach ( string line in page.Lines )
				{
					if ( line.Trim().Length != 0 )
						return false;
				}
			}
			return true;
		}
Beispiel #3
0
		public static void Copy( BaseBook bookSrc, BaseBook bookDst )
		{
			bookDst.Title = bookSrc.Title;
			bookDst.Author = bookSrc.Author;

			BookPageInfo[] pagesSrc = bookSrc.Pages;
			BookPageInfo[] pagesDst = bookDst.Pages;
			for ( int i = 0; i < pagesSrc.Length && i < pagesDst.Length; i++ )
			{
				BookPageInfo pageSrc = pagesSrc[i];
				BookPageInfo pageDst = pagesDst[i];

				int length = pageSrc.Lines.Length;
				pageDst.Lines = new string[length];

				for ( int j = 0; j < length; j++ )
					pageDst.Lines[j] = pageSrc.Lines[j];
			}
		}
Beispiel #4
0
        public BookPageDetails(BaseBook 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 BookHeader(Mobile from, BaseBook 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
        }
Beispiel #6
0
 public BookGump( Mobile from, BaseBook book )
     : base( 150, 200 )
 {
     if ( book != null )
     {
         m_Book = book;
         AddBackground();
         AddTitlePage();
         AddText();
     }
 }
Beispiel #7
0
        public BaseReadBook(ReadBookInfo bookInfo, int pageCount, String title, String author, BaseBook sourceBook)
            : base(bookInfo.ItemID)
        {
            m_Background = bookInfo.BackgroundID;
            m_CustomArt = bookInfo.CustomArt;
            m_BigBook = bookInfo.BigBook;
            BookContent content = this.DefaultContent;

            if (sourceBook != null)
            {
                m_Author = sourceBook.Author;
                m_Title = sourceBook.Title;
                m_Pages = (BookPageInfo[])sourceBook.Pages.Clone();
                m_Full = true;
            }
            else
            {
                if (content == null)
                {
                    m_Pages = new BookPageInfo[pageCount];
                    for (int i = 0; i < m_Pages.Length; ++i)
                        m_Pages[i] = new BookPageInfo();
                }
                else
                {
                    m_Title = content.Title;
                    m_Author = content.Author;
                    m_Pages = content.Copy();
                }                
                
            }
            if (author != null)
            {
                m_Author = author;
            }
            if (title != null)
            {
                m_Title = title;
            }
            if ((author != null) && (title != null))
            {
                m_Full = true;
            }
            Weight = BookWeight;
        }
Beispiel #8
0
 public bool CopyFromBook(BaseBook book)
 {
     if (IsFull)
     {
         return false;
     }
     m_Author = book.Author;
     m_Title = book.Title;
     m_Pages = (BookPageInfo[])book.Pages.Clone();
     InvalidateProperties();
     return true;
 }
Beispiel #9
0
		private static void CancelUser( BaseBook book )
		{
			m_UseTable.Remove( book );
		}
Beispiel #10
0
			public InternalTargetDst( BaseBook bookSrc ) : base ( 3, false, TargetFlags.None )
			{
				m_BookSrc = bookSrc;
			}
Beispiel #11
0
        public BookHeader(Mobile from, BaseBook 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);

            this.EnsureCapacity(15 + titleBuffer.Length + authorBuffer.Length);

            this.m_Stream.Write((int)book.Serial);
            this.m_Stream.Write((bool)true);
            this.m_Stream.Write((bool)book.Writable && from.InRange(book.GetWorldLocation(), 1));
            this.m_Stream.Write((ushort)book.PagesCount);

            this.m_Stream.Write((ushort)(titleBuffer.Length + 1));
            this.m_Stream.Write(titleBuffer, 0, titleBuffer.Length);
            this.m_Stream.Write((byte)0); // terminate

            this.m_Stream.Write((ushort)(authorBuffer.Length + 1));
            this.m_Stream.Write(authorBuffer, 0, authorBuffer.Length);
            this.m_Stream.Write((byte)0); // terminate
        }
Beispiel #12
0
        public BookPageDetailsForTheIlliterate( BaseBook book )
            : base(0x66)
        {
            EnsureCapacity( 256 );

            m_Stream.Write( (int)    book.Serial );
            m_Stream.Write( (ushort) 1 ); // All burns must fit on one page

            string[] lines = {
                "Hello,",
                "prime",
                "minister"
            };

            m_Stream.Write( (ushort) (1) );
            m_Stream.Write( (ushort) lines.Length );

            for ( int j = 0; j < lines.Length; ++j )
            {
                byte[] buffer = Utility.UTF8.GetBytes( lines[j] );

                m_Stream.Write( buffer, 0, buffer.Length );
                m_Stream.Write( (byte) 0 );
            }
        }
Beispiel #13
0
		public static void CopyBook( BaseBook bookSrc, BaseBook bookDst )
		{
			if (bookSrc == null || bookDst == null)
				return;

			bookDst.Title = bookSrc.Title;
			bookDst.Author = bookSrc.Author;
			bookDst.LastEdited = bookSrc.LastEdited; //erl: LastEdited Serial

			bookDst.ClearPages();
			for(int i = 0; i < bookSrc.Pages.Length; i++)
				bookDst.AddPage(bookSrc.Pages[i]);
		}
Beispiel #14
0
 private static void CancelUser( BaseBook book )
 {
     m_UseTable[book] = null;
 }
Beispiel #15
0
        public BaseReadBook(ReadBookInfo bookInfo, int pageCount, String title, String author, BaseBook sourceBook)
            : base(bookInfo.ItemID)
        {
            m_Background = bookInfo.BackgroundID;
            m_CustomArt  = bookInfo.CustomArt;
            m_BigBook    = bookInfo.BigBook;
            BookContent content = this.DefaultContent;

            if (sourceBook != null)
            {
                m_Author = sourceBook.Author;
                m_Title  = sourceBook.Title;
                m_Pages  = (BookPageInfo[])sourceBook.Pages.Clone();
                m_Full   = true;
            }
            else
            {
                if (content == null)
                {
                    m_Pages = new BookPageInfo[pageCount];
                    for (int i = 0; i < m_Pages.Length; ++i)
                    {
                        m_Pages[i] = new BookPageInfo();
                    }
                }
                else
                {
                    m_Title  = content.Title;
                    m_Author = content.Author;
                    m_Pages  = content.Copy();
                }
            }
            if (author != null)
            {
                m_Author = author;
            }
            if (title != null)
            {
                m_Title = title;
            }
            if ((author != null) && (title != null))
            {
                m_Full = true;
            }
            Weight = BookWeight;
        }
Beispiel #16
0
        public static void ContentChange(NetState state, PacketReader pvSrc)
        {
            Mobile   from = state.Mobile;
            BaseBook book = World.FindItem(pvSrc.ReadInt32()) as BaseBook;

            string ParsedContents = "";

            if (book == null || !book.Writable || !from.InRange(book.GetWorldLocation(), 1))
            {
                return;
            }

            int pageCount = pvSrc.ReadUInt16();

            if (pageCount > 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;
                            }
                            ParsedContents = ParsedContents + lines[j];
                        }

                        book.Pages[index].Lines = lines;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            //erl: log the changed content (applied on page turn or book close, records page changed)
            // ||--

            // Log the changes
            StreamWriter LogFile = new StreamWriter("logs/bookchange.log", true);

            LogFile.WriteLine("{0}: {1}: {2}: x:{3}, y:{4}, z:{5}: {6}: {7}", DateTime.Now, from.Account, from.Name, from.Location.X, from.Location.Y, from.Location.Z, book.Title, ParsedContents);
            LogFile.Close();

            // Update LastEdited property
            book.LastEdited = from.Serial.ToString();

            // ---||
        }
Beispiel #17
0
        public static void Copy( BaseBook bookSrc, BaseBook bookDst, Mobile from )
        {
            bookDst.Title = bookSrc.Title;
            bookDst.Author = bookSrc.Author;

            BookPageInfo[] pagesSrc = bookSrc.Pages;
            BookPageInfo[] pagesDst = bookDst.Pages;
            for ( int i = 0; i < pagesSrc.Length && i < pagesDst.Length; i++ )
            {
                BookPageInfo pageSrc = pagesSrc[i];
                BookPageInfo pageDst = pagesDst[i];

                int length = pageSrc.Lines.Length;
                pageDst.Lines = new string[length];

                for ( int j = 0; j < length; j++ )
                    pageDst.Lines[j] = pageSrc.Lines[j];
            }

            /* mod */
            if ( bookSrc is HTMLBook && bookDst is HTMLBook )
            {
                HTMLBook bookSource = bookSrc as HTMLBook;
                HTMLBook bookDestination = bookDst as HTMLBook;
                if ( bookSource.CharactersPerLineMax == bookDestination.CharactersPerLineMax &&
                    bookSource.MaxLines == bookDestination.MaxLines )
                {
                    if ( bookSource.RequiresFormatting )
                    {
                        bookSource.FixContent();
                        bookSource.RequiresFormatting = false;
                    }
                    /* copy all html style-related data to the target book
                     members are not cloned, but that's irrelevant, because we never modify them anywhere */
                    bookDestination.HTMLContent.WordsTable = new Dictionary<int, List<HTMLTag>>( bookSource.HTMLContent.WordsTable );
                    bookDestination.HTMLContent.LinesTable = new Dictionary<int, List<HTMLTag>>( bookSource.HTMLContent.LinesTable );
                    bookDestination.HTMLContent.PagesTable = new Dictionary<int, List<HTMLTag>>( bookSource.HTMLContent.PagesTable );
                    bookDestination.HTMLContent.Body = new List<HTMLTag>( bookSource.HTMLContent.Body );
                    bookDestination.HTMLContent.HTMLPage = new Dictionary<int, int>( bookSource.HTMLContent.HTMLPage );
                    bookDestination.HTMLContent.HTMLLines = new Dictionary<int, int>( bookSource.HTMLContent.HTMLLines );
                    bookDestination.FixContent();
                    bookDestination.FixStyling();
                    bookDestination.HTMLContent.UpdateCache();
                    bookDestination.RequiresFormatting = false;
                    bookDestination.Writable = bookSource.Writable;
                    if ( bookDestination.Writable == false )
                        bookDestination.SealedBy = from;
                    bookDestination.Cypher = bookSource.Cypher;
                    bookDestination.Language = bookSource.Language;
                }
                else
                {
                    bookDestination.FixContent();
                    from.SendMessage( "Because the books have different page dimensions, you've been able to copy the content, but not the styles." );
                }
            }
            else if ( bookDst is HTMLBook ) // copying from normal -> htmlbook
            {
                ((HTMLBook)bookDst).RequiresFormatting = true;
            }
            /* mod end */
        }
Beispiel #18
0
		private static void ExportBook( BaseBook book )
		{
			World.Broadcast( 0x35, true, "Export file is being generated, please wait." );

			DateTime startTime = DateTime.Now;
			DirectoryInfo di = null;
			if( !Directory.Exists( path ) )
				di = Directory.CreateDirectory( path );
			path = string.Format( @".\Exports\" + name + ".cs" );

			using( StreamWriter sw = File.CreateText( path ) )
			{
				//======================================================================================
				sw.WriteLine( "using System;" );
				sw.WriteLine( "using Server;" );
				sw.WriteLine( "namespace Server.Items" );
				sw.WriteLine( "{" );
				sw.WriteLine( "\tpublic class " + name + " : BaseBook" );
				sw.WriteLine( "\t{" );
				sw.WriteLine( "\t\t[Constructable]" );
				sw.WriteLine( "\t\tpublic " + name + "() : base( " + book.ItemID + ", " + (book.Writable.ToString()).ToLower() + " )" );
				sw.WriteLine( "\t\t{" );
				sw.WriteLine( "\t\t\tTitle = \"" + book.Title + "\";" );
				sw.WriteLine( "\t\t\tAuthor = \"" + book.Author + "\";" );
				sw.WriteLine( "\t\t\tint lastline = 0;" );
				string body = null;
				for( int i = 0; i < book.PagesCount; i++ )
				{
					foreach( string line in book.Pages[i].Lines )
					{
						if( line == "" )
							body += "\n";
						body += line;
					}
				}
				body = Regex.Replace( body, "\n", " \\n " );
				body = Regex.Replace( body, "  ", " " );
				sw.WriteLine( "\t\t\tstring body = \"" + body + "\";" );
				sw.WriteLine( "\t\t\tint p = GetPages(body, ref lastline);" );
				sw.WriteLine( "\t\t\tPages = new BookPageInfo[p];" );
				sw.WriteLine( "\t\t\tfor ( int i = 0; i < Pages.Length; ++i )" );
				sw.WriteLine( "\t\t\t\tPages[i] = new BookPageInfo();" );
				sw.WriteLine( "\t\t\tFormatPages(body, p, lastline);" );
				sw.WriteLine( "\t\t}" );
				sw.WriteLine( "\t\tpublic " + name + "(Serial serial) : base( serial )" );
				sw.WriteLine( "\t\t{" );
				sw.WriteLine( "\t\t}" );
				sw.WriteLine( "\t\tpublic override void Serialize( GenericWriter writer )" );
				sw.WriteLine( "\t\t{" );
				sw.WriteLine( "\t\t\tbase.Serialize( writer );" );
				sw.WriteLine( "\t\t}" );
				sw.WriteLine( "\t\tpublic override void Deserialize( GenericReader reader )" );
				sw.WriteLine( "\t\t{" );
				sw.WriteLine( "\t\t\tbase.Deserialize( reader );" );
				sw.WriteLine( "\t\t}" );
				sw.WriteLine( "\t}" );
				sw.WriteLine( "}" );

				DateTime endTime = DateTime.Now;

				World.Broadcast( 0x35, true, "Export file has been completed. The entire process took {0:F1} seconds.", (endTime - startTime).TotalSeconds );
				path = string.Format( @".\Exports" );
			}
		}
		public static void BaseContentChange( BaseBook book, NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;

			if ( book == null || !book.Writable || !from.InRange( book.GetWorldLocation(), 1 ) )
				return;

			int pageCount = pvSrc.ReadUInt16();

			if ( pageCount > 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;
				}
			}
		}
Beispiel #20
0
        public static void BaseContentChange(BaseBook book, NetState state, PacketReader pvSrc)
        {
            Mobile from = state.Mobile;

            if (book == null)
            {
                return;
            }

            int pageCount = pvSrc.ReadUInt16();

            if (state.IsEnhancedClient && pageCount == 1)
            {
                book.ContentChangeEC(state, pvSrc);
                return;
            }
            else if (book.Writable && from.InRange(book.GetWorldLocation(), 1))
            {
                if (pageCount > 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();
                        int lns;
                        if (Core.EJ)
                        {
                            lns = 10; //line per page EJ Client
                        }
                        else
                        {
                            lns = 8;          //line per page
                        }
                        if (lineCount <= lns) //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;
                    }
                }
            }
        }
        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());
            }
        }
Beispiel #22
0
        public static void ContentChange(NetState state, PacketReader pvSrc)
        {
            // need to deal with actual books
            //string entryText = String.Empty;
            //Mobile from = state.Mobile;

            int pos = pvSrc.Seek(0, SeekOrigin.Current);

            int serial = pvSrc.ReadInt32();

            Item bookitem = World.FindItem(serial);

            // first try it as a normal basebook
            if (bookitem is BaseBook)
            {
                // do the base book content change
                //BaseContentChange(bookitem as BaseBook, state, pvSrc);

                pvSrc.Seek(pos, SeekOrigin.Begin);

                if (PacketHandlerOverrides.ContentChangeParent != null)
                {
                    PacketHandlerOverrides.ContentChangeParent.OnReceive(state, pvSrc);
                }
                else
                {
                    BaseBook.ContentChange(state, pvSrc);
                }

                return;
            }

            // then try it as a text entry book
            var book = bookitem as BaseEntryBook;

            if (book == null)
            {
                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)
                    {
                        var 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;
                }
            }

            var sb = new StringBuilder();

            // add the book lines to the entry string
            for (int i = 0; i < book.PagesCount; ++i)
            {
                foreach (string line in book.Pages[i].Lines)
                {
                    sb.Append(line);
                }
            }

            // send the book text off to be processed by invoking the callback if it is a textentry book
            var tebook = book as XmlTextEntryBook;

            if (tebook != null && tebook.m_bookcallback != null)
            {
                tebook.m_bookcallback(state.Mobile, tebook.m_args, sb.ToString());
            }
        }
Beispiel #23
0
        public static void ContentChange(NetState state, PacketReader pvSrc)
        {
            Mobile   from = state.Mobile;
            BaseBook book = World.FindItem(pvSrc.ReadInt32()) as BaseBook;

            string ParsedContents = "";

            if (book == null || !book.Writable || !from.InRange(book.GetWorldLocation(), 1))
            {
                return;
            }

            int pageCount = pvSrc.ReadUInt16();

            if (pageCount > 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;
                            }
                            ParsedContents = ParsedContents + lines[j];
                        }

                        book.Pages[index].Lines = lines;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            // log the changed content (applied on page turn or book close, records page changed)
            LogHelper Logger  = new LogHelper("bookchange.log", false, true);
            string    sitem   = Logger.Format(LogType.Item, book, null);
            string    smobile = Logger.Format(LogType.Mobile, from, null);

            Logger.Log(string.Format("Book: {0}\nOwner: {1}\nText: {2}", sitem, smobile, ParsedContents));
            Logger.Finish();

            // Update LastEdited property
            book.LastEdited = from.Serial.ToString();
        }
Beispiel #24
0
        public static void ContentChange( NetState state, PacketReader pvSrc, BaseBook book )
        {
            Mobile from = state.Mobile;

            // MOD BEGIN
            if ( book is HTMLBook && book.RootParent != from )
                return;
            // MOD END

            if ( book == null || !book.Writable || !from.InRange( book.GetWorldLocation(), 1 ) )
                return;

            int pageCount = pvSrc.ReadUInt16();

            if ( pageCount > 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;
                }
            }
            // MOD BEGIN
            if ( book is HTMLBook )
                ((HTMLBook)book).RequiresFormatting = true;
            // MOD END
        }
Beispiel #25
0
        public BookPageDetails(BaseBook book)
            : base(0x66)
        {
            this.EnsureCapacity(256);

            this.m_Stream.Write((int)book.Serial);
            this.m_Stream.Write((ushort)book.PagesCount);

            for (int i = 0; i < book.PagesCount; ++i)
            {
                BookPageInfo page = book.Pages[i];

                this.m_Stream.Write((ushort)(i + 1));
                this.m_Stream.Write((ushort)page.Lines.Length);

                for (int j = 0; j < page.Lines.Length; ++j)
                {
                    byte[] buffer = Utility.UTF8.GetBytes(page.Lines[j]);

                    this.m_Stream.Write(buffer, 0, buffer.Length);
                    this.m_Stream.Write((byte)0);
                }
            }
        }
		public static void BaseContentChange( BaseBook book, NetState state, PacketReader pvSrc )
		{
			BaseBook.ContentChange( state, pvSrc, book );
		}
Beispiel #27
0
		private static void SetUser( BaseBook book, Mobile mob )
		{
			m_UseTable[book] = mob;
		}
		private void Publish(Mobile contributor, BaseBook book)
		{
			PublishedBook publishedBook = book as PublishedBook;
			if(publishedBook != null)
			{
				publishedBook.AddContributor(contributor.Name);
				Republish(contributor, publishedBook);
				return;
			}

			// change into published book
			publishedBook = new PublishedBook(book);
			publishedBook.AddContributor(contributor.Name);
			if(!publishedBook.IsPublishable())
			{
				publishedBook.Delete();
				this.SayTo(contributor, "You might want to try writing something of interest first.");
			}
			else if(XmlBook.Save(publishedBook))
			{
                switch (Utility.Random( 3 ) )
                {
                    case 0:
                    {
                        contributor.AddToBackpack(new Gold(1500, 3000));
                        this.SayTo(contributor, "This seems to be a excellent material. Let me see... hm... here - your royalty. You should see the story soon. I am sure it will sell well.");
                        contributor.SendMessage("You receive a good amount of gold.");
                        if (m_Sound)
                            Effects.PlaySound(contributor.Location, contributor.Map, 0x2E5);
                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                    case 1:
                    {
                        contributor.AddToBackpack(new Gold(1000, 1250));
                        this.SayTo(contributor, "This seems to be decent material. Let me see... hm... here - your royalty. You should see the story soon. I hope it will sell well.");
                        contributor.SendMessage("You receive a decent amount of gold.");
                        if (m_Sound)
                            Effects.PlaySound(contributor.Location, contributor.Map, 0x2E5);
                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                    case 2: 
                    {
                        contributor.AddToBackpack(new Gold(100, 500));
                        this.SayTo(contributor, "I don't know if this is good enough to be sold, but let me see... hm... here - I can't give you more for this. I am not sure it will sell at all.");
                        contributor.SendMessage("You receive some gold.");
                        if (m_Sound)
                            Effects.PlaySound(contributor.Location, contributor.Map, 0x2E5);
                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                  
                }


            }
			else
			{
				publishedBook.Delete();
				this.SayTo(contributor, "Our machines are not working right. Check back later.");
			}
		}
Beispiel #29
0
		public static Mobile GetUser( BaseBook book )
		{
			return (Mobile)m_UseTable[book];
		}
Beispiel #30
0
		public static Mobile GetUser( BaseBook book )
		{
			Mobile m;
			m_UseTable.TryGetValue( book, out m );
			return m;
		}
Beispiel #31
0
		private static void StartCS( Mobile from, BaseBook book )
		{
			from.SendMessage( "Writing book to C# file..." );

			try
			{
				string writetitle = String.Format( "Book{0}", book.Serial );

				if ( !Directory.Exists( "CSBooks/" ) )
					Directory.CreateDirectory( "CSBooks/" );

				string filepath = Path.Combine( String.Format( "CSBooks/{0}.cs", writetitle ) );

				if ( File.Exists( filepath ) )
					from.SendMessage( "File already exists for this book.  Dupe this item to change its serial." );
				else
				{
					using ( StreamWriter op = new StreamWriter( filepath ) )
					{
						op.WriteLine("using System;" );
						op.WriteLine("using Server;" );
						op.WriteLine();
						op.WriteLine("namespace Server.Items" );
						op.WriteLine("{" );
						op.WriteLine("	public class {0} : BaseBook", writetitle );
						op.WriteLine("	{" );
						op.WriteLine("		public static readonly BookContent Content = new BookContent" );
						op.WriteLine("			(" );
						op.WriteLine("				\"{0}\", \"{1}\",", book.Title, String.IsNullOrEmpty( book.Author ) ? "unknown" : book.Author );
						BookPageInfo[] pages = book.Pages;
						int lastpage = 0;
						for ( int i = pages.Length-1;i >= 0; i-- )
						{
							if ( pages[i].Lines.Length > 0 ) //This page has something on it
							{
								lastpage = i;
								break;
							}
						}

						for ( int i = 0;i < lastpage; i++ )
						{
							BookPageInfo pageinfo = pages[i];
						op.WriteLine("				new BookPageInfo" );
						op.WriteLine("				(" );
							for ( int j = 0; j < pageinfo.Lines.Length; j++ )
						op.WriteLine("					\"{0}\"{1}", pageinfo.Lines[j], j < pageinfo.Lines.Length-1 ? "," : "" );
						op.WriteLine("				){0}", i < pages.Length-1 ? "," : "" );
						}
						op.WriteLine("			);" );
						op.WriteLine();
						op.WriteLine("		public override BookContent DefaultContent{ get{ return Content; } }" );
						op.WriteLine();
						op.WriteLine("		[Constructable]" );
						op.WriteLine("		public {0}() : base( {1}, false )", writetitle, book.ItemID );
						op.WriteLine("		{" );
						op.WriteLine("			LootType = LootType.Blessed;" );
						op.WriteLine("		{" );
						op.WriteLine("		public {0}( Serial serial ) : base( serial )", writetitle );
						op.WriteLine("		{" );
						op.WriteLine("		}" );
						op.WriteLine();
						op.WriteLine("		public override void Serialize( GenericWriter writer )" );
						op.WriteLine("		{" );
						op.WriteLine("			base.Serialize( writer );");
						op.WriteLine("			writer.WriteEncodedInt( (int)0 ); // version");
						op.WriteLine("		}" );
						op.WriteLine();
						op.WriteLine("		public override void Deserialize( GenericReader reader )" );
						op.WriteLine("		{" );
						op.WriteLine("			base.Deserialize( reader );" );
						op.WriteLine("			int version = reader.ReadEncodedInt();" );
						op.WriteLine("		}" );
						op.WriteLine("	}" );
						op.WriteLine("}" );
					}
					from.SendMessage( "finished." );
				}
			}
			catch ( Exception e )
			{
				from.SendMessage( "failed. {0}", e.ToString() );
			}
		}
Beispiel #32
0
        public static void ContentChange(NetState state, PacketReader pvSrc)
        {
            Mobile   from = state.Mobile;
            BaseBook book = World.FindItem(pvSrc.ReadInt32()) as BaseBook;

            if (book == null || !book.Writable || !from.InRange(book.GetWorldLocation(), 1) || !book.IsAccessibleTo(from))
            {
                return;
            }

            int pageCount = pvSrc.ReadUInt16();

            if (pageCount > 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];

                        lines.SetAll(
                            j =>
                        {
                            string line = pvSrc.ReadUTF8StringSafe();

                            if (!String.IsNullOrWhiteSpace(line))
                            {
                                if (line.Length > 80)
                                {
                                    line = line.Substring(0, 80);
                                }

                                #region AntiAdverts
                                int exit = 100;
                                string detected;

                                while (AntiAdverts.Detect(line, out detected) && !String.IsNullOrWhiteSpace(detected) && --exit >= 0)
                                {
                                    line = line.Replace(detected, new String('*', detected.Length));
                                }
                                #endregion
                            }

                            return(line);
                        });

                        book.Pages[index].Lines = lines;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }