From 9e586bf2f38498788bb76db87740315566fc58a9 Mon Sep 17 00:00:00 2001 From: mark Date: Sun, 29 Jul 2007 00:58:34 +0000 Subject: [PATCH] Rewrite exit code, shutdown handlers etc --- Scripts/Commands/Handlers.cs | 40 +++++------------------------- Scripts/Gumps/AdminGump.cs | 11 +++----- Scripts/Misc/AutoRestart.cs | 3 +-- Scripts/Misc/ClientVerification.cs | 2 +- Server/Main.cs | 30 ++++++++++++++-------- Server/Mobile.cs | 2 +- 6 files changed, 33 insertions(+), 55 deletions(-) diff --git a/Scripts/Commands/Handlers.cs b/Scripts/Commands/Handlers.cs index 3e4cab2a5..21ecfc5a4 100644 --- a/Scripts/Commands/Handlers.cs +++ b/Scripts/Commands/Handlers.cs @@ -207,7 +207,7 @@ namespace Server.Commands { List list = (List)state; - CommandLogging.WriteLine( from, "{0} {1} deleting {2} objects", from.AccessLevel, CommandLogging.Format( from ), list.Count ); + CommandLogging.WriteLine( from, "{0} {1} deleting {2} object{3}", from.AccessLevel, CommandLogging.Format( from ), list.Count, list.Count == 1 ? "" : "s" ); NetState.Pause(); @@ -248,7 +248,7 @@ namespace Server.Commands if ( list.Count > 0 ) { - CommandLogging.WriteLine( e.Mobile, "{0} {1} starting facet clear of {2} ({3} objects)", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), map, list.Count ); + CommandLogging.WriteLine( e.Mobile, "{0} {1} starting facet clear of {2} ({3} object{4})", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), map, list.Count, list.Count == 1 ? "" : "s" ); e.Mobile.SendGump( new WarningGump( 1060635, 30720, @@ -396,7 +396,7 @@ namespace Server.Commands { m_Mobile = m; - CommandLogging.WriteLine( from, "{0} {1} getting equip for {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( m ) ); + CommandLogging.WriteLine( from, "{0} {1} viewing equipment of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( m ) ); } public override void OnResponse( NetState state, int index ) @@ -429,17 +429,17 @@ namespace Server.Commands { if ( index == 0 ) { - CommandLogging.WriteLine( state.Mobile, "{0} {1} moving equip item {2} of {3}", state.Mobile.AccessLevel, CommandLogging.Format( state.Mobile ), CommandLogging.Format( m_Item ), CommandLogging.Format( m_Mobile ) ); + CommandLogging.WriteLine( state.Mobile, "{0} {1} moving equipment item {2} of {3}", state.Mobile.AccessLevel, CommandLogging.Format( state.Mobile ), CommandLogging.Format( m_Item ), CommandLogging.Format( m_Mobile ) ); state.Mobile.Target = new MoveTarget( m_Item ); } else if ( index == 1 ) { - CommandLogging.WriteLine( state.Mobile, "{0} {1} deleting equip item {2} of {3}", state.Mobile.AccessLevel, CommandLogging.Format( state.Mobile ), CommandLogging.Format( m_Item ), CommandLogging.Format( m_Mobile ) ); + CommandLogging.WriteLine( state.Mobile, "{0} {1} deleting equipment item {2} of {3}", state.Mobile.AccessLevel, CommandLogging.Format( state.Mobile ), CommandLogging.Format( m_Item ), CommandLogging.Format( m_Mobile ) ); m_Item.Delete(); } else if ( index == 2 ) { - CommandLogging.WriteLine( state.Mobile, "{0} {1} opening props for equip item {2} of {3}", state.Mobile.AccessLevel, CommandLogging.Format( state.Mobile ), CommandLogging.Format( m_Item ), CommandLogging.Format( m_Mobile ) ); + CommandLogging.WriteLine( state.Mobile, "{0} {1} opening properties for equipment item {2} of {3}", state.Mobile.AccessLevel, CommandLogging.Format( state.Mobile ), CommandLogging.Format( m_Item ), CommandLogging.Format( m_Mobile ) ); state.Mobile.SendGump( new PropertiesGump( state.Mobile, m_Item ) ); } } @@ -1278,34 +1278,6 @@ namespace Server.Commands } } - private class DeleteItemByLayerTarget : Target - { - private Layer m_Layer; - - public DeleteItemByLayerTarget( Layer layer ) : base( -1, false, TargetFlags.None ) - { - m_Layer = layer; - } - - protected override void OnTarget( Mobile from, object targeted ) - { - if ( targeted is Mobile ) - { - Item item = ((Mobile)targeted).FindItemOnLayer( m_Layer ); - - if ( item != null ) - { - CommandLogging.WriteLine( from, "{0} {1} deleting item on layer {2} of {3}", from.AccessLevel, CommandLogging.Format( from ), m_Layer, CommandLogging.Format( targeted ) ); - item.Delete(); - } - } - else - { - from.SendMessage( "Target a mobile." ); - } - } - } - [Usage( "AutoPageNotify" )] [Aliases( "APN" )] [Description( "Toggles your auto-page-notify status." )] diff --git a/Scripts/Gumps/AdminGump.cs b/Scripts/Gumps/AdminGump.cs index 9e141e9f3..f0bef1504 100644 --- a/Scripts/Gumps/AdminGump.cs +++ b/Scripts/Gumps/AdminGump.cs @@ -2727,20 +2727,17 @@ namespace Server.Gumps private void Shutdown( bool restart, bool save ) { - CommandLogging.WriteLine( m_From, "{0} {1} shuting down server (Restart: {2}) (Save: {3})", m_From.AccessLevel, CommandLogging.Format( m_From ), restart, save ); + CommandLogging.WriteLine( m_From, "{0} {1} shutting down server (Restart: {2}) (Save: {3})", m_From.AccessLevel, CommandLogging.Format( m_From ), restart, save ); if ( save ) InvokeCommand( "Save" ); - if ( restart ) - Process.Start( Core.ExePath, Core.Arguments ); - - Core.Process.Kill(); + Core.Kill( restart ); } - private void InvokeCommand( string ip ) + private void InvokeCommand( string c ) { - CommandSystem.Handle( m_From, String.Format( "{0}{1}", CommandSystem.Prefix, ip ) ); + CommandSystem.Handle( m_From, String.Format( "{0}{1}", CommandSystem.Prefix, c ) ); } public static void GetAccountInfo( Account a, out AccessLevel accessLevel, out bool online ) diff --git a/Scripts/Misc/AutoRestart.cs b/Scripts/Misc/AutoRestart.cs index b0d921599..bd9651382 100644 --- a/Scripts/Misc/AutoRestart.cs +++ b/Scripts/Misc/AutoRestart.cs @@ -61,8 +61,7 @@ namespace Server.Misc private void Restart_Callback() { - Process.Start( Core.ExePath, Core.Arguments ); - Core.Process.Kill(); + Core.Kill( true ); } protected override void OnTick() diff --git a/Scripts/Misc/ClientVerification.cs b/Scripts/Misc/ClientVerification.cs index 2e3d4bd2d..b8c5cdf59 100644 --- a/Scripts/Misc/ClientVerification.cs +++ b/Scripts/Misc/ClientVerification.cs @@ -190,7 +190,7 @@ namespace Server.Misc { if( m.NetState != null && m.NetState.Version < Required ) { - Gump g = new WarningGump( 1060637, 30720, String.Format( "Your client is out of date. Please update your client.
This server reccomends that your client version be at least {0}.

You are currently using version {1}.

To patch, run UOPatch.exe inside your Ultima Online folder.", Required, m.NetState.Version ), 0xFFC000, 480, 360, + Gump g = new WarningGump( 1060637, 30720, String.Format( "Your client is out of date. Please update your client.
This server recommends that your client version be at least {0}.

You are currently using version {1}.

To patch, run UOPatch.exe inside your Ultima Online folder.", Required, m.NetState.Version ), 0xFFC000, 480, 360, delegate( Mobile mob, bool selection, object o ) { m.SendMessage( "You will be reminded of this again." ); diff --git a/Server/Main.cs b/Server/Main.cs index 0166804dd..a5d77ff2d 100644 --- a/Server/Main.cs +++ b/Server/Main.cs @@ -276,8 +276,10 @@ namespace Server { if( World.Saving ) return true; + + Kill(); - return false; + return true; } #endif @@ -287,8 +289,7 @@ namespace Server } private static bool m_Closing; - - public static bool Closing { get { return m_Closing; } set { m_Closing = value; } } + public static bool Closing { get { return m_Closing; } } private static uint m_CycleIndex; private static float[] m_CyclesPerSecond = new float[100]; @@ -315,6 +316,21 @@ namespace Server } } + public static void Kill() + { + Kill( false ); + } + + public static void Kill( bool restart ) + { + HandleClosed(); + + if ( restart ) + Process.Start( ExePath, Arguments ); + + m_Process.Kill(); + } + private static void HandleClosed() { if( m_Closing ) @@ -327,9 +343,6 @@ namespace Server if( !m_Crashed ) EventSink.InvokeShutdown( new ShutdownEventArgs() ); - if( timerThread.ThreadState != System.Threading.ThreadState.Unstarted ) - timerThread.Join(); - if( SocketPool.Created ) SocketPool.Destroy(); @@ -448,7 +461,7 @@ namespace Server int sample = 0; - while( !m_Closing ) + while( true ) { m_Signal.WaitOne(); @@ -477,9 +490,6 @@ namespace Server { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } - - if( timerThread.IsAlive ) - timerThread.Abort(); } public static string Arguments diff --git a/Server/Mobile.cs b/Server/Mobile.cs index 2ded6f2f7..bbc7afd2a 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -7926,7 +7926,7 @@ namespace Server return this == m || ( m.m_Map == m_Map && - (!m.Hidden || (m_AccessLevel != AccessLevel.Player && (m_AccessLevel >= m.AccessLevel || m_AccessLevel >= AccessLevel.Administrator))) && //Admins/devs can still see/find eachother though admin gump, they should be able to see 'em too. + (!m.Hidden || (m_AccessLevel != AccessLevel.Player && (m_AccessLevel >= m.AccessLevel || m_AccessLevel >= AccessLevel.Developer))) && ((m.Alive || (Core.SE && Skills.SpiritSpeak.Value >= 100.0)) || !Alive || m_AccessLevel > AccessLevel.Player || m.Warmode)); }