context: using System;
  using System.Collections;
  using System.Collections.Generic;
  using Server;
  using Server.ContextMenus;
  using Server.Engines.Housing;
  using Server.Engines.Housing.Multis;
  using Server.Gumps;
  using Server.Multis;
  using Server.Prompts;
  using Server.Mobiles;
  using Server.Network;
  
  namespace Server.Items
  {
  	public class PlayerBBSouth : BasePlayerBB
  	{
  		public override int LabelNumber { get { return 1062421; } } // bulletin board (south)
  
  		[Constructable]
  		public PlayerBBSouth()
  			: base( 0x2311 )
  		{
  			Weight = 15.0;
  		}
  
  		public PlayerBBSouth( Serial serial )
  			: base( serial )
  		{
  		}
  
  		public override void Serialize( GenericWriter writer )
  		{
  			base.Serialize( writer );
  
  			writer.Write( (int) 0 ); // version
  		}
  
  		public override void Deserialize( GenericReader reader )
  		{
  			base.Deserialize( reader );
  
  			/*int version = */
  			reader.ReadInt();
  		}
  	}
  
  	public class PlayerBBEast : BasePlayerBB
  	{
  		public override int LabelNumber { get { return 1062420; } } // bulletin board (east)
  
  		[Constructable]
  		public PlayerBBEast()
  			: base( 0x2312 )
  		{
  			Weight = 15.0;
  		}
  
  		public PlayerBBEast( Serial serial )
  			: base( serial )
  		{
  		}
  
  		public override void Serialize( GenericWriter writer )
  		{
  			base.Serialize( writer );
  
  			writer.Write( (int) 0 ); // version
  		}
  
  		public override void Deserialize( GenericReader reader )
  		{
  			base.Deserialize( reader );
  
  			/*int version = */
  			reader.ReadInt();
  		}
  	}
  
  	public abstract class BasePlayerBB : Item, ISecurable
  	{
  		private PlayerBBMessage m_Greeting;
  		private ArrayList m_Messages;
  		private string m_Title;
  		private SecureLevel m_Level;
  
  		public ArrayList Messages { get { return m_Messages; } }
  
  		public PlayerBBMessage Greeting { get { return m_Greeting; } set { m_Greeting = value; } }
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public string Title { get { return m_Title; } set { m_Title = value; } }
  
  		[CommandProperty( AccessLevel.GameMaster )]
  		public SecureLevel Level { get { return m_Level; } set { m_Level = value; } }
  
  		public BasePlayerBB( int itemID )
  			: base( itemID )
  		{
  			m_Messages = new ArrayList();
  			m_Level = SecureLevel.Anyone;
  		}
  
  		public BasePlayerBB( Serial serial )
  			: base( serial )
  		{
  		}
  
  		public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
  		{
  			base.GetContextMenuEntries( from, list );
  			SetSecureLevelEntry.AddTo( from, this, list );
  		}
  
  		public override void Serialize( GenericWriter writer )
  		{
  			base.Serialize( writer );
  
  			writer.Write( (int) 1 );
  
  			writer.Write( (int) m_Level );
  
  			writer.Write( m_Title );
  
  			if ( m_Greeting != null )
  			{
  				writer.Write( true );
  				m_Greeting.Serialize( writer );
  			}
  			else
  			{
  				writer.Write( false );
  			}
  
  			writer.WriteEncodedInt( m_Messages.Count );
  
  			for ( int i = 0; i < m_Messages.Count; ++i )
  				( (PlayerBBMessage) m_Messages[i] ).Serialize( writer );
  		}
  
  		public override void Deserialize( GenericReader reader )
  		{
  			base.Deserialize( reader );
  
  			int version = reader.ReadInt();
  
  			switch ( version )
  			{
  				case 1:
  					{
  						m_Level = (SecureLevel) reader.ReadInt();
  						goto case 0;
  					}
  				case 0:
  					{
  						if ( version < 1 )
  							m_Level = SecureLevel.Anyone;
  
  						m_Title = reader.ReadString();
  
  						if ( reader.ReadBool() )
  							m_Greeting = new PlayerBBMessage( reader );
  
  						int count = reader.ReadEncodedInt();
  
  						m_Messages = new ArrayList( count );
  
  						for ( int i = 0; i < count; ++i )
  							m_Messages.Add( new PlayerBBMessage( reader ) );
  
  						break;
  					}
  			}
  		}
  
  		public static bool CheckAccess( IHouse house, Mobile from )
  		{
  			if ( house.Public )
  				return !house.IsBanned( from );
  
  			return house.HasAccess( from );
  		}
  
  		public override void OnDoubleClick( Mobile from )
  		{
  			var house = HousingHelper.FindHouseAt( this );
  
  			if ( house == null || !house.IsLockedDown( this ) )
  				from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable.
  			else if ( !from.InRange( this.GetWorldLocation(), 2 ) || !from.InLOS( this ) )
  				from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
  			else if ( CheckAccess( house, from ) )
  				from.SendGump( new PlayerBBGump( from, house, this, 0 ) );
  		}
  
  		public class PostPrompt : Prompt
  		{
  			public override int MessageCliloc { get { return m_Cliloc; } }
  
  			private int m_Page;
  			private IHouse m_House;
  			private BasePlayerBB m_Board;
  			private bool m_Greeting;
  			private int m_Cliloc;
  
  			public PostPrompt( int page, IHouse house, BasePlayerBB board, bool greeting, int cliloc )
  				: base( house )
  			{
  				m_Page = page;
  				m_House = house;
  				m_Board = board;
  				m_Greeting = greeting;
  				m_Cliloc = cliloc;
  			}
  
  			public override void OnCancel( Mobile from )
  			{
  				OnResponse( from, "" );
  			}
  
  			public override void OnResponse( Mobile from, string text )
  			{
  				int page = m_Page;
  				IHouse house = m_House;
  				BasePlayerBB board = m_Board;
  
  				if ( house == null || !house.IsLockedDown( board ) )
  				{
  					from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable.
  					return;
  				}
  				else if ( !from.InRange( board.GetWorldLocation(), 2 ) || !from.InLOS( board ) )
  				{
  					from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
  					return;
  				}
  				else if ( !CheckAccess( house, from ) )
  				{
  					from.SendLocalizedMessage( 1062398 ); // You are not allowed to post to this bulletin board.
  					return;
  				}
  				else if ( m_Greeting && !house.IsOwner( from ) )
  				{
  					return;
  				}
  
  				text = text.Trim();
  
  				if ( text.Length > 255 )
  					text = text.Substring( 0, 255 );
  
  				if ( text.Length > 0 )
  				{
  					PlayerBBMessage message = new PlayerBBMessage( DateTime.Now, from, text );
  
  					if ( m_Greeting )
  					{
  						board.Greeting = message;
  					}
  					else
  					{
  						board.Messages.Add( message );
  
  						if ( board.Messages.Count > 50 )
  						{
  							board.Messages.RemoveAt( 0 );
  
  							if ( page > 0 )
  								--page;
  						}
  					}
  				}
  
  				from.SendGump( new PlayerBBGump( from, house, board, page ) );
  			}
  		}
  
  		public class SetTitlePrompt : Prompt
  		{
  			// Enter new title:
  			public override int MessageCliloc { get { return 1062402; } }
  
  			private int m_Page;
  			private IHouse m_House;
  			private BasePlayerBB m_Board;
  
  			public SetTitlePrompt( int page, IHouse house, BasePlayerBB board )
  				: base( board )
  			{
  				m_Page = page;
  				m_House = house;
  				m_Board = board;
  			}
  
  			public override void OnCancel( Mobile from )
  			{
  				OnResponse( from, "" );
  			}
  
  			public override void OnResponse( Mobile from, string text )
  			{
  				int page = m_Page;
  				IHouse house = m_House;
  				BasePlayerBB board = m_Board;
  
  				if ( house == null || !house.IsLockedDown( board ) )
  				{
  					from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable.
  					return;
  				}
  				else if ( !from.InRange( board.GetWorldLocation(), 2 ) || !from.InLOS( board ) )
  				{
  					from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
  					return;
  				}
  				else if ( !CheckAccess( house, from ) )
  				{
  					from.SendLocalizedMessage( 1062398 ); // You are not allowed to post to this bulletin board.
  					return;
  				}
  
  				text = text.Trim();
  
  				if ( text.Length > 255 )
  				{
  
gt: 					text = text.Substring( 0, 255 );