altmp / altv-js-module

JS module for alt:V Multiplayer. Powered by NodeJS & v8
MIT License
55 stars 35 forks source link

Silent replacement of destroyed baseobject on emit #289

Closed xxshady closed 1 year ago

xxshady commented 1 year ago

Description of the problem

If you send baseobject (vehicle, player, etc.) via network it can be received as another baseobject, which is ABA problem.

Reproduction steps

  1. Create serverside vehicle
  2. Send it to client
  3. Send client->server event to destroy vehicle and right after it create another one, it will get same id
  4. Send vehicle (from step 2) back to server
  5. Server receives imposter vehicle we created in step 3

JS code:

server

alt.onClient('test', (player, obj) => {
    alt.log('test:', obj, obj?.id)
    alt.log(
        'is bmx:', obj.model === alt.hash('bmx'),
        'is sultan:', obj.model === alt.hash('sultan')
    )
})

let veh
alt.onClient('destroy', (player) => {
    veh.destroy()
    veh = new alt.Vehicle('bmx', 0, 0, 0, 0, 0, 0)
    alt.log('recreated veh id:', veh.id)
})

veh = new alt.Vehicle('sultan', 0, 0, 0, 0, 0, 0)
alt.log('created veh id:', veh.id)

player.emit('test', veh)

client

alt.onServer('test', (obj) => {
    alt.log('on server test')
    alt.emitServer('destroy')
    alt.emitServer('test', obj)
})

Expected behaviour

Somehow prevent it in the distant future, since as Heron said, there is no way to fix it now.

Additional context

No response

Operating system

Windows 11

Version

15.0-dev404

Crashdump ID

No response

Reproduction tested

xxshady commented 1 year ago

It's core issue, and Heron said it wont be fixed