by Maik on Mon Aug 27, 2007 9:45 pm
Just don't want to use pandora or the admin gump has to many clicks to restart/shutdown the server? Here you have a shortcut:
- Code: Select all
using System;
using System.Reflection;
using System.Collections;
using Server;
using Server.Network;
using Server.Scripts.Commands;
namespace Server.Scripts.Commands
{
public class AdministrativeCommandShortcuts
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static void Initialize()
{
Server.Commands.Register( "Shutdown", AccessLevel.Administrator, new CommandEventHandler( Shutdown_OnCommand ) );
}
[Usage( "Shutdown" )]
[Description( "Shutdown server. If -r is given, it does a reboot, if -s is given, the world is saved first." )]
private static void Shutdown_OnCommand(CommandEventArgs e)
{
string arg = "";
int i = 0;
bool restart = false;
bool save = false;
try
{
if( e.Length > 0)
{
for(i = 0; i < e.Length; i++)
{
arg = e.GetString(i);
if (arg == "")
{
break;
}
if (arg == "-r")
{
restart = true;
}
if (arg == "-s")
{
save = true;
}
if (arg == "-rs" || arg == "-sr" || arg == "-s-r" || arg == "-r-s")
{
restart = true;
save = true;
}
}
}
if(save)
{
e.Mobile.SendMessage("Initialized world save before shutdown...");
}
if(save && restart)
{
Shutdown(true, true, e.Mobile);
}
else if(!save && restart)
{
Shutdown(true, false, e.Mobile);
}
else if(save && !restart)
{
Shutdown(false, true, e.Mobile);
}
else
{
Shutdown(false,false, e.Mobile);
}
}
catch(Exception ex)
{
log.DebugFormat("{0}",ex.StackTrace);
}
}
private static void Shutdown( bool restart, bool save , Mobile m_From)
{
log.InfoFormat( "{0} shuting down server (Restart: {1}) (Save: {2})", m_From, restart, save );
// Disconnect each player before shutdown
foreach( NetState ns in NetState.Instances) {
if(ns != null) {
log.InfoFormat( "Force disconnect {0}", ns.Mobile );
ns.Dispose();
}
}
if ( save )
{
World.Save(false);
}
Core.Shutdown(restart);
}
}
}