Пример #1
0
        public static void OldHeaderChange(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;
            }

            pvSrc.Seek(4, SeekOrigin.Current); // Skip flags and page count

            string title  = pvSrc.ReadStringSafe(60);
            string author = pvSrc.ReadStringSafe(30);

            book.Title  = Utility.FixHtml(title);
            book.Author = Utility.FixHtml(author);
        }
Пример #2
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
        }
Пример #3
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
        }
Пример #4
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();
        }
Пример #5
0
		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;
				}
			}
		}
Пример #6
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
        }
Пример #7
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;
                    }
                }
            }
        }
Пример #8
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();

            // ---||
        }
Пример #9
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;
                }
            }
        }