Connecting¶
Steps¶
open the connection
→ say hello, with your protocol version
→ log in
→ play (send REQ, get RES and EVT)
→ connection ends
→ you get a short time to come back
→ come back in time, or you lose the match
- Your WebSocket or socket library opens the connection. The protocol starts after that, with your hello.
REQ,RESandEVTare the tags that start each line.- The commands page lists what you can send while you play.
- Connection ends? See Reconnecting.
- Leaving on purpose? See Disconnecting.
WebSocket or telnet?¶
| Telnet | WebSocket | |
|---|---|---|
| Where to connect | TCP port 8023, like localhost:8023 |
/ws on port 8080, like ws://localhost:8080/ws |
| Log in as a guest | send session.login with a name (Guest) |
send session.login with a name (Guest) |
| Log in with an account | send session.login with your account token (Account) |
put your account token in the address (Account) |
| Is the connection alive? | PING / PONG lines |
ping frames, answered by your library |
Both use the same lines.
Say hello¶
- You talk first. When the connection is open, send
session.hellowith the protocol version your client uses. - The server sends nothing before your hello.
- Any other request before it gives
ERR HANDSHAKE_REQUIRED.
OKmeans the server knows you are there and speaks your version.- Connected with an account token in the address? Then the
OKalso carries your session token:RES <id> OK {"session_token": "<session_token>"}.
Wrong version? The server answers with a FATAL error and disconnects:
- The server will not switch versions for you. The
<reason>names the version it uses.
Log in¶
You log in as a guest or with an account. Both ways give you a session token.
As a guest¶
Pick a name. On telnet and on WebSocket (connect to /ws), log in after your hello:
- Login failed? You get
ERR AUTH_FAILED. You can try again.
With an account¶
First log in on the website. You get an account token.
WebSocket:
- Connect to
/ws?account_token=<account_token>. - Bad account token? The server refuses the connection with HTTP 401.
- Say hello. The
OKcarries your session token. Nosession.loginneeded. - Your account is already logged in on another connection? The hello answers
ERR AUTH_FAILEDinstead. To take over that session, reconnect with its session token.
Telnet has no address to put the token in, so log in with it after your hello:
C: REQ <id> session.login {"account_token": "<account_token>"}
S: RES <id> OK {"session_token": "<session_token>"}
- Bad account token on telnet? You get
ERR AUTH_FAILED. - Your player name is your account name.
The website doesn't give out account tokens yet
Log in as a guest. To test account logins on your own computer, put accounts in the server's appsettings.json, like "Accounts": { "secret-jane": "jane" }.
Tokens¶
| Token | You get it from | Lasts | Use it to |
|---|---|---|---|
<account_token> |
the website | a long time. The website decides. | log in with your account |
<session_token> |
the server, when you log in | until your reconnect window runs out | reconnect |
- Save the session token. You need it to reconnect.
- Keep your account token secret. It logs in as you.
Rules¶
- One login per name. If the name is already logged in, you get
ERR AUTH_FAILED. The other connection stays logged in. - Lost your connection? You keep your name, your lobby place and your matches for a short time. See Reconnecting. After that your name is free again and your session token stops working.
- One login per connection. Sending
session.loginorsession.reconnectafter you are logged in givesERR AUTH_FAILED.
Is the connection alive?¶
| You want to know | How you know |
|---|---|
| Is the connection there? | Your hello got OK. |
| Did it end? | Your library reports a close or an error. Come back in time. |
| Does the other side still answer? | Pings. See below. |
Telnet: PING and PONG¶
- If you get
PING, answerPONG. - Any line you send counts as an answer. A client that sends requests often is fine without
PONG. - You can send
PINGtoo. The server answersPONG. - No answer in time counts as a lost connection. The server closes it. See Reconnecting.
WebSocket: ping frames¶
- The server sends WebSocket ping frames. Your WebSocket library answers them for you.
- Your library only answers while your program keeps reading messages. Keep reading.
- No
PING/PONGlines on WebSocket. - No answer counts as a lost connection. See Reconnecting.