Skip to content
Browse files
Games: announce joining/leaving of players in continuous games
  • Loading branch information
RussellLVP committed Aug 1, 2020
1 parent 18b7033 commit 356eebdaa4f9e1b87c6878178103980c6c91bbb7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
@@ -160,6 +160,8 @@
"FRIENDS_REMOVED": "@success %s has been removed from your friends list.",
"FRIENDS_USAGE": "{FFFFFF}Use '/friends add' to add a friend or '/friends remove' to remove one.",

"GAME_CONTINUOUS_JOINED": "{CCD782}* %s has joined the %s.",
"GAME_CONTINUOUS_LEFT": "{CCD782}* %s has left the %s.",
"GAME_REGISTRATION_ANNOUNCEMENT": "{CCD782}Sign up for the {838F31}%s{CCD782}! Type {838F31}/%s{CCD782} to join for %$.",
"GAME_REGISTRATION_ANNOUNCEMENT_FREE": "{CCD782}Sign up for the {838F31}%s{CCD782}! Type {838F31}/%s{CCD782} to join.",
"GAME_REGISTRATION_CREATED": "{CCD782}Please allow for up to {838F31}%d seconds{CCD782} for the game to start.",
@@ -160,6 +160,21 @@ export class GameRuntime extends GameActivity {

// Formally introduce the |player| to the game.
await this.game_.onPlayerAdded(player);

// If the game had already started, we need to immediately spawn the |player| as well and
// tell the other players that they have joined the game.
if (this.state_ === GameRuntime.kStateRunning) {
const gameName = this.description_.nameFn(this.settings_);

for (const target of this.players_) {
if (target === player)
continue; // no need to inform the |player| about their participation

target.sendMessage(Message.GAME_CONTINUOUS_JOINED,, gameName);

await this.onPlayerSpawn(player);

// Called when the |player| has to be removed from the game, either because they disconnected,
@@ -180,6 +195,15 @@ export class GameRuntime extends GameActivity {
// Restore the |player|'s state -- back as if nothing ever happened.
if (!disconnecting)

// If the game is continuous, inform the remaining participants (if any) about the |player|
// having left. This might influence their decision to stick around.
if (this.description_.continuous) {
const gameName = this.description_.nameFn(this.settings_);

for (const target of this.players_)
target.sendMessage(Message.GAME_CONTINUOUS_LEFT,, gameName);

// ---------------------------------------------------------------------------------------------
@@ -467,6 +467,7 @@ describe('GameRuntime', (it, beforeEach) => {
// (1) The game should start immediately for |gunther|, even though other players are
// available. This is because it's been marked as a continuous game.
assert.isTrue(await gunther.issueCommand('/bubblegame'));
assert.equal(gunther.messages.length, 1);

@@ -477,6 +478,12 @@ describe('GameRuntime', (it, beforeEach) => {
// (2) Have Russell join the game as well. They should be added to the active game, rather
// than be routed through registration and in a new game instead.
assert.isTrue(await russell.issueCommand('/bubblegame'));
assert.equal(russell.messages.length, 1);

assert.equal(gunther.messages.length, 2);
Message.format(Message.GAME_CONTINUOUS_JOINED,, 'Bubble'));

@@ -488,6 +495,11 @@ describe('GameRuntime', (it, beforeEach) => {
// (3) Have Gunther leave the game. Russell should still be playing.
assert.isTrue(await gunther.issueCommand('/leave'));

assert.equal(russell.messages.length, 2);
Message.format(Message.GAME_CONTINUOUS_LEFT,, 'Bubble'));

assert.equal(activePlayers, 1);

0 comments on commit 356eebd

Please sign in to comment.