RegistrationAndLogin - Mini-IT/SnipeWiki GitHub Wiki

User Registration and Login

Overview

This article describes the basics of user registration and login into game server. After connecting to the game server port, the client is marked as not logged in and can either send a request to register new user or login as returning user (It can also send one of the requests that do not require client login but that is beyond the scope of this article.). These messages are done through the standard Snipe server messaging protocol and API. If you want to extend the registration and login functionality, there are event hooks available for that. They are described in the Users Module article.

User Registration

The user registration client request must have a type "user.register" and have the following string fields:

Parameter name Maximum length Description
name 100 User name. Has to be unique, at a minimum length is 4 symbols.
password 40 User password. Used for logging into the game server in the case when user registers through the SNS.
networkid 100 SNS ID. Can be empty.
networktype 2 SNS type. Can be empty.

The response will always have a string field "errorCode" that contains the operation result. User registration request can return the following error codes:

  • "ok" - Operation successful.
  • "stringTooLong" - One of the parameter strings is too long.
  • "nameExists" - The record with this name exists in database.
  • "networkidExists" - The record with this SNS ID exists in database.

User Login

There are two ways to login to Snipe server. The first one is used when symbols two and three of "name" parameter are a valid SNS type defined in Server.coreModuleParams.user.socialNetworks array. In this case SNS type / password pair will be used for logging in. The other case is when this SNS type is undefined. In that case "name" and "password" parameters are used to get the user record.

For example, let's suppose the login request sends name "$FB$" and password "123". The socialNetworks array has "FB" element. The SQL query will try to find a record with password "123" and SNS type "FB".

In another example, the login request sends name "Joe" and password "123", Since socialNetworks array does not have the "oe" element, the SQL query will try to find a record with the name "Joe" and the password "123".

Keep in mind, that you should always calculate a hash of password entered by user before sending it to the server (if the user is even allowed to enter the password himself, and it is not stored in SNS variables).

The response will always have a string field "errorCode" that contains the operation result. User login client request must have a type "user.login" and have the following fields:

Parameter name Description
name User name or SNS type identifier.
password User password. Can be empty.
lang Two-symbol user language identifier. Will be used for string localization. If it is an empty string or is not set, "en" will be used.
migrateServerID (optional) Only used for the automatic [[Client Migration

User login request can return the following error codes:

  • "ok": Operation successful.
  • "userNotFound": User not found in database.
  • "userBanned": User banned.
  • "userDisconnecting": User is already logged in to another game server and will be disconnected. If the client receives this error code, it should wait for a short amount of time (3-5 seconds) and try to login again.

After the user logs in successfully and receives "user.login" response with error code "ok", by default, the server will also send "user.join" response to all clients including this one notifying them that a new client was logged in. This response will have a field "name" containing the name of the new client. You can disable that behavior by overriding the Server.onJoinNotify() method.

By default, when user tries to login to one of the non-game slave servers, the operation will always be a success if no "user.loginPre" event hooks are subscribed to by the project that can modify that behavior. You can read about module subscriptions in Module Subscriptions article.

This article marks the end of "Getting started" section of the Snipe server documentation. If you wish to learn more, proceed to the documentation home page.

Next: Home

⚠️ **GitHub.com Fallback** ⚠️