There are three parts: clients (the games), one hub, and any number of game servers.
- The hub (
:hub, default port 7177, TCP) keeps the accounts and stats and lists the game servers that registered with it. It is the only part that talks to the database. See hub.md, accounts.md and stats.md. - A game server (
:server, default port 7770, TCP and UDP) runs the lobbies and game rooms: parties, adverts, relays. It links players and forwards their traffic without reading the game data, and the host's game is authoritative. See game-server.md. - A client is a game running on OpenRAC. It reaches a hub through the launcher's server setting
(
OPENRAC_SERVER, host and port), by defaulthub.openrac.dev:7177.
This follows the online games' own split: an authentication server with a list of lobby servers, then the lobby and the games of the one chosen. Up Your Arsenal's login maps onto the hub's accounts, and its city select onto the list (one city per listed server, named by its region).
flowchart LR
subgraph Clients
C1[Game]
C2[Game]
end
H[Hub<br/>TCP 7177]
DB[(PostgreSQL<br/>optional)]
S1[Game server<br/>TCP and UDP 7770<br/>HTTP 7771]
S2[Game server<br/>region B]
C1 -- "HELLO, ACCOUNT LOGIN,<br/>REGIONS or SERVERS WATCH, STATS" --> H
C1 -- "HELLO, ACCOUNT TOKEN,<br/>PARTY, DATA, RELAY, UI" --> S1
C2 --> S1
S1 -- "REGISTER, HUB STATUS,<br/>HUB VERIFY, HUB RESULT" --> H
S2 --> H
H --- DB
- A game server registers. It connects to
HUB_ADDRESSand sendsREGISTER. The hub answersHUB REGISTEREDwith the server's id, or anERRORand closes. - It keeps in step. It sends
HUB STATUSeveryREGION_REPORT_SECONDSwith its player and party counts, andHUB CLOSINGwhen it shuts down. - A player reaches the hub. Its client says
HELLO, thenACCOUNT LOGIN. It asksREGIONSfor a snapshot of the list, orSERVERS WATCHfor every server and then each change. - It picks a game server and connects there:
HELLOas before, thenACCOUNT TOKENwith its session token. The game server asks the hub (HUB VERIFY) and answersACCOUNT LOGGED_INorSESSION_INVALID. A player that sends no token plays under itsHELLOname, as before accounts. - It plays. It creates, finds or joins a party, and the game server forwards
DATA,RELAYand UDPSTATEbetween the members. When a game ends, the server sendsHUB RESULTwith the scoreboard.
The details of each step are in hub.md, accounts.md and game-server.md; the packets are in protocol.md.
Each service keeps its network code in the same shape (see protocol.md for the wire):
:commonholdsPackets,Opcodes, the buffers, the outgoing packets (net/packets/out/) andIncomingPacket<C>, the base of every packet a service receives. It says whether the packet isstrict(the connection must have said hello or registered first) and which per-connection rate limit it draws from, and itshandle(connection, payload)does the work.- A
PacketRouterper service (com.openrac.server.net.packets,com.openrac.hub.net.packets) maps eachPacketsvalue the service takes to itsIncoming<Name>Packet, registered in one static block. A game server has two maps: players' connections and the link to the hub. A packet with no entry is not taken, and the sender is closed. - One class per packet, under
game/in/andhub/in/on a game server andin/on the hub. The opcodes of a packet are switched inside its class, one private method each. - The Netty handler (
GamePacketHandler,HubPacketHandler) is thin: it decodes, looks the packet up, refuses a strict packet before login, applies the rate limit, and callshandle. It also admits and cleans up the connection. Per-connection state lives in the service'sConnection, which the packets read and change.
MODE picks a game server's role:
| Mode | Runs |
|---|---|
region (default) |
lobbies and game rooms, registered with the hub at HUB_ADDRESS (hub.openrac.dev:7177) |
all |
the same, plus a hub on HUB_PORT (7177) in the same process, which the server registers with over loopback: one box for a LAN party or a group of friends |
The hub alone runs from its own jar (./scripts/run_hub.sh, or hub.jar in the image). Ctrl+C
(or SIGTERM) closes the ports and shuts the event loops down. A game server tells its hub it is
closing first, so players stop being sent to it.