ReadUTF8StringSafe() public méthode

public ReadUTF8StringSafe ( ) : string
Résultat string
		public static void UnicodeSpeech( NetState state, PacketReader pvSrc )
		{
			Mobile from = state.Mobile;

			MessageType type = (MessageType)pvSrc.ReadByte();
			int hue = pvSrc.ReadInt16();
			pvSrc.ReadInt16(); // font
			string lang = pvSrc.ReadString( 4 );
			string text;

			bool isEncoded = (type & MessageType.Encoded) != 0;
			int[] keywords;

			if ( isEncoded )
			{
				int value = pvSrc.ReadInt16();
				int count = (value & 0xFFF0) >> 4;
				int hold = value & 0xF;

				if ( count < 0 || count > 50 )
					return;

				KeywordList keyList = m_KeywordList;

				for ( int i = 0; i < count; ++i )
				{
					int speechID;

					if ( (i & 1) == 0 )
					{
						hold <<= 8;
						hold |= pvSrc.ReadByte();
						speechID = hold;
						hold = 0;
					}
					else
					{
						value = pvSrc.ReadInt16();
						speechID = (value & 0xFFF0) >> 4;
						hold = value & 0xF;
					}

					if ( !keyList.Contains( speechID ) )
						keyList.Add( speechID );
				}

				text = pvSrc.ReadUTF8StringSafe();

				keywords = keyList.ToArray();
			}
			else
			{
				text = pvSrc.ReadUnicodeStringSafe();

				keywords = m_EmptyInts;
			}

			text = text.Trim();

			if ( text.Length <= 0 || text.Length > 128 )
				return;

			type &= ~MessageType.Encoded;

			if ( !Enum.IsDefined( typeof( MessageType ), type ) )
				type = MessageType.Regular;

			from.Language = lang;
			from.DoSpeech( text, keywords, type, Utility.ClipDyedHue( hue ) );
		}
        public static void BBPostMessage( Mobile from, BaseBulletinBoard board, PacketReader pvSrc )
        {
            BulletinMessage thread = World.FindItem( pvSrc.ReadInt32() ) as BulletinMessage;

            if ( thread != null && thread.Parent != board )
                thread = null;

            int breakout = 0;

            while ( thread != null && thread.Thread != null && breakout++ < 10 )
                thread = thread.Thread;

            DateTime lastPostTime = DateTime.MinValue;

            if ( board.GetLastPostTime( from, ( thread == null ), ref lastPostTime ) )
            {
                if ( !CheckTime( lastPostTime, (thread == null ? ThreadCreateTime : ThreadReplyTime) ) )
                {
                    if ( thread == null )
                        from.SendMessage( "You must wait {0} before creating a new thread.", FormatTS( ThreadCreateTime ) );
                    else
                        from.SendMessage( "You must wait {0} before replying to another thread.", FormatTS( ThreadReplyTime ) );

                    return;
                }
            }

            string subject = pvSrc.ReadUTF8StringSafe( pvSrc.ReadByte() );

            if ( subject.Length == 0 )
                return;

            string[] lines = new string[pvSrc.ReadByte()];

            if ( lines.Length == 0 )
                return;

            for ( int i = 0; i < lines.Length; ++i )
                lines[i] = pvSrc.ReadUTF8StringSafe( pvSrc.ReadByte() );

            board.PostMessage( from, thread, subject, lines );
        }
Exemple #3
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];

                        for (int j = 0; j < lineCount; ++j)
                            if ((lines[j] = pvSrc.ReadUTF8StringSafe()).Length >= 80)
                                return;

                        book.Pages[index].Lines = lines;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
Exemple #4
0
        public static void HeaderChange(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

            int titleLength = pvSrc.ReadUInt16();

            if (titleLength > 60)
                return;

            string title = pvSrc.ReadUTF8StringSafe(titleLength);

            int authorLength = pvSrc.ReadUInt16();

            if (authorLength > 30)
                return;

            string author = pvSrc.ReadUTF8StringSafe(authorLength);

            book.Title = Utility.FixHtml(title);
            book.Author = Utility.FixHtml(author);
        }
		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());
			}
		}
Exemple #6
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();

			// ---||

		}
		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)
					{
						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;
				}
			}
		}
		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());
			}
		}
Exemple #9
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
        }
Exemple #10
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;
				}
			}
		}
Exemple #11
0
		public static void HeaderChange( 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

			int titleLength = pvSrc.ReadUInt16();

			if ( titleLength > 60 )
				return;

			string title = pvSrc.ReadUTF8StringSafe( titleLength );

			int authorLength = pvSrc.ReadUInt16();

			if ( authorLength > 30 )
				return;

			string author = pvSrc.ReadUTF8StringSafe( authorLength );

			title = Utility.FixHtml( title );
			author = Utility.FixHtml( author );

			#region AntiAdverts
			if (!String.IsNullOrWhiteSpace(title))
			{
				int exit = 100;
				string detected;

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

			if (!String.IsNullOrWhiteSpace(author))
			{
				int exit = 100;
				string detected;

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

			book.Title = title;
			book.Author = author;
		}