Often times server-side code requires a number of configuration parameters that can be easily tweaked without recompiling and re-deploying the Extension. In this article we will show a useful and little known feature of SFS2X’s Extensions. Continue reading
In this recipe we will take a look at how we can tweak the logging configuration in SmartFoxServer 2X in order to do advanced logging from Extension code. Continue reading
In this new recipe we’re going to take a look at how we can integrate regular HTTP calls with the SmartFoxServer runtime and specifically how to communicate with Extension code via HTTP GET/POST requests.
Common applications of the HTTP/Extension interoperability are debugging interfaces and administration UIs. With this approach developers can easily build a simple web interface that reports that game state, monitors data structures, users etc… allowing to quickly debug problems while testing, triggering events and so on.
In this article we’re going to build a simple Login Extension using EclipseLink in place of the default DBManager API provided by SFS2X.
EclipseLink is a powerful ORM (object-relational mapping) framework, that is compliant with the Java Persistence API (JPA) standard.
NOTE: the tutorial presupposes you have an understanding of the basic concepts of object-relational mapping and you’re familiar with at least one database technology. If you don’t have experience with these tools we recommend to check this introduction.
The trace(…) method is a useful little tool to log any information in the log files for debugging your Extension code.
It is available in the main Extension class and in every Request or Event handler. However, often times, developers need to log messages from other places in their code such as data classes, or any other object that doesn’t extend the Request/Event base classes.
How can we call trace(…) from somewhere else? Continue reading
Attaching an Extension at Room level is a convenient way to provide each game Room with its own logic. Different Rooms can use different code and manage their own game rules very conveniently. Continue reading
Continuing from a previous post about Singletons we are going to discuss a simple strategy to maintain application state across multiple Extension reloads. Before delving into the details, let’s first analyze the reasons why this may help. Continue reading
One of the questions that often gets asked in our support forums is something along the lines of “How do I create a singleton class where to store data that is global among all Extensions?”
This is a relatively complex subject in SmartFoxServer because each Extension is loaded in a separate Class Loader, thus making it more difficult to create a singleton that can be shared.
If you’re not entirely familiar with how Extension loading works you can consult this article for a quick overview. Part of these rules are essentially inherited from the Java Virtual Machine (JVM) architecture and, even if they might seem a bit convoluted, they help with reloading new code at runtime without stopping or restarting the server.
There is however a simple deployment trick that can be employed. Using the extensions/__lib__/ folder we can deploy a jar file with one or multiple classes that will be accessible from any Extension, even throughout multiple reloads.
In other words this will not change the way in which you deploy your Extension in SmartFoxServer 2X, however you will need to export the Singleton class(es) to a separate jar file that will be deployed to –> extensions/__lib__/
From a coding point of view nothing changes, which means that you don’t need to create a different project for your Singleton(s). You can keep them with your main Extension project and just deploy them differently, as described. Most Java IDEs will allow you to export a number of selected classes to a specific jar file, which can then be deployed as we have discussed.
In this recipe we will see how we can create a simple Extension that automatically joins users in an available Room and creates more Rooms when the seats are all occupied. Continue reading