Sign in and registration
Creating an account: register
{ "type": "register", "username": "mario-88", "email": "mario@esempio.it", "password": "una-password" }If all goes well, the server answers only with this:
{ "type": "register-success", "username": "mario-88" }The account exists, but you are not inside yet: the server does not log you in by itself. Send login on the same connection.
Getting in: login
{ "type": "login", "identifier": "mario-88", "password": "una-password" }The identifier field can be the username or the email. Mind the capital letters:
- The username is compared exactly:
Mario-88andmario-88are different names. - The email is compared in lowercase: it does not matter how you write it.
If all goes well, the server answers with welcome. If you get it wrong, it answers with auth-error. The server accepts one login at a time on each connection. If you send another one while the first is being checked, you receive auth-error with the reason login-in-progress.
For an account that does not exist and for a wrong password the server always answers invalid-credentials: it does not say which of the two. A suspended account with the right password receives account-suspended instead.
If you send login again on a connection that is already inside, the server does not close it: it sends you a welcome again with the same playerId.
The rules of the data
- Username: from 3 to 20 characters, after removing the spaces at the edges. Letters without accents and numbers, plus the symbols
_,-and.. The symbols cannot be at the start or at the end, and two of them cannot be in a row. At least one letter or number is needed.mario-88,mario.rossianddark_knight-2are fine._mario,mario_andmario__88are not. The name stays as you wrote it, capital letters included. Two names that differ only in capital letters count as the same name in the registration. - Email: at most 254 characters, with a valid basic format. It is saved in lowercase, and you cannot use the same email twice, however you write it.
- Password: from 1 to 128 characters.
If a register field does not follow the rules, the server refuses it right away. In the login, instead, a name or a password that is too long gives no separate error: you receive invalid-credentials, and it counts as a failed attempt.
When something is wrong: auth-error
The auth-error message always has these fields:
type: it isauth-errorcontext: when it happened,loginorregisterreason: the reason, a fixed word (in the table below)message: a text for people, present only in some cases
reason | When | What it means |
|---|---|---|
invalid-credentials | login | Wrong name or password. Without message. |
username-taken | register | The username is already used. Without message. |
email-taken | register | The email is already used. Without message. |
invalid-input | register | A field does not follow the rules. The message says which one. |
too-many-attempts | login | Too many failed attempts: at most 5 a minute for the same pair of name and address, and 20 a minute per address. Try again later. |
too-many-attempts | register | Too many registrations from the same address: at most 3 an hour. Every attempt counts, even a failed one. |
account-suspended | login | The account is suspended. It arrives only if the name and the password are right. |
login-in-progress | login | There is already a login being checked on this connection. |
Note
Try the login first, and send register only when you receive invalid-credentials. That way a player who opens the game several times does not use up the 3 registrations an hour.
The counts work in fixed windows, not sliding ones. A successful login never counts as a failed attempt.
Show the player a text of your own, in their language, starting from reason. Do not use the text of message to decide what to do: the fixed word is reason.
The answer: welcome
After a successful login, the server sends welcome, to you only. It is the most important message: it contains everything you need to begin.
| Field | What it contains |
|---|---|
protocolVersion | The protocol version. Today 1. |
movementMode | tile, platform or eightdir. |
playerId | The identifier of your player. |
username | The name of your account, with the capital letters as they are saved. |
x, y | The starting position, or the last saved one. |
otherPlayers | The other players already there. |
level | The level of the game. See the level page. |
Then each mode adds its own fields:
- Tile:
tileConfig(tileSize,moveDurationMs,mapWidthTiles,mapHeightTiles) andfacing. - Platform:
onGroundandphysicsConfig(gravity,jumpVelocity,walkSpeed,runSpeed,voidY,playerWidth,playerHeight). - 8 directions:
eightdirConfig(walkSpeed,runSpeed,playerWidth,playerHeight,hitboxOffsetY,playerCollision),facingandangle.angleis the last saved angle,facingis worked out fromangle, and without a saved angle they are 90.
An example for the tile mode:
{
"type": "welcome",
"protocolVersion": 1,
"movementMode": "tile",
"playerId": "381edad1-68a0-4dba-aba0-8536a2666f34",
"username": "mario-88",
"x": 320,
"y": 320,
"otherPlayers": [],
"tileConfig": { "tileSize": 32, "moveDurationMs": 200, "mapWidthTiles": 50, "mapHeightTiles": 50 },
"facing": 90,
"level": { "name": "Livello 1", "worldSize": { "width": 854, "height": 480 }, "layers": [], "tilesets": [], "spriteAssets": [] }
}Always read these values from the welcome, instead of writing them by hand in your client: if you change a value in the panel, the client finds it already updated.
Note
Your playerId is also the identifier of your character. If you connect again, you find the position where you left it. There is no session code: after a reconnection you receive the complete welcome again.