ff_u_watchdog
Watchdog unit.
The following file writes a timestamp to nwnx/watchdog.nss every minute.
On shutdown, it writes a “0” instead.
On startup, it will password protect the server until the ON_MODULE_START is received.
Variables
ENABLE__FF_U_WATCHDOG: (string) (opt-out) Set to “N” on module to disable unit.
Source code
// @code
#include "ff_i_core"
const string ENABLE__FF_U_WATCHDOG = "ENABLE__FF_U_WATCHDOG";
const string PASSWORD = "__PASSWORD";
// -----------------------------------------------------------------------------
void main()
{
if (!GetModuleFlag(ENABLE__FF_U_WATCHDOG, TRUE))
return;
object oModule = GetModule();
string sEvent = GetCurrentEvent();
if (sEvent == ON_REGISTER)
{
SubscribeToEvent(ON_MODULE_START, __FILE__);
SubscribeToEvent(ON_REALTIME_MINUTE, __FILE__);
SubscribeToEvent(ON_MODULE_SHUTDOWN, __FILE__);
// Lock the server until it's started
SetLocalString(oModule, PASSWORD, NWNX_Administration_GetPlayerPassword());
NWNX_Administration_SetPlayerPassword(IntToString(Random(1000)));
LogNotice("Locked the server with a player password.");
NWNX_Util_AddNSSFile("watchdog", IntToString(GetTimeStamp()));
LogNotice("Watchdog has started.");
}
else if (sEvent == ON_MODULE_START)
{
// Lock the server until it's started
string sPassword = GetLocalString(oModule, PASSWORD);
if (sPassword != "")
NWNX_Administration_SetPlayerPassword(sPassword);
else
NWNX_Administration_ClearPlayerPassword();
LogNotice("Unlocked server by restoring previous player password");
DeleteLocalString(oModule, PASSWORD);
}
else if (sEvent == ON_REALTIME_MINUTE)
{
string sTime = IntToString(GetTimeStamp());
NWNX_Util_AddNSSFile("watchdog", sTime);
}
else if (sEvent == ON_MODULE_SHUTDOWN)
{
NWNX_Util_AddNSSFile("watchdog", "0");
}
}