Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle cases where getPlayerSlot() returns undefined #14

Merged
merged 1 commit into from Nov 17, 2021
Merged

Handle cases where getPlayerSlot() returns undefined #14

merged 1 commit into from Nov 17, 2021

Conversation

kiwec
Copy link
Contributor

@kiwec kiwec commented Nov 3, 2021

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

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.
@ThePooN
Copy link
Owner

ThePooN commented Nov 17, 2021

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.

@ThePooN ThePooN merged commit 8d65000 into ThePooN:master Nov 17, 2021
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.

None yet

2 participants