ThePooN / bancho.js

Interface with Bancho over IRC, made easy and reliable.
https://bancho.js.org
GNU General Public License v3.0
57 stars 6 forks source link

Handle cases where getPlayerSlot() returns undefined #14

Closed kiwec closed 2 years ago

kiwec commented 2 years ago

When bancho.js joins an existing lobby, you can receive playerMoved or playerLeft events before bancho.js had the time to fetch the lobby info. When that happens, an unhandled error is thrown, since "undefined" is not a valid key for the slots array.

I chose to just check if getPlayerSlot() returns something, but a better fix might be to ignore those events until the lobby is initialized.

Original errors (as logged by sentry):

TypeError: Cannot add property undefined, object is not extensible
  File "/root/osubot/node_modules/bancho.js/lib/Multiplayer/BanchoLobby.js", line 224, col 28, in null.<anonymous>
    this.slots[oldSlot] = null;
  File "node:internal/process/task_queues", line 96, col 5, in processTicksAndRejections
TypeError: Cannot add property undefined, object is not extensible
  File "/root/osubot/node_modules/bancho.js/lib/Multiplayer/BanchoLobby.js", line 242, col 25, in null.<anonymous>
    this.slots[slot] = null;
  File "node:internal/process/task_queues", line 96, col 5, in processTicksAndRejections
ThePooN commented 2 years ago

Eh, it has never been ignoring the events, and I don't see much stuff that can go wrong with pre-!mp settings events really. It's probably fine to handle these as you have.