Skip to content

Fix RESYNC not loading script files added since the last load - #1698

Open
nightNR wants to merge 1 commit into
Sphereserver:devfrom
nightNR:fix/resync-new-script-files
Open

nightNR wants to merge 1 commit into
Sphereserver:devfrom
nightNR:fix/resync-new-script-files

Conversation

@nightNR

@nightNR nightNR commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Description

Problem. RESYNC doesn't load script files that were added since the last load. If you add a file or a folder to [RESOURCES] in spheretables.scp, or drop a new .scp into the main scripts folder, the resync indexes it but never reads it. Its definitions stay missing until the server is restarted. Changes to files that were already loaded are resynced normally.

Cause. During the resync, the [RESOURCES] section of the changed spheretables.scp is parsed again, and AddResourceFile() adds the new files to m_ResourceFiles. It opens each one through CResourceScript::Open(), which calls CheckForChange(). On a first check that call only stores the file's size and date. Later in the same resync, CServerConfig::Load(true) calls ReSync() on every file, and ReSync() returns unless the file is on its first check or has changed. The new file is neither anymore, so its content is never loaded.

At startup this doesn't happen, because every file is loaded unconditionally with LoadResources(). ReSync() does have a branch for a file that was never checked, so the intent clearly was to load new files, but the open in AddResourceFile() defeats it. The behaviour is the same in the 0.56b sources.

Change (src/game/CServerConfig.cpp, CServerConfig::Load):

  • Remember how many script files were indexed before the (re)load.
  • During a resync, the files indexed after that count are new, so they are loaded with LoadResources(), the same call startup uses. The other files still go through ReSync(), which reloads them only if they changed.

What is still not covered: a new file inside a folder that is already listed in [RESOURCES] is found only when spheretables.scp changed too, because only then are the listed folders read again. The main scripts folder is read on every resync, so new files there are always found.

Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation update
  • Build / CI change
  • Other (please describe)

Related Issues

No existing issue.

Testing

I tested on a clean instance with the latest Scripts-X pack (663d1c7), using a Debug build (MSVC 2022, Windows x64). The server ran a test-only function from f_onserver_timer (TimerCall 1 s) that:

  • logged a tick every second;
  • ran SERV.RESYNC at tick 8;
  • at tick 14, logged the defnames that each test file defines.

Between tick 3 and the resync, while the server was running, the test:

  • added rt_new/ (a new folder holding one file) and rt_extra/rt_single.scp (a new single file) to [RESOURCES];
  • created rt_root.scp (a new file in the main scripts folder);
  • changed the value in rt_existing.scp, a file that was already loaded.
Run new folder new single file new file in main folder changed existing file
before the fix not loaded not loaded not loaded reloaded
with the fix loaded loaded loaded reloaded
with the fix, spheretables.scp not changed (not listed) (not listed) loaded reloaded

With the fix, the log shows Loading .../rt_new/rt_dir.scp, Loading .../rt_extra/rt_single.scp and Loading .../rt_root.scp during the resync, followed by Resync complete!. No new errors or warnings appear.

The test scripts were local only and are not part of this PR.

Checklist

  • Code compiles successfully (MSVC 2022, Debug; not built with GCC/Clang locally)
  • Changes follow the project's coding style
  • No unrelated code was modified
  • Documentation updated where necessary (Changelog.txt)
  • This PR does not introduce breaking changes (or they are documented)

Additional Notes

A file loaded this way is processed exactly as it is at startup. So, as at startup, it can redefine things that already exist; the usual "Replacing existing ..." warnings are logged.

A file or folder added to [RESOURCES], or a new file in the main scripts
folder, was indexed by the resync but never read: opening it in
AddResourceFile already stored its size and date, so ReSync() saw neither
a first check nor a change and skipped it. Files indexed for the first
time by a resync are now loaded with LoadResources(), like at startup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant