mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 17:53:29 +00:00
Bugfix: Kick player in private lobby not working
Nginx was stripping query params when routing requests to workers, so the creatorClientID param was stripped when creating a private game. This caused the game server to not know who the lobby owner was, so it rejected the kick requests.
This commit is contained in:
+2
-1
@@ -307,7 +307,8 @@ server {
|
|||||||
if ($worker = "39") { set $worker_port 3040; }
|
if ($worker = "39") { set $worker_port 3040; }
|
||||||
if ($worker = "40") { set $worker_port 3041; }
|
if ($worker = "40") { set $worker_port 3041; }
|
||||||
|
|
||||||
proxy_pass http://127.0.0.1:$worker_port$2;
|
# Preserve query string by appending $is_args$args
|
||||||
|
proxy_pass http://127.0.0.1:$worker_port$2$is_args$args;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection $connection_upgrade;
|
proxy_set_header Connection $connection_upgrade;
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ export class GameServer {
|
|||||||
private turns: Turn[] = [];
|
private turns: Turn[] = [];
|
||||||
private intents: Intent[] = [];
|
private intents: Intent[] = [];
|
||||||
public activeClients: Client[] = [];
|
public activeClients: Client[] = [];
|
||||||
private LobbyCreatorID: string | undefined;
|
|
||||||
private allClients: Map<ClientID, Client> = new Map();
|
private allClients: Map<ClientID, Client> = new Map();
|
||||||
private clientsDisconnectedStatus: Map<ClientID, boolean> = new Map();
|
private clientsDisconnectedStatus: Map<ClientID, boolean> = new Map();
|
||||||
private _hasStarted = false;
|
private _hasStarted = false;
|
||||||
@@ -75,10 +74,9 @@ export class GameServer {
|
|||||||
public readonly createdAt: number,
|
public readonly createdAt: number,
|
||||||
private config: ServerConfig,
|
private config: ServerConfig,
|
||||||
public gameConfig: GameConfig,
|
public gameConfig: GameConfig,
|
||||||
lobbyCreatorID?: string,
|
private lobbyCreatorID?: string,
|
||||||
) {
|
) {
|
||||||
this.log = log_.child({ gameID: id });
|
this.log = log_.child({ gameID: id });
|
||||||
this.LobbyCreatorID = lobbyCreatorID ?? undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateGameConfig(gameConfig: Partial<GameConfig>): void {
|
public updateGameConfig(gameConfig: Partial<GameConfig>): void {
|
||||||
@@ -134,10 +132,10 @@ export class GameServer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Log when lobby creator joins private game
|
// Log when lobby creator joins private game
|
||||||
if (client.clientID === this.LobbyCreatorID) {
|
if (client.clientID === this.lobbyCreatorID) {
|
||||||
this.log.info("Lobby creator joined", {
|
this.log.info("Lobby creator joined", {
|
||||||
gameID: this.id,
|
gameID: this.id,
|
||||||
creatorID: this.LobbyCreatorID,
|
creatorID: this.lobbyCreatorID,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.log.info("client (re)joining game", {
|
this.log.info("client (re)joining game", {
|
||||||
@@ -249,13 +247,11 @@ export class GameServer {
|
|||||||
|
|
||||||
// Handle kick_player intent via WebSocket
|
// Handle kick_player intent via WebSocket
|
||||||
case "kick_player": {
|
case "kick_player": {
|
||||||
const authenticatedClientID = client.clientID;
|
|
||||||
|
|
||||||
// Check if the authenticated client is the lobby creator
|
// Check if the authenticated client is the lobby creator
|
||||||
if (authenticatedClientID !== this.LobbyCreatorID) {
|
if (client.clientID !== this.lobbyCreatorID) {
|
||||||
this.log.warn(`Only lobby creator can kick players`, {
|
this.log.warn(`Only lobby creator can kick players`, {
|
||||||
clientID: authenticatedClientID,
|
clientID: client.clientID,
|
||||||
creatorID: this.LobbyCreatorID,
|
creatorID: this.lobbyCreatorID,
|
||||||
target: clientMsg.intent.target,
|
target: clientMsg.intent.target,
|
||||||
gameID: this.id,
|
gameID: this.id,
|
||||||
});
|
});
|
||||||
@@ -263,16 +259,16 @@ export class GameServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't allow lobby creator to kick themselves
|
// Don't allow lobby creator to kick themselves
|
||||||
if (authenticatedClientID === clientMsg.intent.target) {
|
if (client.clientID === clientMsg.intent.target) {
|
||||||
this.log.warn(`Cannot kick yourself`, {
|
this.log.warn(`Cannot kick yourself`, {
|
||||||
clientID: authenticatedClientID,
|
clientID: client.clientID,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log and execute the kick
|
// Log and execute the kick
|
||||||
this.log.info(`Lobby creator initiated kick of player`, {
|
this.log.info(`Lobby creator initiated kick of player`, {
|
||||||
creatorID: authenticatedClientID,
|
creatorID: client.clientID,
|
||||||
target: clientMsg.intent.target,
|
target: clientMsg.intent.target,
|
||||||
gameID: this.id,
|
gameID: this.id,
|
||||||
kickMethod: "websocket",
|
kickMethod: "websocket",
|
||||||
@@ -517,10 +513,6 @@ export class GameServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public isPrivateLobbyCreator(clientID: string): boolean {
|
|
||||||
return this.LobbyCreatorID === clientID;
|
|
||||||
}
|
|
||||||
|
|
||||||
phase(): GamePhase {
|
phase(): GamePhase {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const alive: Client[] = [];
|
const alive: Client[] = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user