Category Archives: Recipes

Using a database in Overcast (part 1)

In this new article in the series dedicated to Overcast, the cloud solution for SmartFoxServer 2X, we will describe how to use a database server alongside SmartFoxServer.

In this first part of the article we will focus on launching the database, populating it with some test data and configuring SmartFoxServer to connect to it. In the second and third parts we will deploy an Extension in SmartFoxServer to test the connection with a query.

Continue reading

How to deploy a game in Overcast

In this third article in the series dedicated to Overcast, the cloud solution for SmartFoxServer 2X, we will focus on the deployment of your games onto a cloud server.

For this purpose we will use one of the existing SFS2X examples, the Tris game (aka Tic-Tac-Toe), which we released for almost all supported platforms. We will refer to the Unity version of the example, but all the concepts relevant to the purpose of this article apply to any version.

If you are new to SmartFoxServer, don’t worry: we will also provide some context and guidance to get started!

Continue reading

Launching SmartFoxServer in the cloud

In early November 2020 we have launched a new cloud service called Overcast which joins the family of SmartFoxServer products.

In this short series of articles we will be taking a look at how Overcast works, how to get started and and how it can help new or existing projects based on SmartFoxServer.

Continue reading

Using the geolocation API

The following instructions are valid for al SFS2X prior to version 2.12. See the last section at the bottom for more recent releases.

SmartFoxServer 2X comes with a geolocation API and database that are used mainly in the AdminTool’s Analytics module to aggregate and show statistics based on geographical positions. The API is not directly exposed to developers but since it’s been requested several times here is a quick recipe on how to use geolocation in your Extension code.

For starters we need to add lib/logs-analysis-app.jar to our project’s dependencies and import a couple of classes:

import com.maxmind.geoip.Country;
import com.smartfoxserver.v2.admin.utils.IpGeoLocator;

NOTE: starting from SmartFoxServer 2X v2.12, the com.maxmind.geoip.Country class has been replaced by com.maxmind.geoip2.record.Country; change the above import accordingly.

Next we instantiate and initialize the IpGeoLocator class:

IpGeoLocator geo = new IpGeoLocator();
geo.init("data/", false);

This tells the geolocation service to load the relative database, located under SFS2X/data/. Finally we can test the service with an IP address:

String ipAdr = "208.80.154.224"; // wikipedia's IP

// Locate address
Country country = geo.locateIP(adr);

if (country == null)
   System.out.println("Not found for address: " + ipAdr);
else
   System.out.println(ipAdr + ": " + countrt.getName() + ", " + country.getCode();

Running the code results in this output:

208.80.154.224: United States, US

NOTE: it is important to always check that the returned Country object is not null. If it is, the geolocation service was not able to resolve the IP to a specific country.

» SFS2X 2.12.x and higher

SFS2X 2.12 introduced automatic geolocation for every client. The setting is configurable per-Zone from the AdminTool > Zone Configurator > Enable Geolocation.

When the service is active we can access the geolocation data with a few lines of server side code:

import com.smartfoxserver.v2.util.Country;

class MyHandler extends BaseClientRequestHandler
{
	void handleClientRequest(User sender, ISFSObject params)
	{
		Country ctry = sender.getCountry();
		
		if (ctry != null)
		{
			trace("User's country: " + ctry.getName());
			trace("Country ISO code: " + ctry.getIsoCode());
		}
	}
}

 

HTTP Request and Extensions integration

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.

Continue reading

Fine tuning Room Lists

In this new recipe we will take a look at how to optimize the Room List that SmartFoxServer 2X sends to each client.

Room Lists are very important to show players what is going on in the server and allow them to quickly find games to join. Sometimes, however, they can get too big and result in a waste of bandwidth and information overload for clients.

Continue reading