Skip to content
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
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,4 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
2 changes: 1 addition & 1 deletion src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
/>
</g>
</svg>
<div class="l-header__highlightText">v23.0</div>
<div class="l-header__highlightText">v0.1.0</div>
</div>
</header>
<div class="bg-image"></div>
Expand Down
116 changes: 61 additions & 55 deletions src/server/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,72 +294,78 @@ export function startWorker() {

try {
// Parse and handle client messages
const parsed = ClientJoinMessageSchema.safeParse(
JSON.parse(message.toString()),
);
if (!parsed.success) {
const error = z.prettifyError(parsed.error);
log.warn("Error parsing join message client", error);
ws.close();
return;
}
const clientMsg = parsed.data;

if (clientMsg.type === "join") {
// Verify this worker should handle this game
const expectedWorkerId = config.workerIndex(clientMsg.gameID);
if (expectedWorkerId !== workerId) {
log.warn(
`Worker mismatch: Game ${clientMsg.gameID} should be on worker ${expectedWorkerId}, but this is worker ${workerId}`,
);
log.warn(`Raw WebSocket message: ${message.toString()}`);
const raw = JSON.parse(message.toString());

if (raw?.type === "join") {
const parsed = ClientJoinMessageSchema.safeParse(
JSON.parse(message.toString()),
);
if (!parsed.success) {
log.warn("ClientJoinMessage parsing failed:");
for (const issue of parsed.error.errors) {
log.warn(` → [${issue.path.join(".")}] ${issue.message}`);
}
ws.close();
return;
}
const clientMsg = parsed.data;

if (clientMsg.type === "join") {
// Verify this worker should handle this game
const expectedWorkerId = config.workerIndex(clientMsg.gameID);
if (expectedWorkerId !== workerId) {
log.warn(
`Worker mismatch: Game ${clientMsg.gameID} should be on worker ${expectedWorkerId}, but this is worker ${workerId}`,
);
return;
}

const { persistentId, claims } = await verifyClientToken(
clientMsg.token,
config,
);
const { persistentId, claims } = await verifyClientToken(
clientMsg.token,
config,
);

let roles: string[] | undefined;
let roles: string[] | undefined;

// Check user roles
if (claims !== null) {
const result = await getUserMe(clientMsg.token, config);
if (result === false) {
log.warn("Token is not valid", claims);
return;
// Check user roles
if (claims !== null) {
const result = await getUserMe(clientMsg.token, config);
if (result === false) {
log.warn("Token is not valid", claims);
return;
}
roles = result.player.roles;
}
roles = result.player.roles;
}

// TODO: Validate client settings based on roles

// Create client and add to game
const client = new Client(
clientMsg.clientID,
persistentId,
claims,
roles,
ip,
clientMsg.username,
ws,
clientMsg.flag,
);

const wasFound = gm.addClient(
client,
clientMsg.gameID,
clientMsg.lastTurn,
);
// TODO: Validate client settings based on roles

// Create client and add to game
const client = new Client(
clientMsg.clientID,
persistentId,
claims,
roles,
ip,
clientMsg.username,
ws,
clientMsg.flag,
);

if (!wasFound) {
log.info(
`game ${clientMsg.gameID} not found on worker ${workerId}`,
const wasFound = gm.addClient(
client,
clientMsg.gameID,
clientMsg.lastTurn,
);
// Handle game not found case

if (!wasFound) {
log.info(
`game ${clientMsg.gameID} not found on worker ${workerId}`,
);
// Handle game not found case
}
}
}

// Handle other message types
} catch (error) {
log.warn(
Expand Down
2 changes: 1 addition & 1 deletion supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ user=node
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stderr_logfile_maxbytes=0
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default async (env, argv) => {
},
historyApiFallback: true,
compress: true,
port: 3000,
port: 9000,
proxy: [
// WebSocket proxies
{
Expand Down
Loading