Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying max number of players via "/create-table" URL (?maxPlayers= or ?numPlayers=) #2986

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions packages/client/src/lobby/url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ServerCommandWelcomeData } from "@hanabi-live/data";
import { DEFAULT_CREATE_TABLE_MAX_PLAYERS } from "@hanabi-live/data";
import { DEFAULT_VARIANT_NAME } from "@hanabi-live/game";
import { parseIntSafe } from "complete-common";
import { globals } from "../Globals";
Expand Down Expand Up @@ -32,6 +33,11 @@ export function parseAndGoto(data: ServerCommandWelcomeData): void {
const detrimentalCharacters =
urlParams.get("detrimentalCharacters") === "true";
const password = urlParams.get("password") ?? "";
const maxPlayers = parseIntSafe(
urlParams.get("maxPlayers") ??
urlParams.get("numPlayers") ??
DEFAULT_CREATE_TABLE_MAX_PLAYERS.toString()
);

globals.conn!.send("tableCreate", {
name,
Expand All @@ -50,6 +56,7 @@ export function parseAndGoto(data: ServerCommandWelcomeData): void {
detrimentalCharacters,
},
password,
maxPlayers,
});
return;
}
Expand Down Expand Up @@ -89,7 +96,7 @@ export function parseAndGoto(data: ServerCommandWelcomeData): void {
const shadowingPlayerIndexString = shadowMatch[1];
if (shadowingPlayerIndexString !== undefined) {
const shadowingPlayerIndexInt = parseIntSafe(
shadowingPlayerIndexString,
shadowingPlayerIndexString
);
if (
shadowingPlayerIndexInt !== undefined &&
Expand All @@ -110,7 +117,7 @@ export function parseAndGoto(data: ServerCommandWelcomeData): void {

// Automatically go into a replay if we are using a "/(shared-)?replay/123" URL.
const replayMatch = /\/(?:shared-)?replay\/(\d+)/.exec(
window.location.pathname,
window.location.pathname
);
if (replayMatch !== null) {
const databaseIDString = replayMatch[1];
Expand All @@ -134,7 +141,7 @@ export function parseAndGoto(data: ServerCommandWelcomeData): void {
// Automatically go into a replay if we are using a "/replay-json/string" or
// "/shared-replay-json/string" URL.
const replayJSONMatch = /\/(?:shared-)?replay-json\/([\d,A-Za-z-]+)$/.exec(
window.location.pathname,
window.location.pathname
);
if (replayJSONMatch !== null) {
const gameJSONStringCompressed = replayJSONMatch[1];
Expand Down
Loading