tetrjs / tetr.js

An API Wrapper For TETR.IO
https://tetr.js.org/
MIT License
28 stars 3 forks source link

Disconnecting right after a round finishes leaves round victor unknown #62

Open mat1jaczyyy opened 2 months ago

mat1jaczyyy commented 2 months ago

If a player wins a round and then immediately disconnects before the room.game.on("score", event can fire, then victor will be undefined.

/srv/eucannon-test/bot/index.js:453
                .input('winner', room.tournament_match.players.indexOf(victor.user.id) + 1)
                                                                              ^

TypeError: Cannot read properties of undefined (reading 'user')
    at Game.<anonymous> (/srv/eucannon-test/bot/index.js:453:79)
    at Game.emit (node:events:518:28)
    at /srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:60:29
    at Generator.next (<anonymous>)
    at /srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:4:12)
    at default_1 (/srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/commands/game.end.js:14:12)
    at WebSocketManager.<anonymous> (/srv/eucannon-test/bot/node_modules/tetr.js/dist/ws/WebSocketManager.js:187:23)
    at Generator.next (<anonymous>)

In EU Cannon code:

https://github.com/EUCannon/bot/blob/94b0a303cb1f6771537fba8d711d16a07a6913de/index.js#L447-L454

mat1jaczyyy commented 2 months ago

https://github.com/tetrjs/tetr.js/assets/13300194/237d0e19-20a3-4b3a-a89e-90e66effc715

Sup3rFire commented 2 months ago

After some investigation, it seems like the game.score and game.end set the success field of the victor to false, causing tetr.js to not recognize a winner and not defining it instead.