Skip to content

fix(server/player)!: derive statuses on the server - #254

Open
DoluTattoo wants to merge 1 commit into
overextended:mainfrom
DoluTattoo:fix/status-client-authority
Open

DoluTattoo wants to merge 1 commit into
overextended:mainfrom
DoluTattoo:fix/status-client-authority

Conversation

@DoluTattoo

Copy link
Copy Markdown
Contributor

Problem

ox:updateStatuses applies whatever the client sends:

onNet('ox:updateStatuses', async (data: Dict<OxStatus>) => {
  ...
  if (status && typeof value === 'number') player.setStatus(name, value);
});

The client owns the decay loop and reports the result every second, so the server can't tell a normal tick from an injected one. Anyone able to trigger events can hold hunger and thirst at 100, or keep stress at 0, and ignore survival mechanics entirely.

Fix

The event is removed and the server derives the values itself. onTick is server-side config published through GlobalState, so decay is deterministic and there is nothing the client needs to report.

Ticking every player every second would not scale, so elapsed decay is applied when a status is read instead:

get #tickedStatuses() {
  const ticks = Math.floor((GetGameTimer() - this.#statusesTickedAt) / 1000);
  ...
}

getStatus, setStatus, #adjustStatus and #getSaveData all read through it. That is O(1) per read and nothing per second, so idle players cost nothing regardless of player count.

The client keeps its tick for the UI (ox:statusTick), it just no longer sends the result back.

Breaking

ox:updateStatuses is removed, so any resource listening for it server-side will stop receiving it.

Because the server applies onTick * ticks in one step while the client still increments once per second, a displayed value can differ by a rounding step until the next setStatus or addStatus resyncs the client.

BREAKING CHANGE: the ox:updateStatuses event is removed and clients can no longer set status values.
@thelindat

Copy link
Copy Markdown
Member

the server can't tell a normal tick from an injected one. Anyone able to trigger events can hold hunger and thirst at 100, or keep stress at 0, and ignore survival mechanics entirely.

Frankly, if they're going to bother with that they're going to attempt far worse things which will inevitably get them caught. Statuses are such a low priority and unimportant feature that it really doesn't matter. The net event probably isn't used anywhere so that's fine - but the client is intended to be able to modify the values, which obviously breaks here.

@FjamZoo

FjamZoo commented Aug 26, 2026

Copy link
Copy Markdown
Member

Yeah, we have noticed on our server with 150+ players this was consuming about 30% of server resources.

the band-aid fix we had was just setting the timer up to sync server/client every 30 seconds or smt, which obviously isnt super ideal.

@DoluTattoo

Copy link
Copy Markdown
Contributor Author

Yeah that's fair. If the client is supposed to be able to change the values then this goes the wrong way.

I'll leave it there, feel free to close.

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.

3 participants