Aquila

Quickstart

Run a fleet, allocate a server, talk to it over UDP and match two players, in about 10 minutes.

You will run a fleet of Aquila's example UDP server, allocate one of its servers the way a matchmaker does, send it packets, and watch the fleet replace it once the session ends. Then you will queue two players and have Aquila match them onto a server.

Everything runs from a terminal with curl, jq and nc, plus the console.

Your organization needs approval

A new organization can create keys straight away, but runs no servers until Aquila approves it. Create it first, then write to [email protected] with its name and what you are building.

1. Create an organization

Sign in to the console, open Organizations in the account menu (or go to aquilahosting.com/org) and create one. Its page is where fleets, queues and keys live.

2. Create an API key

On the organization's page, under API keys, create a key with the Manage fleets, Allocate game servers and Create matchmaking tickets scopes. Copy the key, and the organization ID shown above the keys.

Keep both in your shell for the rest of this guide:

export AQUILA_API_KEY="aqk_..."   # the key you just created
export ORG_ID="..."               # Organization ID, shown above your API keys
export AQUILA_API="https://api.aquilahosting.com"
export AQUILA_ALLOCATE="https://allocate-eu.aquilahosting.com"

3. Create a fleet

Create a fleet of two servers running the example image. It listens on UDP port 7777 and uses the Aquila SDK to report Ready and to read its allocation.

FLEET_ID=$(curl -sS --fail-with-body "$AQUILA_API/fleets.v1.FleetService/CreateFleet" \
  -H "Authorization: Bearer $AQUILA_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF | jq -r .fleet.fleetId
{
  "organizationId": "$ORG_ID",
  "zone": "eu",
  "name": "quickstart",
  "replicas": 2,
  "template": {
    "image": "ghcr.io/aquila-hosting/aquila-hosting/example-udp:1.0.0",
    "ports": [{ "name": "game", "containerPort": 7777, "protocol": "PORT_PROTOCOL_UDP" }],
    "cpuMillicores": 250,
    "memoryMib": 128
  }
}
EOF
)
echo "$FLEET_ID"

The call returns the fleet, and the command keeps its ID in FLEET_ID.

4. Wait for Ready servers

The servers start in a few seconds. Watch them on the organization's page, or list them:

curl -sS --fail-with-body "$AQUILA_API/fleets.v1.FleetService/GetFleet" \
  -H "Authorization: Bearer $AQUILA_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF | jq -c '.gameServers[]? | {name, state}'
{ "fleet": { "organizationId": "$ORG_ID", "fleetId": "$FLEET_ID" } }
EOF
{"name":"quickstart-x7k2p","state":"GAME_SERVER_STATE_READY"}
{"name":"quickstart-m4q9d","state":"GAME_SERVER_STATE_READY"}

5. Allocate a server and talk to it

Your matchmaker allocates a server for each match. Do it by hand, and put an annotation on the server for the game to read:

ALLOCATION=$(curl -sS --fail-with-body "$AQUILA_ALLOCATE/allocation.v1.AllocationService/Allocate" \
  -H "Authorization: Bearer $AQUILA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "fleet": "quickstart", "annotations": { "greeting": "hello" } }')
echo "$ALLOCATION" | jq

ADDRESS=$(echo "$ALLOCATION" | jq -r .address)
PORT=$(echo "$ALLOCATION" | jq -r '.ports[] | select(.name == "game") | .port')
{
  "gameServer": "quickstart-x7k2p",
  "address": "203.0.113.10",
  "ports": [{ "name": "game", "port": 30412, "protocol": "UDP" }],
  "zone": "eu"
}

The server is now Allocated and out of the pool. Send it a packet:

echo "hi there" | nc -u -w2 "$ADDRESS" "$PORT"
[Allocated greeting=hello] hi there

The example echoes what it receives, behind its state and the annotations it read through the SDK.

6. End the session

A server runs one session. The example ends it when it hears bye:

echo "bye" | nc -u -w2 "$ADDRESS" "$PORT"
[Allocated greeting=hello] bye, shutting down

The game calls Shutdown, and the fleet starts a fresh server in its place. List the servers again and the allocated one is gone, with a new one Starting or Ready.

7. Match two players

Aquila can also run the matchmaker. In the console, under Matchmaking, choose New queue and create a queue named duel on the quickstart fleet, with 2 Teams of 1 Players per team.

Your game backend creates a ticket for each player who wants a match:

ticket() {
  curl -sS --fail-with-body "$AQUILA_API/matchmaking.v1.MatchmakingService/CreateTicket" \
    -H "Authorization: Bearer $AQUILA_API_KEY" \
    -H "Content-Type: application/json" \
    -d @- <<EOF | jq -r .ticket.ticketId
{ "organizationId": "$ORG_ID", "queue": "duel", "playerIds": ["$1"] }
EOF
}
ALICE_TICKET=$(ticket alice)
BOB_TICKET=$(ticket bob)

The queue puts the two tickets in one match and allocates a server for it. Read a ticket to get the server's address:

TICKET=$(curl -sS --fail-with-body "$AQUILA_API/matchmaking.v1.MatchmakingService/GetTicket" \
  -H "Authorization: Bearer $AQUILA_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF | jq .ticket
{ "ticket": { "organizationId": "$ORG_ID", "ticketId": "$ALICE_TICKET" } }
EOF
)
echo "$TICKET" | jq '{state, assignment}'

ADDRESS=$(echo "$TICKET" | jq -r .assignment.address)
PORT=$(echo "$TICKET" | jq -r '.assignment.ports[]? | select(.name == "game") | .port')
{
  "state": "TICKET_STATE_ASSIGNED",
  "assignment": {
    "matchId": "8f0c3a52-…",
    "zone": "eu",
    "gameServer": "quickstart-m4q9d",
    "address": "203.0.113.10",
    "ports": [{ "name": "game", "port": 30187, "protocol": "UDP" }]
  }
}

The game server reads the match, with its teams and player IDs, from an annotation. The example seats players who say join <player> and shuts down once everyone has left. Play both players, each from its own local port:

echo "join alice" | nc -u -w2 -p 40001 "$ADDRESS" "$PORT"
echo "join bob" | nc -u -w2 -p 40002 "$ADDRESS" "$PORT"
echo "bye" | nc -u -w2 -p 40001 "$ADDRESS" "$PORT"
echo "bye" | nc -u -w2 -p 40002 "$ADDRESS" "$PORT"
[Allocated match-id=8f0c3a52-…] welcome alice, team 1, 1/2 joined
[Allocated match-id=8f0c3a52-…] welcome bob, team 2, 2/2 joined
[Allocated match-id=8f0c3a52-…] alice left, 1 still playing
[Allocated match-id=8f0c3a52-…] bob left, everyone is gone, shutting down

Clean up

Delete the fleet, and the duel queue in the console:

curl -sS --fail-with-body "$AQUILA_API/fleets.v1.FleetService/DeleteFleet" \
  -H "Authorization: Bearer $AQUILA_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{ "fleet": { "organizationId": "$ORG_ID", "fleetId": "$FLEET_ID" } }
EOF

Next

On this page