mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 17:26:42 +00:00
Fix broken intent handling (#1801)
## Description: Restore code that was accidentally deleted in the previous PR. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced
This commit is contained in:
@@ -40,13 +40,52 @@ export async function postJoinMessageHandler(
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (clientMsg.intent.type === "mark_disconnected") {
|
||||
log.warn(
|
||||
`Should not receive mark_disconnected intent from client`,
|
||||
);
|
||||
return;
|
||||
switch (clientMsg.intent.type) {
|
||||
case "mark_disconnected": {
|
||||
log.warn(`Should not receive mark_disconnected intent from client`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle kick_player intent via WebSocket
|
||||
case "kick_player": {
|
||||
const authenticatedClientID = client.clientID;
|
||||
|
||||
// Check if the authenticated client is the lobby creator
|
||||
if (authenticatedClientID !== gs.lobbyCreatorID) {
|
||||
log.warn(`Only lobby creator can kick players`, {
|
||||
clientID: authenticatedClientID,
|
||||
creatorID: gs.lobbyCreatorID,
|
||||
gameID: gs.id,
|
||||
target: clientMsg.intent.target,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't allow lobby creator to kick themselves
|
||||
if (authenticatedClientID === clientMsg.intent.target) {
|
||||
log.warn(`Cannot kick yourself`, {
|
||||
clientID: authenticatedClientID,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Log and execute the kick
|
||||
log.info(`Lobby creator initiated kick of player`, {
|
||||
creatorID: authenticatedClientID,
|
||||
gameID: gs.id,
|
||||
kickMethod: "websocket",
|
||||
target: clientMsg.intent.target,
|
||||
});
|
||||
|
||||
gs.kickClient(clientMsg.intent.target);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
gs.addIntent(clientMsg.intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
gs.addIntent(clientMsg.intent);
|
||||
break;
|
||||
}
|
||||
case "ping": {
|
||||
@@ -82,9 +121,9 @@ function handleWinner(
|
||||
client: Client, clientMsg: ClientSendWinnerMessage) {
|
||||
if (
|
||||
gs.outOfSyncClients.has(client.clientID) ||
|
||||
gs.kickedClients.has(client.clientID) ||
|
||||
gs.winner !== null ||
|
||||
client.reportedWinner !== null
|
||||
gs.kickedClients.has(client.clientID) ||
|
||||
gs.winner !== null ||
|
||||
client.reportedWinner !== null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user