Author Topic: Enhanced Windows startmud script  (Read 3144 times)

Offline saquivor

  • BFF
  • ***
  • Posts: 111
    • View Profile
Enhanced Windows startmud script
« on: September 22, 2006, 11:34:23 pm »
This a jscript file I wrote (orginally posted on lpuni.org) that starts driver.exe as a hidden background process. It will also restart the mud if it shutdown from within the driver or crashes. I do most of my development on Windows at the momement, so I found the script very useful.



It only allows one copy of driver.exe to run at once. I have found it to give me stable performace when running on Windows and it looks tidier not having a command screen stuck on application tray ;)



To stop the mud running you will need to run the killmud.js file. I am posting the code for both files, but if you prefer to download them then click on http://monkeyx.net/runds2.zip">here.





Save this code as something like startmud.js, to run double click on file.

jscript code:

/*
**********************************************************************************************
Script written to start MUDOS driver as background process.

Script was produce to support Dead Souls 2 mudlib.

Script defaults to hiding windows, if you want to see them then set var wind=1;

The script current only allows one copy of driver to be loaded at once.

In Order to stop the script trying to restart the mud you will need to run the killmud.js script.

Script written by saquivor@monkeyx.net. Any improvements/suggestions. Then please let me know

ver 00b testing release
**********************************************************************************************
*/

var oShell = WScript.CreateObject("WScript.Shell");
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var envVolatile = oShell.Environment("Volatile");
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var wind;
var mudhome;
var pfile;
wind=0; // set to 1 to make program visible
mudhome="C:/ds/win32/"; //Path to driver
pfile="driver.exe";
if (!fso.FileExists(mudhome + pfile))
   {
   WScript.Echo("Script abending as " + mudhome + pfile + " does not exist");
   WScript.Quit(1);
   }

try {
   var objWMIService = GetObject( "winmgmts://./root/cimv2" );
   }
catch(e)  {
   WScript.Echo("WMI Error caught " + e.number + " " + e.description + " Guru Meditation Error!");
   WScript.Quit(1);
   }

envVolatile("MUDmon")="run"; //Used to create a temp env variable for closing down program

while (envVolatile("MUDmon")=="run")
   {
   var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process where Name='" + pfile +
    "'", "WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);
   var enumItems = new Enumerator(colItems);
      if (enumItems.atEnd()) //Checks if collection empty, will be true if so run the driver
      {
      oShell.Run ("%comspec% /c " + mudhome + pfile +
      " c:/ds/lib/secure/cfg/mudos.cfg >C:/ds/driver_log.txt",wind,false); //redirect not sending much to file
      }
WScript.Sleep(1500); // Stop the script using all spare cycles
}
WScript.Quit(0);





The is the code that stops the driver running save as something like killmud.js and double click to run.



jscript code:

/*
**********************************************************************************************
Script written to stop MUDOS driver and and address server from a single script.
Script was produce to support Dead Souls 2 mudlib.
Address server termination has been remarked due to it ebing remove from general distrubtion on Win32

Script defaults to stopping all running instances of driver.

Script written by saquivor@monkeyx.net. Any improvements/suggestions. Then please let me know

ver 00a testing release
**********************************************************************************************
*/
var oShell = WScript.CreateObject("WScript.Shell");
var objWMIService = GetObject("winmgmts://./root/CIMV2");
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);
var envVolatile = oShell.Environment("Volatile");

envVolatile("MUDmon")="stop";

var enumItems = new Enumerator(colItems);
   for (; !enumItems.atEnd(); enumItems.moveNext()) {
      var objItem = enumItems.item();
/*   if (objItem.Name=="addr_server.exe") //Is the program already running ?
   {
   objItem.Terminate();
//      WScript.Echo("Program Due for termination!!!: " +objItem.Name + " Process ID: " + objItem.ProcessID);
   }
*/
   if (objItem.Name=="driver.exe") //Is the program already running ?
   {
   objItem.Terminate();
//      WScript.Echo("Program Due for termination!!!: " +objItem.Name + " Process ID: " + objItem.ProcessID);
   }
}
WScript.Quit();


Offline Silvyar

  • Acquaintance
  • *
  • Posts: 3
    • View Profile
Re: Enhanced Windows startmud script
« Reply #1 on: May 01, 2008, 11:19:32 am »
Is there any interest in developing a Win32 Service version of the driver?

Offline saquivor

  • BFF
  • ***
  • Posts: 111
    • View Profile
Re: Enhanced Windows startmud script
« Reply #2 on: May 01, 2008, 02:03:54 pm »
Been a while since I used this tool, but have you looked at http://www.iopus.com/guides/srvany.htm. Could maybe use that to help run driver as service.

Offline Silvyar

  • Acquaintance
  • *
  • Posts: 3
    • View Profile
Re: Enhanced Windows startmud script
« Reply #3 on: May 05, 2008, 11:18:57 am »
Indeed, there are a number of ways to "sort of" be a Windows Service, all with various advantages and disadvantages.

If there was enough interest, I'd tackle building a true Windows Service.

Offline saquivor

  • BFF
  • ***
  • Posts: 111
    • View Profile
Re: Enhanced Windows startmud script
« Reply #4 on: May 05, 2008, 01:11:30 pm »
I only run ds2 on Windows every now again, so would not be of any interest to me.

If I was ever to host a real "mud" LOL. I would probably chose Linux over Win 32.