Skip to content

Instantly share code, notes, and snippets.

@antonyfairport
Last active October 5, 2015 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonyfairport/2855164 to your computer and use it in GitHub Desktop.
Save antonyfairport/2855164 to your computer and use it in GitHub Desktop.
Simple script that notifies you via IM, or email, when your sim has restarted
//////////////////////////////////////////////////////////////////////
// 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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment