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

add player disconnect detect #378

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion extensions/battleroyale/standalone.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,19 @@ class Standalone {
// No location? Just skip.
return;
}

if (msg.removed) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can consider making killPlayer() tolerant of player not being online, then change this to call killPlayer() instead.

However, it's only a small improvement in terms of reusing code, so it's up to you on if you want to make the change or just merge the current variant as is.

console.log(`${playerID} disconnect`)
// player disconnect, remove player if exists
if (this.participatePlayerIDs.has(playerID)) {
this.participatePlayerIDs.delete(playerID);
}
if (this.playerOldPosition.has(playerID)) {
this.playerOldPosition.delete(playerID);
}
if (this.participatePlayerIDs.size <= 1) {
await this.terminateGame();
}
}
const bullets = this.helper.gameMap.getCell(mapCoord, LAYER_BULLET.layerName);
if (bullets) {
await this.killPlayer(playerID);
Expand Down
14 changes: 14 additions & 0 deletions extensions/bombman/standalone.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,20 @@ class Standalone {
// No location? Just skip.
return;
}

if (msg.removed) {
// player disconnect, remove player if exists
if (this.participatePlayerIDs.has(playerID)) {
this.participatePlayerIDs.delete(playerID);
}
if (this.playerOldPosition.has(playerID)) {
this.playerOldPosition.delete(playerID);
}
if (this.participatePlayerIDs.size <= 1) {
await this.terminateGame();
}
}

const explodeCell = this.helper.gameMap.getCell(mapCoord, LAYER_BOMB_EXPLODE.layerName);
if (explodeCell) { // if walk into bomb => teleport to somewhere
await this.killPlayer(playerID);
Expand Down