2012-06-01

Region Restart Notifier (again)

Last year I posted a script that I use to let me know when our region has restarted. It's always proven to be handy, letting me know as soon as possible when it's safe to TP home again. Recently I thought it'd be handy if I had it keep track of a couple of key details and let me know if they've changed in any way. This was prompted by the fact that, one day, our home sim stopped being main channel and became an RC channel (I'm not overly bothered by that, but it seemed like it would be handy to know that such a change has taken place).

So, with that in mind, here's a newer version of that script:

//////////////////////////////////////////////////////////////////////
// Sim Restart Notifier -- By Antony Fairport
//
// Informs you when the sim it is located on restarts. Handy during
// rolling restarts when you've had to run away and want to be told
// as soon as it's back up.
//
// Revision history:
// ------------------------------------------------------------
//
// 2012-05-21
// Added more information to the notification (channel, version, etc)
// and also added the option to send an email instead of an IM.
//
// 2011-05-31
// First version.
//////////////////////////////////////////////////////////////////////
// Set the following to an email address if you want the restart
// notifier to send an email rather than send an IM. Leave it empty
// to get an IM instead.
string EMAIL_TO = "";
//////////////////////////////////////////////////////////////////////
// Gobals.
string g_sLastChannel = "";
string g_sLastVersion = "";
string g_sLastHost = "";
string g_sLastRestart = "";
//////////////////////////////////////////////////////////////////////
// Format a llGetTimestamp()
string FormatTime( string sTime )
{
list l = llParseString2List( sTime, [ "T", "." ], [] );
return llList2String( l, 0 ) + " " + llList2String( l, 1 ) + " UTC";
}
//////////////////////////////////////////////////////////////////////
// Record details about the current server.
RememberServer()
{
g_sLastChannel = llGetEnv( "sim_channel" );
g_sLastVersion = llGetEnv( "sim_version" );
g_sLastHost = llGetSimulatorHostname();
}
//////////////////////////////////////////////////////////////////////
// Return details of a change (or not).
string Changed( string sOld, string sNew )
{
if ( sOld != sNew )
{
return " (Changed. Was " + sOld + ")";
}
else
{
return "";
}
}
//////////////////////////////////////////////////////////////////////
// Send out the information about the restart.
InformAboutRestart()
{
// Remember the time of this restart.
g_sLastRestart = FormatTime( llGetTimestamp() );
// The headline for the information.
string sHeadline = llGetRegionName() + " has restarted.";
// The body of the information.
string s = sHeadline + "\n\n";
// Get the current information about the region.
string sChannel = llGetEnv( "sim_channel" );
string sVersion = llGetEnv( "sim_version" );
string sHost = llGetSimulatorHostname();
// Add the host/server details.
s += "Channel: " + sChannel + Changed( g_sLastChannel, sChannel ) + "\n";
s += "Version: " + sVersion + Changed( g_sLastVersion, sVersion ) + "\n";
s += "Host: " + sHost + Changed( g_sLastHost, sHost ) + "\n";
// Having compared, we remember the new server state.
RememberServer();
// If we have an email address...
if ( EMAIL_TO != "" )
{
// ...send it as an email.
llEmail( EMAIL_TO, sHeadline, s );
}
else
{
// No email address. Just IM it.
llInstantMessage( llGetOwner(), s );
}
}
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Remember the current details of the server.
RememberServer();
}
//////////////////////////////////////////////////////////////////
// Reset on rez.
on_rez( integer start_param )
{
llResetScript();
}
//////////////////////////////////////////////////////////////////
// React to a touch.
touch_start( integer num_detected )
{
// If we don't have a last restart time...
if ( g_sLastRestart == "" )
{
// ...so say.
llWhisper( 0, "No restart has been recorded yet." );
}
else
{
// Otherwise say what the last recorded restart time is.
llWhisper( 0, "Last restart was " + g_sLastRestart );
}
}
//////////////////////////////////////////////////////////////////
// React to changes.
changed( integer change )
{
// If the region has started...
if ( change & CHANGED_REGION_START )
{
// ...inform about the restart.
InformAboutRestart();
}
// Reset if we're passed on.
else if ( change & CHANGED_OWNER )
{
llResetScript();
}
}
}
It's also worth noting that I've extended it so that it'll send an email instead of an IM. This has actually turned out to be handy because, if I've run to another region while I wait for a restart, I can miss the IM. On the other hand an email causes an alert on my desktop and on my phone.

No comments:

Post a Comment