Skip to content

Conversation

@zagor
Copy link
Contributor

@zagor zagor commented Jun 15, 2025

Use the newer layers.json file which contains modern game data.

Look up layer factions and units in updateServerInformation().

@zagor zagor requested a review from werewolfboy13 as a code owner June 15, 2025 19:56
@zagor
Copy link
Contributor Author

zagor commented Jun 15, 2025

This PR replaces #404.

@fantinodavide
Copy link
Contributor

Haven't had a chance to test these changes yet, but I went through the whole diffs and the changes are looking good to me

@werewolfboy13
Copy link
Collaborator

I would need a server to test this to make sure no breaking changes are occuring.

@zagor
Copy link
Contributor Author

zagor commented Jun 16, 2025

There are breaking changes, for a strict definition of breaking.

The new game data file contains data that the old file doesn't, and vice versa. Any plugin depending on that old deprecated data would therefore break. But since we (or at least I) don't know what custom plugins people use there is no way to know the scope of this hypothetical breakage.

Also, the actual live game servers have moved away from this old data format since quite a long time (over a year?), which would already have broken any plugins depending on it. In that context, I think it is unlikely this data format change breaks any plugin that currently works correctly against master.

@werewolfboy13 werewolfboy13 mentioned this pull request Jun 22, 2025
@werewolfboy13
Copy link
Collaborator

Any changes need testing on live servers before being pushed to prod. Will only push once we have a validated test.

This is from lessons learned from other incidents.

@werewolfboy13 werewolfboy13 added Testing Required This requires testing before approval. core bug Bug related to the core SquadJS API labels Jun 22, 2025
@zagor
Copy link
Contributor Author

zagor commented Jun 23, 2025

Any changes need testing on live servers before being pushed to prod. Will only push once we have a validated test.

I agree completely. I have only tested this on my test server so far, not a live server. I am in the process of deploying it on a live server "soon", hopefully in the next couple of weeks.

Ideally several people should try it so we don't rely on testing only by the PR author.

@zagor
Copy link
Contributor Author

zagor commented Jul 12, 2025

Ok, this is now running on a live server since a few days. The only issue I've found was that immediately after game server restart, we get one or two server information blocks without any teams defined. So I've added a check for that.

@zagor
Copy link
Contributor Author

zagor commented Jul 30, 2025

I have found that this solution is not good enough for my needs.

The information returned by rcon command ShowServerInfo is up to 30 seconds old. Maybe this is old news, but it was unknown to me. The game server only updates this data when it posts a server information update to EOS. The command is, essentially, returning the server information that is shown in the server browser. The effect of this is that the function returns information about the previous round up to 30 seconds into the staging of a new round, causing problems for any plugin looking for accurate information.

I cannot therefore update teams and vehicle information in updateServerInformation() but must instead do it in updateLayerInformation(), which does gets proper accurate server status.

However, the ShowCurrentMap command used by updateLayerInformation() returns team information in the form ADF+Mechanized rather than the ADF_LO_Mechanized format that we get from ShowServerInfo, and which we need to look up units in the layer file. So I need to do a little transformation from one form to the other, in order to get accurate unit information at the start of a round.

Background for this effort: The reason I need team information timely is that I have written a plugin for automatic enforcement of vehicle claim rules. It needs to know which vehicles are available on each side at the start of the round when the race for claims occurs.

@zagor
Copy link
Contributor Author

zagor commented Aug 2, 2025

Change how layer and factions are discovered

Since the data returned by ShowServerInfo is delayed up to 30 seconds, it can not be relied on to determine current layer and faction. Especially not at the start of rounds. Instead, use ShowCurrentMap and ShowNextMap for this. They return the actual current state of the server.

Also, since the same layer object can be returned for both the current map and the next, we cannot store team information there. Thus, a new team object is returned in addition to the layer object. This requires parsing and returning additional fields from rcon.getCurrentMap() and rcon.getNextMap().

zagor added 3 commits August 2, 2025 15:20
Use the newer layers.json file which contains modern game data.

Look up layer factions and units in updateServerInformation().
Right after server restart, we get server information without any team
information.
Just skip the team creation then, we'll get those the next update.
Since the data returned by ShowServerInfo is delayed up to 30 seconds, it
can not be relied on to determine current layer and faction. Especially not
at the start of rounds. Instead, use ShowCurrentMap and ShowNextMap for
this. They return the actual current state of the server.

Also, since the same layer object can be returned for both the current map
and the next, we cannot store team information there. Thus, a new team
object is returned in addition to the layer object. This requires parsing
and returning additional fields from rcon.getCurrentMap() and
rcon.getNextMap().
@zagor zagor force-pushed the read-new-layers-file branch from f186f9f to 407ca57 Compare August 2, 2025 13:20
@zagor
Copy link
Contributor Author

zagor commented Aug 2, 2025

(Rebased on master)

@zagor
Copy link
Contributor Author

zagor commented Aug 15, 2025

This is running on server "Squad International", where it forms the foundation for an automatic vehicle claims handling plugin.

Anyone interested in seeing it in action can join the server and/or ping me. I'm "Baxter" in Squad and Discord.

werewolfboy13
werewolfboy13 previously approved these changes Aug 29, 2025
@werewolfboy13 werewolfboy13 dismissed their stale review August 29, 2025 10:52

Needs further review. This PR changes more than what is intended.

Copy link
Collaborator

@werewolfboy13 werewolfboy13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR title needs to be corrected or separate PRs need to be made for the additional changes.

@zagor
Copy link
Contributor Author

zagor commented Aug 29, 2025

Thank you for the feedback. Can you clarify what you consider to be additional changes and what would then be the core changes?

@werewolfboy13
Copy link
Collaborator

Change how layer and factions are discovered

Since the data returned by ShowServerInfo is delayed up to 30 seconds, it can not be relied on to determine current layer and faction. Especially not at the start of rounds. Instead, use ShowCurrentMap and ShowNextMap for this. They return the actual current state of the server.

Also, since the same layer object can be returned for both the current map and the next, we cannot store team information there. Thus, a new team object is returned in addition to the layer object. This requires parsing and returning additional fields from rcon.getCurrentMap() and rcon.getNextMap().

This here is not in the title. Each core change needs to be its own PR.

@werewolfboy13 werewolfboy13 linked an issue Aug 29, 2025 that may be closed by this pull request
@werewolfboy13
Copy link
Collaborator

This will satisfy #386 as an interim fix.

@zagor
Copy link
Contributor Author

zagor commented Sep 9, 2025

Ok, coming back to this now.

@werewolfboy13 Do you require that they are separate PRs or is it enough that they are separate commits in this PR?

Making two PRs means first making a PR that works with the old layer code and team objects. And then a second PR that substantially rewrites what was in the first PR. The code in the first PR will thus only live until the second is merged, which seems a little wasteful. But I can do it if you really prefer it that way.

@lbzepoqo
Copy link
Contributor

I'm getting this

(node:36) UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'tickets')
    at new Layer (file:///home/container/squad-server/layers/layer.js:21:44)
    at Layers.pull (file:///home/container/squad-server/layers/layers.js:29:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SquadServer.watch (file:///home/container/squad-server/index.js:72:5)
    at async main (file:///home/container/index.js:17:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:36) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core bug Bug related to the core SquadJS API Testing Required This requires testing before approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SEV 2] Layers File broken on recent update

4 participants