Skip to content

Commit e509ccd

Browse files
author
gyorokpeter
committed
force disconnect player if invalid lobby is provided, so they don't get locked out for 60 seconds
1 parent 06be9d8 commit e509ccd

5 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/server/src/lobby/LobbyManager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export class LobbyManager {
5757
},
5858
player: data.player,
5959
});
60+
this.pubSub.publish(Events.PlayerShouldDisconnect, {
61+
event: LegacyEvents.EVENTS.LOBBY_EXCEPTION,
62+
payload: {
63+
error: "Unable to join lobby, ensure token is correct",
64+
},
65+
player: data.player,
66+
});
6067
}
6168
}
6269

packages/server/src/pub-sub/Events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export enum Events {
1313
LobbyPlayerBan = "LobbyPlayerBan",
1414
LobbyPlayerKick = "LobbyPlayerKick",
1515
PlayerDisconnected = "PlayerDisconnected",
16+
PlayerShouldDisconnect = "PlayerShouldDisconnect",
1617
}

packages/server/src/socket/SocketServer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class SocketServer {
7474
this.pubSub.subscribe(PubSubEvents.BroadcastNamespaced, this.sendMessageToNamespace);
7575
this.pubSub.subscribe(PubSubEvents.AddPlayerToNamespace, this.addPlayerToNamespace);
7676
this.pubSub.subscribe(PubSubEvents.GameList, this.sendGameListToEveryone);
77+
this.pubSub.subscribe(PubSubEvents.PlayerShouldDisconnect, this.disconnectPlayer);
7778
}
7879

7980
private addPlayerToNamespace = (data: Messages.ADD_PLAYER_TO_NAMESPACE_MESSAGE) => {
@@ -136,6 +137,15 @@ export class SocketServer {
136137
}
137138
}
138139

140+
private disconnectPlayer = (data: Messages.ADD_PLAYER_TO_NAMESPACE_MESSAGE) => {
141+
if (!this.playerSockets[data.player]) {
142+
debug("Error disconnecting player (%s), player socket does not exist", data.player);
143+
return;
144+
}
145+
debug("Disconnecting player (%s)", data.player);
146+
this.playerSockets[data.player].disconnect();
147+
}
148+
139149
private onPlayerDisconnect = (player: Player) => () => {
140150
debug("Removing player (%s) from server", player);
141151
delete this.playerSockets[player];

packages/ui/src/components/Lobby/Tournament/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class MatchPage extends React.PureComponent {
8080
return (
8181
<Button
8282
icon='play'
83-
content={this.props.tournament.matches.length > 0 ? 'Play Next Match' : 'Start Tournament'}
83+
content={this.props.tournament.matches == null ? 'no matches' : this.props.tournament.matches.length > 0 ? 'Play Next Match' : 'Start Tournament'}
8484
onClick={this.props.continueMatches}
8585
disabled={ disabled }
8686
size='tiny'

packages/ui/src/components/Lobby/Tournament/types/Brackets/parseStats.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
export const parseStats = stats => {
88
const matches = stats.matches;
99
const brackets = [];
10+
if (!matches) return brackets;
1011
// Prepare a map of matches for quick reference
1112
const matchesRef = {};
1213
matches.forEach(match => {

0 commit comments

Comments
 (0)