Login and Setup Smartfoxserver

Source: Internet
Author: User

» Login Phase

We have seen how to start a connection to Smartfoxserver in the previous chapter and mentioned that you must log in to a zone before the client can start interacting with the server API and other users.

To see the areas available on the server and create new zones, you can use the SFS2X management tool. Select Area Configurator in the left sidebar of the tool and display a list of all areas.

From here, you can double-click (or select and click the Edit button) for any zone name, and then continue with the configuration of the locale. Refer to the Zone Configurator documentation for instructions on use.
» Default and Custom Login

Before we continue to display the base code for the login request, we need to focus on a very important setting in the "Use custom Login" area after the "zone Configurator" zone name.

The value of this parameter (set to OFF by default) determines which controller will receive and process the logon request.

Customlogin set to False: the system controller will process the logon phase. In this case, any user name will be accepted unless the other user is already logged into the zone with the same names. The password will be ignored. If an empty string is passed as a name, the server automatically generates a "guest" user name (for example, guest #42).
Customlogin set to True:extension controller will process the logon phase, allowing the developer's Extension to validate the user credentials and perform any other required actions.

» Login Area

The logon phase always sends a loginrequest to the server from the client. This requires several parameters:

User name: (optional) User name
password: (optional) password
region name: The name of the zone; it must exist on the server side
additional parameters: (optional) An object that contains additional custom data; Typically this is used in conjunction with an extended-based login, To send the custom data to the server side

The login area requires only a few lines of code: Essentially, you only need to register the Smartfox class instance to receive the Sfsevent.login and Sfsevent.login_error events and continue to execute the request.

var sfs:smartfox = new Smartfox ();
Sfs.addeventlistener (Sfsevent.login, onlogin);
Sfs.addeventlistener (Sfsevent.login_error, onloginerror);
...
...

This code was executed after the connection
sfs.send (New Loginrequest ("," "," Simplechat "));

Public Function Onlogin (evt:sfsevent): void
{
    trace ("Login success:" + evt.params.user.name);

Public Function Onloginerror (evt:sfsevent): void
{
    trace ("Login failed:" + evt.params.errorMessage);

In the ActionScript 3 example above, we use the default login (handled by the system controller) and pass an empty string as the user name to get an automatically generated guest name.

Attention
When loading an external configuration file, you do not need to pass the zone name to the Loginrequest constructor, which is automatically acquired by the API.

This is another loginrequest code snippet:

Sfs.send (New Loginrequest ("Fozzie"));

In this case, we send the user name, no password, and do not specify a zone name, the system will use the name loaded from the configuration file.
» What can go wrong.

During the logon phase, the server performs many validations that may block the process and cause the Sfsevent.login_error event to fire. Let's take a brief look at the problems that may arise.

Missing zone: The requested zone name does not correspond to any available zons on the server.
Zone full: The requested region has reached the maximum allowed number of users (configurable in the Admintool Zone Configurator module).
server is full: The Smartfoxserver instance has reached its maximum capacity and cannot accept other users.
duplicate Name: No two users can use the same name in a zone. This is case-sensitive, so two usernames "Fozzie" and "Fozzie" do not cause any problems.
bad words in username: If you configure word filter in area and apply it to a user name, an error may be triggered if the name matches any of the pronounced words that are configured in the filter.
Forbidden User name: If the provided user name is forbidden by the host or administrator, the client will not be able to join the zone until the exile expires.

» Room List

In the first code example, we see that when the login succeeds, the server joins the user to the requested zone. Behind the scenes Smartfoxserver also performs some other operations that we need to understand.

1. Automatically subscribe to the default room group: In the Zone Configurator, you can declare some common room groups. By default, only one group is called "Default" and you can add more if you want. A room group is simply a string ID that is used to organize different categories of rooms called room groups.
after logging in, the client will be subscribed to all the groups specified in the zone's default room group settings.
Use the initial room list to fill in the client: the behind-the-scenes client receives a list of rooms filled with all the rooms included in all the subscription groups. Once this operation is completed, only small updates will be sent to the client at logon to maintain the room list with the latest server.

In the example above, the area contains three different room groups, called Europe, America and Asia, each containing a certain number of rooms. If we assume that the default group property for this zone is set to "Europe, United States", the client list will populate the details of all rooms in these two groups and will receive updates about any "interesting" changes (for example, a new room is created or another is deleted, etc.).

You can read additional information about the group in this document.
» Custom Login

A very common use case during the sign-in process is to write an extension that processes user credentials and checks against your database. In order to do this, you will need some preliminary steps. Set up a database connection. You can follow this tutorial to learn how to configure SFS2X to communicate with the database. Prepare a simple extension that will perform user name and password validation. We provide an in-depth overview of the extensions and login how-to tutorials. Open the Use custom login setting in the Zone Configurator and set up your extension.

Translated from Http://docs2x.smartfoxserver.com/DevelopmentBasics/login-phase

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.