Limit /autosaver to staff, add SuperAdminOnly pref and /autosaver access
This commit is contained in:
1 parent
283410617e
commit
8a52259499
1 file changed
+45
-11
+45
-11
@@ -37,6 +37,7 @@ static int gSavedCount = -1;
|
||||
static bool gReady = false;
|
||||
static bool gPreview = true;
|
||||
static bool gAutoLoad = false;
|
||||
static bool gSuperAdminOnly = false;
|
||||
|
||||
struct Row {
|
||||
ADDR obj;
|
||||
@@ -593,8 +594,9 @@ static void prefsToScript()
|
||||
"$Pref::Server::AutoSave::Chunk = %d;"
|
||||
"$Pref::Server::AutoSave::Tick = %d;"
|
||||
"$Pref::Server::AutoSave::Preview = %d;"
|
||||
"$Pref::Server::AutoSave::AutoLoad = %d;",
|
||||
gEnabled ? 1 : 0, gInterval, gChunk, gTickMs, gPreview ? 1 : 0, gAutoLoad ? 1 : 0);
|
||||
"$Pref::Server::AutoSave::AutoLoad = %d;"
|
||||
"$Pref::Server::AutoSave::SuperAdminOnly = %d;",
|
||||
gEnabled ? 1 : 0, gInterval, gChunk, gTickMs, gPreview ? 1 : 0, gAutoLoad ? 1 : 0, gSuperAdminOnly ? 1 : 0);
|
||||
tsf_Eval(code);
|
||||
}
|
||||
|
||||
@@ -619,6 +621,9 @@ static void prefsFromScript()
|
||||
value = varOf("$Pref::Server::AutoSave::AutoLoad");
|
||||
if (!value.empty())
|
||||
gAutoLoad = truthy(value);
|
||||
value = varOf("$Pref::Server::AutoSave::SuperAdminOnly");
|
||||
if (!value.empty())
|
||||
gSuperAdminOnly = truthy(value);
|
||||
clampPrefs();
|
||||
prefsToScript();
|
||||
}
|
||||
@@ -1634,7 +1639,11 @@ static void autoSaveApply(ADDR obj, int argc, const char *argv[])
|
||||
static const char kChatScript[] = R"TS(
|
||||
function AutoSave_Admin(%client)
|
||||
{
|
||||
return isObject(%client) && (%client.isAdmin || %client.isSuperAdmin);
|
||||
if (!isObject(%client))
|
||||
return 0;
|
||||
if ($AutoSave::SuperAdminOnly)
|
||||
return %client.isSuperAdmin;
|
||||
return %client.isAdmin || %client.isSuperAdmin;
|
||||
}
|
||||
function AutoSave_Tell(%client, %line)
|
||||
{
|
||||
@@ -1658,6 +1667,7 @@ function AutoSave_Help(%client)
|
||||
AutoSave_Tell(%client, "/autosaver save");
|
||||
AutoSave_Tell(%client, "/autosaver load <optional autosave name>");
|
||||
AutoSave_Tell(%client, "/autosaver autoload <on or off>");
|
||||
AutoSave_Tell(%client, "/autosaver access <admins or superadmins>");
|
||||
}
|
||||
function AutoSave_Busy()
|
||||
{
|
||||
@@ -1788,6 +1798,11 @@ function AutoSave_Command(%client, %cmd, %arg)
|
||||
{
|
||||
echo("AutoSave: /autosaver" SPC %cmd SPC %arg);
|
||||
%cmd = strlwr(%cmd);
|
||||
if (!AutoSave_Admin(%client))
|
||||
{
|
||||
AutoSave_Tell(%client, $AutoSave::SuperAdminOnly ? "Only super admins can use /autosaver." : "Only admins can use /autosaver.");
|
||||
return;
|
||||
}
|
||||
if (%cmd $= "" || %cmd $= "help")
|
||||
{
|
||||
AutoSave_Help(%client);
|
||||
@@ -1795,15 +1810,32 @@ function AutoSave_Command(%client, %cmd, %arg)
|
||||
}
|
||||
if (%cmd $= "status")
|
||||
{
|
||||
AutoSave_Tell(%client, "Enabled \c3" @ ($AutoSave::Enabled ? "on" : "off") @ "\c6, every \c3" @ $AutoSave::Interval @ "\c6 seconds, \c3" @ $AutoSave::Chunk @ "\c6 bricks per slice, \c3" @ $AutoSave::Tick @ "\c6 ms between slices, screenshots \c3" @ ($AutoSave::Preview ? "on" : "off") @ "\c6, autoload \c3" @ ($AutoSave::AutoLoad ? "on" : "off") @ "\c6.");
|
||||
return;
|
||||
}
|
||||
if (!AutoSave_Admin(%client))
|
||||
{
|
||||
AutoSave_Tell(%client, "Only an admin can change autosave.");
|
||||
AutoSave_Tell(%client, "Enabled \c3" @ ($AutoSave::Enabled ? "on" : "off") @ "\c6, every \c3" @ $AutoSave::Interval @ "\c6 seconds, \c3" @ $AutoSave::Chunk @ "\c6 bricks per slice, \c3" @ $AutoSave::Tick @ "\c6 ms between slices, screenshots \c3" @ ($AutoSave::Preview ? "on" : "off") @ "\c6, autoload \c3" @ ($AutoSave::AutoLoad ? "on" : "off") @ "\c6, access \c3" @ ($AutoSave::SuperAdminOnly ? "super admins" : "admins") @ "\c6.");
|
||||
return;
|
||||
}
|
||||
%name = %client.getPlayerName();
|
||||
if (%cmd $= "access")
|
||||
{
|
||||
if (!%client.isSuperAdmin)
|
||||
{
|
||||
AutoSave_Tell(%client, "Only a super admin can change who can use /autosaver.");
|
||||
return;
|
||||
}
|
||||
%arg = strlwr(%arg);
|
||||
if (%arg $= "admin" || %arg $= "admins")
|
||||
%super = 0;
|
||||
else if (%arg $= "superadmin" || %arg $= "superadmins" || %arg $= "super")
|
||||
%super = 1;
|
||||
else
|
||||
{
|
||||
AutoSave_Tell(%client, "Use \c3/autosaver access admins\c6 or \c3/autosaver access superadmins\c6.");
|
||||
return;
|
||||
}
|
||||
$AutoSave::SuperAdminOnly = %super;
|
||||
autoSaveApply();
|
||||
messageAll('', "\c6[\c3AutoSave\c6] \c3" @ %name @ "\c6 set /autosaver to \c3" @ (%super ? "super admins only" : "admins and super admins") @ "\c6.");
|
||||
return;
|
||||
}
|
||||
if (%cmd $= "on")
|
||||
{
|
||||
$AutoSave::Enabled = 1;
|
||||
@@ -2253,8 +2285,9 @@ static void autoSaveHostCheck(ADDR obj, int argc, const char *argv[])
|
||||
gServerId = id;
|
||||
gHaveBaseline = false;
|
||||
prefsFromScript();
|
||||
BlPrintf("%s: $Pref::Server::AutoSave: %s, every %d seconds, %d bricks per slice, %d ms, screenshots %s, autoload %s", PROJECT_NAME,
|
||||
gEnabled ? "on" : "off", gInterval, gChunk, gTickMs, gPreview ? "on" : "off", gAutoLoad ? "on" : "off");
|
||||
BlPrintf("%s: $Pref::Server::AutoSave: %s, every %d seconds, %d bricks per slice, %d ms, screenshots %s, autoload %s, %s", PROJECT_NAME,
|
||||
gEnabled ? "on" : "off", gInterval, gChunk, gTickMs, gPreview ? "on" : "off", gAutoLoad ? "on" : "off",
|
||||
gSuperAdminOnly ? "super admins only" : "admins");
|
||||
if (gAutoLoad && truthy(callFn1("isFunction", "AutoSave_AutoLoadStart")))
|
||||
tsf_Eval("AutoSave_AutoLoadStart();");
|
||||
tsf_Eval("if (isEventPending($AutoSave::Schedule)) cancel($AutoSave::Schedule);");
|
||||
@@ -2471,6 +2504,7 @@ bool init()
|
||||
tsf_AddVar("AutoSave::Loading", &gLoading);
|
||||
tsf_AddVar("AutoSave::Preview", &gPreview);
|
||||
tsf_AddVar("AutoSave::AutoLoad", &gAutoLoad);
|
||||
tsf_AddVar("AutoSave::SuperAdminOnly", &gSuperAdminOnly);
|
||||
installPreview();
|
||||
tsf_AddConsoleFunc(0, 0, "autoSaveTick", autoSaveTick, "autoSaveTick() - timed brick save", 1, 1);
|
||||
tsf_AddConsoleFunc(0, 0, "autoSaveChunk", autoSaveChunk, "autoSaveChunk() - continue a brick save", 1, 1);
|
||||
|
||||
Reference in new issue
Block a user