mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 07:07:05 +00:00
2e2e686699
## Description: This implements the backend for multiple lobbies in preparation for https://github.com/openfrontio/OpenFrontIO/pull/3191 The server now schedules & sends a map of game type (ffa, teams, special) => public lobbies. NOTE: this is just temporary, the lobby only shows ffa currently. Have the Master scheduler schedule ffa, teams, & special games. ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { z } from "zod";
|
|
import {
|
|
GameConfigSchema,
|
|
PublicGameInfoSchema,
|
|
PublicGamesSchema,
|
|
PublicGameTypeSchema,
|
|
} from "../core/Schemas";
|
|
|
|
export type WorkerLobbyList = z.infer<typeof WorkerLobbyListSchema>;
|
|
export type WorkerReady = z.infer<typeof WorkerReadySchema>;
|
|
export type MasterLobbiesBroadcast = z.infer<
|
|
typeof MasterLobbiesBroadcastSchema
|
|
>;
|
|
export type MasterCreateGame = z.infer<typeof MasterCreateGameSchema>;
|
|
export type WorkerMessage = z.infer<typeof WorkerMessageSchema>;
|
|
export type MasterMessage = z.infer<typeof MasterMessageSchema>;
|
|
|
|
// --- Worker Messages ---
|
|
|
|
// Worker tells the master about its lobbies.
|
|
const WorkerLobbyListSchema = z.object({
|
|
type: z.literal("lobbyList"),
|
|
lobbies: z.array(PublicGameInfoSchema),
|
|
});
|
|
|
|
const WorkerReadySchema = z.object({
|
|
type: z.literal("workerReady"),
|
|
workerId: z.number(),
|
|
});
|
|
|
|
export const WorkerMessageSchema = z.discriminatedUnion("type", [
|
|
WorkerLobbyListSchema,
|
|
WorkerReadySchema,
|
|
]);
|
|
|
|
// --- Master Messages ---
|
|
|
|
// Broadcasts all public game info to all workers.
|
|
// Workers need information on all public lobbies so
|
|
// it can send it to the client.
|
|
const MasterLobbiesBroadcastSchema = z.object({
|
|
type: z.literal("lobbiesBroadcast"),
|
|
publicGames: PublicGamesSchema,
|
|
});
|
|
|
|
// Master sends a message to worker to schedule a new public game/lobby.
|
|
const MasterCreateGameSchema = z.object({
|
|
type: z.literal("createGame"),
|
|
gameID: z.string(),
|
|
gameConfig: GameConfigSchema,
|
|
startsAt: z.number(),
|
|
publicGameType: PublicGameTypeSchema,
|
|
});
|
|
|
|
export const MasterMessageSchema = z.discriminatedUnion("type", [
|
|
MasterLobbiesBroadcastSchema,
|
|
MasterCreateGameSchema,
|
|
]);
|