Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c18aa81f88 | ||
|
|
e08059d324 | ||
|
|
8a52259499 |
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(AutoSave VERSION 1.2.1)
|
||||
project(AutoSave VERSION 1.2.2)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-static -static-libgcc -static-libstdc++ -Wall -Werror")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O2 -DTSFUNCS_DEBUG=false")
|
||||
|
||||
@@ -56,13 +56,11 @@ Up to 75000 bricks, bricks are sorted by height like the stock save. Over 75000,
|
||||
|
||||
`/as` is short for `/autosaver` and works with every command below, for example `/as save` or `/as load 08-55-15`.
|
||||
|
||||
Anyone can use:
|
||||
Only staff can use `/autosaver` at all, including `help` and `status`. By default that is admins and super admins. With `$Pref::Server::AutoSave::SuperAdminOnly = 1` it is super admins only. The host is always a super admin. Anyone else is told who can use it, and nothing runs.
|
||||
|
||||
- `/autosaver help`
|
||||
- `/autosaver status`
|
||||
|
||||
Admins can use:
|
||||
|
||||
- `/autosaver access admins` or `/autosaver access superadmins`: who can use `/autosaver`. Only a super admin can change this.
|
||||
- `/autosaver on` and `/autosaver off`
|
||||
- `/autosaver save` (or `now`): save right away
|
||||
- `/autosaver load` (or `reload`): clear all bricks, then load the newest file in `saves/autosave/`
|
||||
@@ -97,12 +95,13 @@ $Pref::Server::AutoSave::Chunk = 4000;
|
||||
$Pref::Server::AutoSave::Enabled = 1;
|
||||
$Pref::Server::AutoSave::Interval = 300;
|
||||
$Pref::Server::AutoSave::Preview = 1;
|
||||
$Pref::Server::AutoSave::SuperAdminOnly = 0;
|
||||
$Pref::Server::AutoSave::Tick = 1;
|
||||
```
|
||||
|
||||
They are read each time a server starts. AutoSave checks every 5 seconds for a new server, which it tells apart by the mission's `MissionGroup`, so stopping one server and starting another is noticed even within one save interval. The save timer restarts with each new server. If a pref is missing, the default is used and added to the file the next time the game writes its prefs.
|
||||
|
||||
Every `/autosaver on`, `off`, `interval`, `chunk`, `tick`, `screenshot` and `autoload` writes `prefs.cs` right away, using the same export the game runs when custom game settings change. AutoSave only writes the file while a server is running, after the game has loaded it, so other prefs are kept. You can also edit the lines while the game is closed. Values out of range are clamped the same way as in chat.
|
||||
Every `/autosaver on`, `off`, `interval`, `chunk`, `tick`, `screenshot`, `autoload` and `access` writes `prefs.cs` right away, using the same export the game runs when custom game settings change. AutoSave only writes the file while a server is running, after the game has loaded it, so other prefs are kept. You can also edit the lines while the game is closed. Values out of range are clamped the same way as in chat.
|
||||
|
||||
## Console
|
||||
|
||||
@@ -110,7 +109,7 @@ Every `/autosaver on`, `off`, `interval`, `chunk`, `tick`, `screenshot` and `aut
|
||||
- `autoSaveNewest()` returns the newest autosave path
|
||||
- `autoSaveFind(name)` returns the autosave path for a name, `*N` if N files match, or nothing
|
||||
- `autoSaveApply()` clamps the settings, copies them to `$Pref::Server::AutoSave::*`, writes `config/server/prefs.cs` while hosting, and restarts the timer
|
||||
- `$AutoSave::Enabled`, `$AutoSave::Interval`, `$AutoSave::Chunk`, `$AutoSave::Tick`, `$AutoSave::Preview`, `$AutoSave::AutoLoad` are the live values
|
||||
- `$AutoSave::Enabled`, `$AutoSave::Interval`, `$AutoSave::Chunk`, `$AutoSave::Tick`, `$AutoSave::Preview`, `$AutoSave::AutoLoad`, `$AutoSave::SuperAdminOnly` are the live values
|
||||
|
||||
A value set on `$AutoSave::*` in the console is not saved, and a new interval does not take effect, until `autoSaveApply()` is called.
|
||||
|
||||
|
||||
+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