The topic of managing NPCs in games is an interesting and less discussed one. In this article we’re going to cover some concepts and strategies to work with NPCs in our multiplayer game, focusing on different modalities of interaction with real players and the game environment.
SmartFoxServer 2.12 is out
SmartFoxServer 2X 2.12 is out with a host of new features and fixes, such as:
- JoinRoomInvite, allows players to invite other clients in a game Room to play, available also from client side
- Private UserVariables, allow to create UserVariables that are local to the player, and not broadcast to other clients
- Updated Jetty version 9.3 for web services (BlueBox, uploads, crypto init)
- Support IP ranges for black/white lists in IP Filter
- AdminTool support for TLS encrypted connection
- Embedded Java 8 runtime
… and lots more!
You can read the full release notes and download the installer from here.
Also make sure to check the Client API download page where we have published updates for all supported clients (API release 1.7.x).
Using the geolocation API
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());
}
}
}
An App, a Marathon and an Astronaut: a SFS case story
Over the last few years, the RunSocial mobile app has been under development featuring SmartFoxServer 2X and other innovative technologies. Recently, the app was approved by the American National Aeronautics and Space Administration (NASA) and the European Space Agency (ESA) for use on the International Space Station (ISS).
On April 24th 2016, Tim Peake of the European Space Agency completed the London Marathon, running the 42.2 km on a treadmill connected to RunSocial while circling the Earth about two and half times at an altitude of 400 km high, being visible to all other virtual concurrent runners.
SmartFoxServer proved to be a mature and robust solution for this task, thanks to its high performance and scalable messaging system in multi-user, realtime scenarios, a sensible structure for organizing application logic and a wide range of options to store, organize, and distribute users and data.
Game state serialization strategies
In this article we’re going to analyze a few strategies to serialize game state data between client and server, and discuss the pros and cons of each approach. Continue reading
Understanding JVM/SmartFoxServer memory usage
In this article we’re going to address yet another oft-asked question regarding how SmartFoxServer uses memory and how to read the graph in the AdminTool’s Dashboard. Continue reading
White paper: SmartFoxServer 2X and Hazelcast integration
We have a new white paper available for download in our documentation website, called “SmartFoxServer 2X and Hazelcast integration“.
This is an advanced paper discussing how to integrate an in-memory data grid with multiple SmartFoxServer instances to create a fault tolerant system. The paper takes our classic Tris game example and explores ways of scaling it horizontally with multiple servers and a centralized data store.
Additionally we discuss ways to tackle the load balancing and how to restart interrupted games.
We highly recommend that you’re already familiar with how the Tris game example works and also with out previous paper, SmartFoxServer 2X Server Architecture.
SmartFoxServer 2X Haxe client API
Vincent Blanchet of Chapatiz ported the AS3 client API of SmartFoxServer 2X to Haxe, making it publicly available on GitHub for community contribution. So we took the opportunity to open the “Unofficial client API” section on the API download page.
Take a look at the bottom of this page: http://www.smartfoxserver.com/download/sfs2x#p=client
Objective-C API update 1.6.2 available
We have just released a new update of the Objective-C API for iOS/tvOS/Mac OS X, release 1.6.2.
The update contains a fix for a bug recently discovered.
You can read the release notes and download the frameworks from here.
Using properties files to load Extension settings
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