context: /***************************************************************************
   *                                EventSink.cs
   *                            -------------------
   *   begin                : May 1, 2002
   *   copyright            : (C) The RunUO Software Team
   *   email                : info@runuo.com
   *
   *   $Id: EventSink.cs 644 2010-12-23 09:18:45Z asayre $
   *
   ***************************************************************************/
  
  /***************************************************************************
   *
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   ***************************************************************************/
  
  using System;
  using System.Net;
  using System.Net.Sockets;
  using System.Collections;
  using System.Collections.Generic;
  using Server;
  using Server.Items;
  using Server.Accounting;
  using Server.Network;
  using Server.Guilds;
  using Server.Commands;
  
  namespace Server
  {
  	public delegate void CharacterCreatedEventHandler( CharacterCreatedEventArgs e );
  	public delegate void OpenDoorMacroEventHandler( OpenDoorMacroEventArgs e );
  	public delegate void SpeechEventHandler( SpeechEventArgs e );
  	public delegate void LoginEventHandler( LoginEventArgs e );
  	public delegate void ServerListEventHandler( ServerListEventArgs e );
  	public delegate void MovementEventHandler( MovementEventArgs e );
  	public delegate void HungerChangedEventHandler( HungerChangedEventArgs e );
  	public delegate void CrashedEventHandler( CrashedEventArgs e );
  	public delegate void ShutdownEventHandler( ShutdownEventArgs e );
  	public delegate void HelpRequestEventHandler( HelpRequestEventArgs e );
  	public delegate void DisarmRequestEventHandler( DisarmRequestEventArgs e );
  	public delegate void StunRequestEventHandler( StunRequestEventArgs e );
  	public delegate void OpenSpellbookRequestEventHandler( OpenSpellbookRequestEventArgs e );
  	public delegate void CastSpellRequestEventHandler( CastSpellRequestEventArgs e );
  	public delegate void AnimateRequestEventHandler( AnimateRequestEventArgs e );
  	public delegate void LogoutEventHandler( LogoutEventArgs e );
  	public delegate void SocketConnectEventHandler( SocketConnectEventArgs e );
  	public delegate void ConnectedEventHandler( ConnectedEventArgs e );
  	public delegate void DisconnectedEventHandler( DisconnectedEventArgs e );
  	public delegate void RenameRequestEventHandler( RenameRequestEventArgs e );
  	public delegate void PlayerDeathEventHandler( PlayerDeathEventArgs e );
  	public delegate void VirtueGumpRequestEventHandler( VirtueGumpRequestEventArgs e );
  	public delegate void VirtueItemRequestEventHandler( VirtueItemRequestEventArgs e );
  	public delegate void VirtueMacroRequestEventHandler( VirtueMacroRequestEventArgs e );
  	public delegate void ChatRequestEventHandler( ChatRequestEventArgs e );
  	public delegate void AccountLoginEventHandler( AccountLoginEventArgs e );
  	public delegate void PaperdollRequestEventHandler( PaperdollRequestEventArgs e );
  	public delegate void ProfileRequestEventHandler( ProfileRequestEventArgs e );
  	public delegate void ChangeProfileRequestEventHandler( ChangeProfileRequestEventArgs e );
  	public delegate void AggressiveActionEventHandler( AggressiveActionEventArgs e );
  	public delegate void GameLoginEventHandler( GameLoginEventArgs e );
  	public delegate void DeleteRequestEventHandler( DeleteRequestEventArgs e );
  	public delegate void WorldLoadEventHandler();
  	public delegate void WorldSaveEventHandler( WorldSaveEventArgs e );
  	public delegate void SetAbilityEventHandler( SetAbilityEventArgs e );
  	public delegate void FastWalkEventHandler( FastWalkEventArgs e );
  	public delegate void ServerStartedEventHandler();
  	public delegate BaseGuild CreateGuildHandler( CreateGuildEventArgs e );
  	public delegate void GuildGumpRequestHandler( GuildGumpRequestArgs e );
  	public delegate void QuestGumpRequestHandler( QuestGumpRequestArgs e );
  	public delegate void ClientVersionReceivedHandler( ClientVersionReceivedArgs e );
  
  	public class ClientVersionReceivedArgs : EventArgs
  	{
  		private NetState m_State;
  		private ClientVersion m_Version;
  
  		public NetState State { get { return m_State; } }
  		public ClientVersion Version { get { return m_Version; } }
  
  		public ClientVersionReceivedArgs( NetState state, ClientVersion cv )
  		{
  			m_State = state;
  			m_Version = cv;
  		}
  	}
  
  	public class CreateGuildEventArgs : EventArgs
  	{
  		private int m_Id;
  		public int Id { get { return m_Id; } set { m_Id = value; } }
  
  		public CreateGuildEventArgs( int id )
  		{
  			m_Id = id;
  		}
  	}
  
  	public class GuildGumpRequestArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public GuildGumpRequestArgs( Mobile mobile )
  		{
  			m_Mobile = mobile;
  		}
  	}
  
  	public class QuestGumpRequestArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile { get { return m_Mobile; } }
  
  		public QuestGumpRequestArgs( Mobile mobile )
  		{
  			m_Mobile = mobile;
  		}
  	}
  
  	public class SetAbilityEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  		private int m_Index;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  		public int Index{ get{ return m_Index; } }
  
  		public SetAbilityEventArgs( Mobile mobile, int index )
  		{
  			m_Mobile = mobile;
  			m_Index = index;
  		}
  	}
  
  	public class DeleteRequestEventArgs : EventArgs
  	{
  		private NetState m_State;
  		private int m_Index;
  
  		public NetState State{ get{ return m_State; } }
  		public int Index{ get{ return m_Index; } }
  
  		public DeleteRequestEventArgs( NetState state, int index )
  		{
  			m_State = state;
  			m_Index = index;
  		}
  	}
  
  	public class GameLoginEventArgs : EventArgs
  	{
  		private NetState m_State;
  		private string m_Username;
  		private string m_Password;
  		private bool m_Accepted;
  		private CityInfo[] m_CityInfo;
  
  		public NetState State{ get{ return m_State; } }
  		public string Username{ get{ return m_Username; } }
  		public string Password{ get{ return m_Password; } }
  		public bool Accepted{ get{ return m_Accepted; } set{ m_Accepted = value; } }
  		public CityInfo[] CityInfo{ get{ return m_CityInfo; } set{ m_CityInfo = value; } }
  
  		public GameLoginEventArgs( NetState state, string un, string pw )
  		{
  			m_State = state;
  			m_Username = un;
  			m_Password = pw;
  		}
  	}
  
  	public class AggressiveActionEventArgs : EventArgs
  	{
  		private Mobile m_Aggressed;
  		private Mobile m_Aggressor;
  		private bool m_Criminal;
  
  		public Mobile Aggressed{ get{ return m_Aggressed; } }
  		public Mobile Aggressor{ get{ return m_Aggressor; } }
  		public bool Criminal{ get{ return m_Criminal; } }
  
  		private static Queue<AggressiveActionEventArgs> m_Pool = new Queue<AggressiveActionEventArgs>();
  
  		public static AggressiveActionEventArgs Create( Mobile aggressed, Mobile aggressor, bool criminal )
  		{
  			AggressiveActionEventArgs args;
  
  			if ( m_Pool.Count > 0 )
  			{
  				args = m_Pool.Dequeue();
  
  				args.m_Aggressed = aggressed;
  				args.m_Aggressor = aggressor;
  				args.m_Criminal = criminal;
  			}
  			else
  			{
  				args = new AggressiveActionEventArgs( aggressed, aggressor, criminal );
  			}
  
  			return args;
  		}
  
  		private AggressiveActionEventArgs( Mobile aggressed, Mobile aggressor, bool criminal )
  		{
  			m_Aggressed = aggressed;
  			m_Aggressor = aggressor;
  			m_Criminal = criminal;
  		}
  
  		public void Free()
  		{
  			m_Pool.Enqueue( this );
  		}
  	}
  
  	public class ProfileRequestEventArgs : EventArgs
  	{
  		private Mobile m_Beholder;
  		private Mobile m_Beheld;
  
  		public Mobile Beholder{ get{ return m_Beholder; } }
  		public Mobile Beheld{ get{ return m_Beheld; } }
  
  		public ProfileRequestEventArgs( Mobile beholder, Mobile beheld )
  		{
  			m_Beholder = beholder;
  			m_Beheld = beheld;
  		}
  	}
  
  	public class ChangeProfileRequestEventArgs : EventArgs
  	{
  		private Mobile m_Beholder;
  		private Mobile m_Beheld;
  		private string m_Text;
  
  		public Mobile Beholder{ get{ return m_Beholder; } }
  		public Mobile Beheld{ get{ return m_Beheld; } }
  		public string Text{ get{ return m_Text; } }
  
  		public ChangeProfileRequestEventArgs( Mobile beholder, Mobile beheld, string text )
  		{
  			m_Beholder = beholder;
  			m_Beheld = beheld;
  			m_Text = text;
  		}
  	}
  
  	public class PaperdollRequestEventArgs : EventArgs
  	{
  		private Mobile m_Beholder;
  		private Mobile m_Beheld;
  
  		public Mobile Beholder{ get{ return m_Beholder; } }
  		public Mobile Beheld{ get{ return m_Beheld; } }
  
  		public PaperdollRequestEventArgs( Mobile beholder, Mobile beheld )
  		{
  			m_Beholder = beholder;
  			m_Beheld = beheld;
  		}
  	}
  
  	public class AccountLoginEventArgs : EventArgs
  	{
  		private NetState m_State;
  		private string m_Username;
  		private string m_Password;
  
  		private bool m_Accepted;
  		private ALRReason m_RejectReason;
  
  		public NetState State{ get{ return m_State; } }
  		public string Username{ get{ return m_Username; } }
  		public string Password{ get{ return m_Password; } }
  		public bool Accepted{ get{ return m_Accepted; } set{ m_Accepted = value; } }
  		public ALRReason RejectReason{ get{ return m_RejectReason; } set{ m_RejectReason = value; } }
  
  		public AccountLoginEventArgs( NetState state, string username, string password )
  		{
  			m_State = state;
  			m_Username = username;
  			m_Password = password;
  		}
  	}
  
  	public class VirtueItemRequestEventArgs : EventArgs
  	{
  		private Mobile m_Beholder;
  		private Mobile m_Beheld;
  		private int m_GumpID;
  
  		public Mobile Beholder{ get{ return m_Beholder; } }
  		public Mobile Beheld{ get{ return m_Beheld; } }
  		public int GumpID{ get{ return m_GumpID; } }
  
  		public VirtueItemRequestEventArgs( Mobile beholder, Mobile beheld, int gumpID )
  		{
  			m_Beholder = beholder;
  			m_Beheld = beheld;
  			m_GumpID = gumpID;
  		}
  	}
  
  	public class VirtueGumpRequestEventArgs : EventArgs
  	{
  		private Mobile m_Beholder, m_Beheld;
  
  		public Mobile Beholder{ get{ return m_Beholder; } }
  		public Mobile Beheld{ get{ return m_Beheld; } }
  
  		public VirtueGumpRequestEventArgs( Mobile beholder, Mobile beheld )
  		{
  			m_Beholder = beholder;
  			m_Beheld = beheld;
  		}
  	}
  
  	public class VirtueMacroRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  		private int m_VirtueID;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  		public int VirtueID{ get{ return m_VirtueID; } }
  
  		public VirtueMacroRequestEventArgs( Mobile mobile, int virtueID )
  		{
  			m_Mobile = mobile;
  			m_VirtueID = virtueID;
  		}
  	}
  
  	public class ChatRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public ChatRequestEventArgs( Mobile mobile )
  		{
  			m_Mobile = mobile;
  		}
  	}
  
  	public class PlayerDeathEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public PlayerDeathEventArgs( Mobile mobile )
  		{
  			m_Mobile = mobile;
  		}
  	}
  
  	public class RenameRequestEventArgs : EventArgs
  	{
  		private Mobile m_From, m_Target;
  		private string m_Name;
  
  		public Mobile From{ get{ return m_From; } }
  		public Mobile Target{ get{ return m_Target; } }
  		public string Name{ get{ return m_Name; } }
  
  		public RenameRequestEventArgs( Mobile from, Mobile target, string name )
  		{
  			m_From = from;
  			m_Target = target;
  			m_Name = name;
  		}
  	}
  
  	public class LogoutEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public LogoutEventArgs( Mobile m )
  		{
  			m_Mobile = m;
  		}
  	}
  
  	public class SocketConnectEventArgs : EventArgs
  	{
  		private Socket m_Socket;
  		private bool m_AllowConnection;
  
  		public Socket Socket{ get{ return m_Socket; } }
  		public bool AllowConnection{ get { return m_AllowConnection; } set { m_AllowConnection = value; } }
  
  		public SocketConnectEventArgs( Socket s )
  		{
  			m_Socket = s;
  			m_AllowConnection = true;
  		}
  	}
  
  	public class ConnectedEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public ConnectedEventArgs( Mobile m )
  		{
  			m_Mobile = m;
  		}
  	}
  
  	public class DisconnectedEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public DisconnectedEventArgs( Mobile m )
  		{
  			m_Mobile = m;
  		}
  	}
  
  	public class AnimateRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  		private string m_Action;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  		public string Action{ get{ return m_Action; } }
  
  		public AnimateRequestEventArgs( Mobile m, string action )
  		{
  			m_Mobile = m;
  			m_Action = action;
  		}
  	}
  
  	public class CastSpellRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  		private Item m_Spellbook;
  		private int m_SpellID;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  		public Item Spellbook{ get{ return m_Spellbook; } }
  		public int SpellID{ get{ return m_SpellID; } }
  
  		public CastSpellRequestEventArgs( Mobile m, int spellID, Item book )
  		{
  			m_Mobile = m;
  			m_Spellbook = book;
  			m_SpellID = spellID;
  		}
  	}
  
  	public class OpenSpellbookRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  		private int m_Type;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  		public int Type{ get{ return m_Type; } }
  
  		public OpenSpellbookRequestEventArgs( Mobile m, int type )
  		{
  			m_Mobile = m;
  			m_Type = type;
  		}
  	}
  
  	public class StunRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public StunRequestEventArgs( Mobile m )
  		{
  			m_Mobile = m;
  		}
  	}
  
  	public class DisarmRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public DisarmRequestEventArgs( Mobile m )
  		{
  			m_Mobile = m;
  		}
  	}
  
  	public class HelpRequestEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  
  		public HelpRequestEventArgs( Mobile m )
  		{
  			m_Mobile = m;
  		}
  	}
  
  	public class ShutdownEventArgs : EventArgs
  	{
  		public ShutdownEventArgs()
  		{
  		}
  	}
  
  	public class CrashedEventArgs : EventArgs
  	{
  		private Exception m_Exception;
  		private bool m_Close;
  
  		public Exception Exception{ get{ return m_Exception; } }
  		public bool Close{ get{ return m_Close; } set{ m_Close = value; } }
  
  		public CrashedEventArgs( Exception e )
  		{
  			m_Exception = e;
  		}
  	}
  
  	public class HungerChangedEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  		private int m_OldValue;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  		public int OldValue{ get{ return m_OldValue; } }
  
  		public HungerChangedEventArgs( Mobile mobile, int oldValue )
  		{
  			m_Mobile = mobile;
  			m_OldValue = oldValue;
  		}
  	}
  
  	public class MovementEventArgs : EventArgs
  	{
  		private Mobile m_Mobile;
  		private Direction m_Direction;
  		private bool m_Blocked;
  
  		public Mobile Mobile{ get{ return m_Mobile; } }
  		public Direction Direction{ get{ return m_Direction; } }
  		public bool Blocked{ get{ return m_Blocked; } set{ m_Blocked = value; } }
  
  		private static Queue<MovementEventArgs> m_Pool = new Queue<MovementEventArgs>();
  
  		public static MovementEventArgs Create( Mobile mobile, Direction dir )
  		{
  			MovementEventArgs args;
  
  			if ( m_Pool.Count > 0 )
  			{
  				args = m_Pool.Dequeue();
  
  				args.m_Mobile = mobile;
  				args.m_Direction = dir;
  				args.m_Blocked = false;
  			}
  			else
  			{
  
gt: 				args = new MovementEventArgs( mobile, dir );