How to schedule timed tasks in an Extension

Often times in the server-side game logic it is necessary to use timers for recurring events that are sent to the clients (e.g. the end of a turn time, npc actions, etc).

A quick solution to this problem is using the ScheduledThreadPoolExecutor class, provided in the JDK, which offers a convenient task executor backed by a pool of threads. SFS2X already runs its own instance of this Executor (wrapped in a class called TaskScheduler). Continue reading →

How to debug your Extensions

You can easily attach a Remote Debugger to the server and enable your favorite Debugger for bug hunting in your Extensions.

SmartFoxServer 2X can be started with the sfs2x.bat (Windows) or sfs2x.sh (Linux/Unix/MacOSX) scripts. By adding some JVM switches to the launch script you can enable remote debugging. You can do it by following these steps: Continue reading →

How to use the SmartFoxBits 2X

Together with SFS2X we provide the latest version of our SmartFoxBits components, which can save you a ton of time in setting up the application GUI if you are using the Adobe Flash platform to build your client.

The base SmartFoxBits pack contains five components:

  • Connector: manages the connection/disconnection process (supporting the new reconnection system too)
  • Login: handles the login process
  • RoomList: manages the Rooms list, including the Groups feature (allowing to create multiple views of the list based on groups)
  • UserList: manages the user list allowing private chat
  • ChatBox: provides a basic chatting component

You can check all the details and read the documentation on the SmartFoxBits page.

 

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.