Rooms
A room is a group of up to 8 players who play the same chart at the same time and see each other's scores, and up to 8 spectators who watch them play. Rooms live on phigros.tools, so a player needs a profile there (phigros.tools). They're a built-in mod (mods/multiplayer/): init.lua talks to the server and follows the match, screen.lua draws the rooms and the room.
The tab with two people next to the chapter screen's leaderboard lists the open rooms (GET /api/rooms), with "Create a room" on its right. Its top bar reads Rooms and Friends: tapping Friends shows the player's friends instead (Friends). A room has a name (24 characters at most, links are taken out, the player's name when empty) and may have a password: only the players who type it join, and nothing of what such a room plays shows on phigros.tools. A room without one is open to anyone, shows live on phigros.tools/rooms/<id> and keeps its matches there. That page's "Join in Phigros++" is a phigrospp://room/<id> link: it opens the game in the room, asking for the password when there's one. Invite, in the room, lists the player's friends who are online (Friends): a tap sends one a toast that joins the room.
In a room
The room's screen covers the menus. Its players are on the left, in the order they joined: the first is the host, under a golden crown, and the next one takes over when the host leaves. The chart to play is on the right with its difficulty and modifiers, the chat under the players. Chat lines only go to the players in the room: the server passes them on without keeping them, and the site never gets them.
Anyone adds charts to the room. Add chart hides the screen so the player can browse the game: playing a chart from the song list adds it to the room instead of starting it, at the level and with the modifiers picked there (Modifiers). The room is on the first chart added and queues the others after it, 20 at most and 3 from one player: they show under the chart as Up next, each with its level and who added it. The player who added a chart, or the host, takes it back with its cross, and the host orders the queue: holding a chart, then dragging it to its place. Rooms play the game's own EZ, HD, IN and AT charts, not custom ones.
Everyone plays the room's chart their own way. A player's row shows the level and modifiers they play it with: as the chart was added, until they tap the level under the cover (which goes to the next level of the song they have unlocked) or Modifiers. A chart with effects of its own plays without modifiers, as it does alone. A match ranks its plays by the total their modifiers give the score, whatever the levels played.
Tapping a player's row, anyone can ask them to be a friend, and the host can make them host instead or remove them, who then can't join that room again. Tapping the room's name renames it.
Each game tells the room whether it has the chart unlocked at the level its player picked. A player who doesn't is marked "No chart" and sits the match out, unless they pick a level they have: a room never gives a song the player doesn't own. The others tap Ready, and once everyone who has the chart is ready the host's Start sends them all into it, through the song list's own start (phigrospp.play). A chart played with Random is shuffled from a seed the server draws, the same for everyone.
A play in a room is a play like any other: recorded, saved by the game when it has no modifiers, and sent to phigros.tools with the player's toggles. While it lasts, the room's scores show on the left of the screen, best first ("Show the room's scores while playing"). The game sends its score once it changes, twice a second at most, and its result when the song ends. The others wait on it, so such a play can't be paused from its button nor started again (phigrospp.pausing(false)): Retry and Instant restart do nothing, and Perfect ends the song at anything but a perfect, as Sudden Death does. The game still pauses when the app goes to the background, and its menu then resumes or quits. A player who leaves the song before its end gave up. The match is over once nobody plays any more (or after 20 minutes), and everyone is back in the room with the match's ranking on their rows. The room then goes to the next chart of its queue, and stays on the one it played when nothing is queued: the next chart added takes its place.
Spectating
Spectate, next to Invite, turns a player into a spectator: their name shows grayed, they don't play the matches nor count among the 8 players, and they still chat. Tapping it again makes them a player, when a place is free. One who joins a room full of players joins it as a spectator. The host can spectate too, and still starts the matches.
Every play in a room is streamed as it's played: twice a second the game sends the frames recorded since the last time (phigrospp.replay.chunk, a replay of its own). During a match a spectator taps a player to watch their play in game, a couple of seconds behind it (phigrospp.replay.follow, the replay player without its controls): a play followed late is judged silently up to there first, and it waits when the frames come late. The cross leaves it, back to the room, to watch someone else.
Anyone can watch a room from its page on phigros.tools without signing in, with its password when it has one: the page then shows the room as its players see it (not its chat), and the play of the player picked under the chart player, judged as it comes by the same judge as uploaded replays. The players only see how many watch. A room takes one password a second, so it can't be guessed by trying them all.
The socket
The game keeps one WebSocket to wss://phigros.tools/api/room (phigrospp.socket, .NET's ClientWebSocket that the game ships), carrying JSON objects named by t. web/server/rooms.ts is the other end and says what each means. The server greets with a nonce, which the game signs with the profile's key (phigros.tools rooms v1\0 before it, so the signature is good for nothing else). Every change of the room then comes whole, scores included once a second while a match is played.
A connection that drops is made again every 3 seconds, and the server keeps the player's place for 30: what the game had to say meanwhile, its frames and result included, goes once it's back. A spectator back from a dropped connection asks for the stream from the part it missed, the server keeps the match's streams until it ends.
| From the game | |
|---|---|
create, join, leave | name and password, or room and password |
queue | A chart to add: song (the game's id), level, mods |
unqueue | Takes a chart back, by its entry: one's own, or any for the host |
move | The host's: puts the queued chart entry at the place to of the queue, from 0 |
pick | The level and mods the player plays the room's chart with |
chart | From a game older than the queue: its host's pick replaces the chart the room is on |
able, ready | Whether this game has the chart at the level picked, and whether the player is ready |
start, kick, host | The host's, kick and host (handing the room over) with a player id |
rename | The host's, with a name (empty names it after them) |
score, result, quit | The play as it goes, as it ended, or left before its end |
chat | text, 200 characters at most |
spectate | Whether the player spectates |
frames | The play's frames since the last ones (data, a replay in base64) |
follow | The player whose play to hear, from the part on (0 for all of it), "" for none |
watch | A browser's, before any auth: the room and its password |
| From the server | |
|---|---|
hello, welcome | The nonce to sign, then the player the key is |
room | The room as it is now, null once out of it |
start | To those who play, with the seed |
chat | A player id and their text, never to a browser |
frames | A player id and their data, to those who follow them |
error | password, gone, full, kicked, rooms, queue (it's full), elsewhere, no-profile or auth |
Rooms live in the server's memory: restarting it closes them. The matches of rooms without a password are kept in its database (matches, match_plays), which is what the room's page and its link previews show.