Welcome
Welcome to <strong>SunUO</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Administrative shortcuts

Release your custom scripts to the public. By posting your scripts here it is automatically licensed under the terms of the GPL.

Administrative shortcuts

Postby 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);
      }
   }
}
User avatar
Maik
 
Posts: 30
Joined: Wed Aug 15, 2007 3:30 pm

Postby SiENcE on Wed Aug 29, 2007 8:45 am

Thx for sharing.
SiENcE
 
Posts: 14
Joined: Fri Aug 24, 2007 12:19 pm
Location: Munich


Return to Script Releases

Who is online

Users browsing this forum: No registered users and 0 guests

cron