Nyra Studios
Manual under construction. Some parts are incomplete or may change.

Sign in and registration

Nyra 0.5.4.28

Creating an account: register

json
{ "type": "register", "username": "mario-88", "email": "mario@esempio.it", "password": "una-password" }

If all goes well, the server answers only with this:

json
{ "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

json
{ "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-88 and mario-88 are 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.rossi and dark_knight-2 are fine. _mario, mario_ and mario__88 are 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 is auth-error
  • context: when it happened, login or register
  • reason: the reason, a fixed word (in the table below)
  • message: a text for people, present only in some cases
reasonWhenWhat it means
invalid-credentialsloginWrong name or password. Without message.
username-takenregisterThe username is already used. Without message.
email-takenregisterThe email is already used. Without message.
invalid-inputregisterA field does not follow the rules. The message says which one.
too-many-attemptsloginToo 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-attemptsregisterToo many registrations from the same address: at most 3 an hour. Every attempt counts, even a failed one.
account-suspendedloginThe account is suspended. It arrives only if the name and the password are right.
login-in-progressloginThere 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.

FieldWhat it contains
protocolVersionThe protocol version. Today 1.
movementModetile, platform or eightdir.
playerIdThe identifier of your player.
usernameThe name of your account, with the capital letters as they are saved.
x, yThe starting position, or the last saved one.
otherPlayersThe other players already there.
levelThe level of the game. See the level page.

Then each mode adds its own fields:

  • Tile: tileConfig (tileSize, moveDurationMs, mapWidthTiles, mapHeightTiles) and facing.
  • Platform: onGround and physicsConfig (gravity, jumpVelocity, walkSpeed, runSpeed, voidY, playerWidth, playerHeight).
  • 8 directions: eightdirConfig (walkSpeed, runSpeed, playerWidth, playerHeight, hitboxOffsetY, playerCollision), facing and angle. angle is the last saved angle, facing is worked out from angle, and without a saved angle they are 90.

An example for the tile mode:

json
{
  "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.