Game protocol v1
هذا المحتوى غير متوفر بلغتك بعد.
How a game integration (a mod) or a screen (an overlay, a phone page) talks to the hub. You can write an integration in any language that has JSON and WebSocket.
The source of truth is packages/protocol/src/messages.ts. JSON Schema files for other languages are in packages/protocol/schema/. The Hollow Knight mod (C#) and the simulator (TypeScript) are working examples.
1. Find the hub
Section titled “1. Find the hub”When the hub starts, it writes a discovery file:
- Windows:
%APPDATA%\game-learning\hub.json - macOS:
~/Library/Application Support/game-learning/hub.json - Linux:
~/.config/game-learning/hub.json
{ "protocol": "1", "port": 47474, "token": "3f9c…", "pid": 1234 }If the file is missing, the hub is not running. Retry every few seconds.
2. Connect and say hello
Section titled “2. Connect and say hello”Open ws://127.0.0.1:<port>/. The first message must be hello (within 5 seconds):
{ "type": "hello", "protocol": "1", "role": "game", "token": "<token from hub.json>", "integration": { "id": "hollow-knight", "name": "Hollow Knight mod", "version": "0.1.0" }, "game": { "id": "hollow-knight", "name": "Hollow Knight" }, "capabilities": { "events": ["player.died", "player.rested"], "effects": ["currency.grant", "health.restore"] }}The hub answers { "type": "welcome", "protocol": "1", "sessionId": "…" }, or { "type": "error", "code": "unauthorized" | "unsupported-protocol" | "bad-message", "message": "…" } and closes.
Declare only what you really support. The hub offers a reward only if the game listed its effect.
3. Send events
Section titled “3. Send events”{ "type": "event", "id": "<unique id, e.g. a UUID>", "name": "player.died", "at": "2026-11-21T13:05:00Z"}data is optional, for example { "scene": "Crossroads_01" }. The hub ignores repeated ids, so retrying is safe.
Standard events
Section titled “Standard events”| Name | When |
|---|---|
player.died |
The player died |
player.rested |
The player sat at a safe spot (a bench, a bed) |
boss.started / boss.ended |
A boss fight starts or ends |
scene.changed |
The player moved to another room or level (data.scene) |
area.entered |
The player entered a different region (data.area), e.g. Greenpath |
loading.started |
The game started loading (a room change): a good moment for a fact |
npc.talked |
The player started talking to a character (data.npc) |
game.paused / game.resumed |
The game was paused or resumed |
Game-specific events use a prefix: hollow-knight:charm.equipped.
4. Apply effects
Section titled “4. Apply effects”The hub may ask the game for a reward:
{ "type": "effect", "id": "e-123", "name": "currency.grant", "params": { "amount": 50 } }Apply it on the game’s main thread, then answer:
{ "type": "effect.result", "effectId": "e-123", "status": "applied" }status is applied, rejected (you chose not to, for example during a cutscene) or failed (an error; add message). The player is told about the reward only after applied.
Standard effects
Section titled “Standard effects”| Name | params | Meaning |
|---|---|---|
currency.grant |
amount |
Give in-game money (Geo in Hollow Knight) |
health.restore |
amount |
Restore health |
message.show |
text, language |
Show a short message in the game |
5. Screens (clients)
Section titled “5. Screens (clients)”Screens say hello with "role": "client" and a client object instead of integration/game. They receive state, challenge, feedback and reward messages, and send answer and dismiss. The answer to a question never reaches a screen before the player answers.
6. Surfaces and other devices
Section titled “6. Surfaces and other devices”Any screen can say what it is, so the hub can adapt (all optional):
"surface": { "kind": "phone", "input": ["touch"], "audio": true, "lineLength": 32 }kind: overlay, phone, tablet, tv, web, terminal, in-game. input: keyboard, mouse, touch, controller, voice.
- Screens put it in their hello (
"surface": …next toclient). - Play state: a game that declares
play.startedsends it when a save is loaded andplay.stoppedat the title screen or a menu. Warm-up, timed questions, study breaks and play time then wait for actual play. Games that do not declare it count as always playing. - Settings in the game’s menu: a game with
capabilities.settingsMenu: truegets{ "type": "settings", "values", "locked" }on connect and after each change, and may send{ "type": "settings.set", "key", "value" }. The app checks the value, saves it and applies it (most settings without a restart); the game getssettingsagain after every change, also changes made in the app. Refused while a PIN locks the settings. - Hints: a challenge with
hints: nlets the player ask for up to n hints:{ "type": "hint.request", "challengeId" }. The hub answers every screen withhint(removeChoices: all greyed-out choice indexes so far, keys keep their numbers;text/title: a clue or the lesson part;remaining). A right answer after a hint earns half the reward and is scheduled as “hard”. - Study breaks: the hub sends
break(state:started,progress,ended;unlock,done,needed,skippable). Games with their own UI pause until it ends; other screens cover the game. Questions come as usual during the break. A screen may send{ "type": "break.skip", "breakId" }whenskippable. - Lessons and facts: the hub may send a
lesson(id,title, Markdownbody) before a question, e.g. at a bench; the screen shows it with a Continue button and answers{ "type": "lesson.done", "lessonId" }, and the hub then asks the question. Afact(text, optionalsource) is shown without stopping play (e.g. while loading) and needs no answer. Games with their own UI get both too. - Question kinds: a challenge
viewismultiple-choice,true-false,typed,ordering(shuffleditems) ormatching(leftin order,rightshuffled). Answers are{ "kind": "choice", "index" },{ "kind": "boolean", "value" },{ "kind": "text", "value" },{ "kind": "order", "items": [...] }(item texts in the chosen order) or{ "kind": "pairs", "right": [...] }(the partner of eachleftitem). A surface lists what it can show inquestionKinds; without it, onlymultiple-choiceandtrue-falseare sent to it. - Games that can show questions in their own UI put it in
capabilities.surface. They then receivechallenge,feedbackandrewardlike a screen, and may sendansweranddismiss. A game withoutcapabilities.surfacethat sends an answer gets abad-messageerror. - The companion in the game: a game that draws the companion itself sets
capabilities.companion: true. While it also shows the questions,statemarks it with"drawsCompanion": true, so other screens can hide their own companion (the desktop overlay does when the player’scompanionInGamesetting is on). Thesettingsmessage also carrieslanguage(the content’s language) for the game’s own text. - The
statemessage marks such games with"showsChallenges": true, so other screens can step back (the overlay then only reads the question aloud). The player can turn this off (questionScreen: "overlay"); the game then getsshowsChallenges: falseand no challenges. - The Hollow Knight mod is the reference: it pauses the game, draws the card, and reads keyboard and controller (
integrations/hollow-knight/src/QuestionCard.cs).
This is how console players can learn inside a game (for example through a Minecraft Bedrock server). See PLATFORMS.md.
Versioning
Section titled “Versioning”Within v1, changes only add optional fields and new message types. A breaking change means protocol 2, and the hub will speak both for a while.