-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Custom tribe names in public games #4727
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ecc9a07
Custom tribe names in public games
evanpelle 7d5a075
Simplify tribes to plain names
evanpelle 6e31d22
Embed tribes as {name} objects to match the analytics contract
evanpelle 2f3bd06
Make TribeSchema loose + document the positioned-tribe over-count
evanpelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { z } from "zod"; | ||
| import { Tribe, TribeSchema } from "../core/Schemas"; | ||
| import { ServerEnv } from "./ServerEnv"; | ||
|
|
||
| // TribeSchema is loose: extra per-tribe fields the API sends pass through | ||
| // into the game start info (and thus the analytics record) unchanged. | ||
| const CustomTribesResponseSchema = z.object({ | ||
| tribes: TribeSchema.array().max(100), | ||
| }); | ||
|
|
||
| // A logged-in human in the lobby: in-game client id + account public id. | ||
| // Guests can't own tribe names and must be omitted. | ||
| export interface TribePoolPlayer { | ||
| clientId: string; | ||
| publicId: string; | ||
| } | ||
|
|
||
| /** | ||
| * Fetch the boost-weighted pool of purchased bot tribe names for a game: | ||
| * up to 10 owned by lobby players, then up to 10 from the global pool | ||
| * (array order carries the slicing, so callers drop from the tail). | ||
| * | ||
| * Throws on timeout/non-200/malformed response — callers fail open and | ||
| * start the game with organic bot names. The timeout must fit inside the | ||
| * 2s prestart->start window (see GameManager.tick). | ||
| */ | ||
| export async function fetchCustomTribes( | ||
| players: TribePoolPlayer[], | ||
| ): Promise<Tribe[]> { | ||
| const response = await fetch(`${ServerEnv.jwtIssuer()}/custom_tribes`, { | ||
| method: "POST", | ||
| signal: AbortSignal.timeout(1500), | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-api-key": ServerEnv.apiKey(), | ||
| }, | ||
| body: JSON.stringify({ players: players.slice(0, 500) }), | ||
| }); | ||
| if (!response.ok) { | ||
| throw new Error(`custom_tribes returned ${response.status}`); | ||
| } | ||
| const parsed = CustomTribesResponseSchema.safeParse(await response.json()); | ||
| if (!parsed.success) { | ||
| throw new Error( | ||
| `custom_tribes returned malformed response: ${parsed.error.message}`, | ||
| ); | ||
| } | ||
| return parsed.data.tribes; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Send this request to the master endpoint, not the JWT issuer.
Line 28 derives the destination from
jwtIssuer()while sending an internal API key. In this deployment, master requests must targethttp://localhost:3000; an issuer URL can be a different service, causing failed tribe retrieval or credential disclosure to the wrong internal/external endpoint. Centralize the master base URL inServerEnvand use it here. Based on learnings, “inter-service HTTP calls to the master should target http://localhost:3000 … [as] the canonical address.”🤖 Prompt for AI Agents
Source: Learnings