Category Archives: Recipes

How to create an Extension based custom login

Implementing a custom login on the server-side is a simple process. SFS2X fires the following two login events.

  • USER_LOGIN: fired when a client requests to join a Zone. Here we can validate the client credentials and decide if the User can continue the login process. At this stage the client is represented by a Sessionobject, not by an SFSUser object yet.
  • USER_JOIN_ZONE: notified when a client has successfully joined a Zone (and is turned into an SFSUser).

Continue reading

How to setup a connection to an external Database

SFS2X allows connecting to databases in a way that is very similar to its predecessor. All you need to do is downloading the JDBC connector from your Database vendor (e.g. MySQL or MSSQL) and drop the .jar in the {SFS2XRoot}/lib/ folder.

Of course if you use ODBC instead of JDBC you can even skip the driver deployment step. In fact the ODBC driver is already provided by the Java Runtime.

The following is a list of pages where you can find the JDBC drivers for the most common RDBMS:

The next step is running the SFS2X AdminTool, launch the Zone Configurator module, select your Zone and finally click on the Database manager tab to edit the configuration.

db setup dialog

At the end of the process click Submit and restart the server.

How to add new Java libraries or Extension dependencies

Adding new libraries in SmartFoxServer 2X is a breeze. No messing around with the classpath is required: all we need to do is deploy the .jar file(s) in the proper directory and restart the server.

There are two folders that we recommend to use:

{SFS2XRoot}/extensions/{the-extension-name}.
This is where we will typically deploy our main Extension .jar file. The jar file should contain only our Java code without the external dependencies, if any. The reason why the dependencies should be deployed separately is that if they are shared, they will be loaded once for all Extensions that use them.

{SFS2XRoot}/extensions/__lib__/
This folder is recommended for libraries that will be shared by multiple Extensions in your system. For example the “Google Collections” jar, or the Hibernate jar, etc. Do not add your Extension jar to this folder, because the AdminTool won’t ba able to detect it when you setup the Zone/Room configuration.