Repository navigation
fix(server/player)!: derive statuses on the server - #254
DoluTattoo wants to merge 1 commit into
Conversation
BREAKING CHANGE: the ox:updateStatuses event is removed and clients can no longer set status values.
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. |
|
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. |
|
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. |
Problem
ox:updateStatusesapplies whatever the client sends: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.
onTickis server-side config published throughGlobalState, 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:
getStatus,setStatus,#adjustStatusand#getSaveDataall 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:updateStatusesis removed, so any resource listening for it server-side will stop receiving it.Because the server applies
onTick * ticksin one step while the client still increments once per second, a displayed value can differ by a rounding step until the nextsetStatusoraddStatusresyncs the client.