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!
Getting started with SmartFoxServer
For those who landed on this article looking for a cloud-based multiplayer server for their game, but have never explored SmartFoxServer before, keep reading this section. All the others can skip to the next chapter.
First of all, what is SmartFoxServer? As stated on the homepage of our website, SmartFoxServer is an SDK for rapidly developing multiplayer games and applications based on a choice of technologies, the most prominent currently being HTML5 (web) and Unity (desktop, mobile devices and web — the latter thanks to WebGL). In other words it consists of a server-side middleware and a number of client-side API to develop any kind of multiplayer experience, from turn-based games to realtime games, from collaborative applications to virtual communities and MMO worlds.
SmartFoxServer was born in 2004 and has followed the evolution of the multiplayer games market since then, powering a number of very successful projects (a few of which you will find listed in this showcase). The current version (called 2X) has seen the light in 2010 and we kept improving it since then. The latest iteration of such improvements is the release of Overcast, our first-party solution to deploy SmartFoxServer in the cloud.
If you are new to SmartFoxServer and possibly to multiplayer game development, the first step before proceeding “to the cloud” is to become familiar with the product and its API. You should start by downloading and installing the Community Edition, which is a free version of SFS2X, offering 100% of its features and supporting up to 100 concurrent users.
We then recommend to skim through some of the main introductory topics in our online documentation. Our suggestion is to read at least:
- the description of Zones and Rooms architecture — to understand how an “application” and its users are represented inside SmartFoxServer;
- the introduction to the Administration Tool — the SFS2X admin console you will need to configure the server for the game’s needs;
- the first 4 documents in the Development Basics section of the documentation, which describe the very basic concepts which are also at the core of the Tris game we want to deploy later on.
Finally keep in mind that SmartFoxServer is fully extensible via server side code (called Extensions) allowing to create custom game logic, integrating with other services and building complex interactions.
As the last step in your initial approach to SmartFoxServer, you may want to take a look at the examples we provide for your platform of choice, in particular those discussing how to connect, join a Room, send messages, etc. They are all preparatory to the development of a full game.
Check the Unity examples section in the documentation.
The Tris game
Tic-tac-toe is a relatively simple game that well suited our need to provide an example to beginner SmartFoxServer developers. We could focus on a number of features, often common to multiplayer games (a lobby, dedicated game Rooms, players and spectators, in-game chat, server-side logic, etc), and still have an easy to implement core logic. For this reason we implemented our version of the game, called Tris, for almost all the platforms supported by SmartFoxServer. And what’s cool is that all versions of the game can interoperate too!
In particular, it is important to note that the game features a server-side Extension which is in charge of implementing the game logic, as opposed to keeping the logic on the client-side. In general, using a server-side Extension is a more flexible and secure option for any game. Even if SmartFoxServer provides powerful tools for developing the application logic on the client, this approach can be limiting when your games start getting more complex. Also keeping sensitive game data on the server-side allows overall better security from hacking attempts, cheating, etc.
We will leave the details of the implementation to the in-depth tutorial available in the documentation (here the Unity version), concentrating on the files organization to get ready for the deployment, as per scope of this article. But first of all you should download the game, which is part of the examples package for a given platform, together with other demo projects of increasing difficulty.
The Unity package contains a separate folder for each example. You can now extract the Tris game on your PC. This is divided into two subfolders: client and server.
The client folder contains a Tris folder with the source files for the Unity project. Open the Unity Hub and add a new project, selecting that folder. Then open the newly added project in the Unity Editor and wait for the game assets importing to complete. By default the project’s build should be configured to “PC, Mac & Linux Standalone”. Open the Build Settings panel and switch the platform to WebGL. The game is compatible with all builds, but in this article we will use WebGL to show the deployment of the client to SmartFoxServer’s internal web server. You can now put the client side on hold; we will come back to the client in the next chapter.
Deploying to Overcast
As described in other articles and pages on our website, Overcast is our own dedicated cloud-based hosting service for SmartFoxServer 2X. It allows deploying any number of SFS2X and database (MySQL) instances in the cloud, world-wide, with a simple web-based interface. You can find a full introduction to the service in the cloud section of our website.
In order to deploy the Tris game to Overcast, you need to execute the following steps.
1. Launch the cloud server
In order to launch SmartFoxServer in the cloud, simply follow the Creating a new server article in the Overcast documentation (or the previous article in this blog series). You can assign any name to the application and server; in this case, with very little imagination, you could use Tris App and Tris Server. 🙂
2. Create the game Zone and lobby Room
By default a SmartFoxServer instance launched in Overcast starts with no Zones defined, so you need to add one. Click the toolbox icon to access the AdminTool; login with username sfsadmin and the password specified during the server launch.
After the login, select the Zone Configurator module and in the panel on the left click the +Z button to add a new Zone. In the General tab of the configuration form, set the following parameters:
- Zone name: TrisGame
This is the name used on the client side to connect to the proper “application” (a.k.a. Zone) on the server.
- Maximum length of Room names: 25
The Unity version of the Tris self-generates the name of a game based on the name of the user starting it (i.e. “John’s game”), so the default length of 10 characters might be insufficient.
- Public Room Groups and Default Room Groups: default,games
Every game of tic-tac-toe launched within Tris is represented by a Room, which is assigned to the “games” group. In order to allow the client to create Rooms in that group, and register to that group to receive notifications of new Rooms being created, we need to add the string “games” to these two parameters (comma-separated from the existing “default” group).
You can then click the Submit button to store the configuration on the server side.
The Tris game also requires an initial, static Room to exist, acting as a lobby where users meet before starting a new match, or participating to an existing one.
Select the TrisGame Zone in the list on the left side of the module and click the +R button. Set the Room name specifically to The Lobby (which is the same name hardcoded on the client, which auto-joins the Room right after the login). In this simple example the other settings can be left unchanged, although actual games may need some fine-tuning (i.e. the maximum number of users).
You can then click the Submit button to save the Room configuration.
Finally, as the Zone is not yet active, you must select it and click the ► button to start up the Zone and its inner Room.
As you can see in the Zone Configurator images above, both Zone and Room configuration forms show tabs called respectively Zone Extension and Room Extension. You may ask: why aren’t we configuring the Extension now, as the game comes with one?
SmartFoxServer supports two types of Extensions: Zone Extensions and Room Extensions. First of all, the Tris game uses a Room Extension only, so the tab in the Zone configuration is not needed. Also, the game’s Extension is in charge of handling the actual game logic (player moves, validation, victory conditions, etc), while the lobby Room you just created has no “custom logic” attached (all its interactivity is based on standard SmartFoxServer features — public messaging, dynamic Room creation, etc); so that tab in the Room configuration is useless too for this game.
So, when does the game’s Extension come into play? Well, at runtime, whenever a game Room (representing — remember — a match started by a player) is created, the Extension is attached dynamically. For reference, you may check the game tutorial where we describe the behavior of the “Start new game” button.
3. Upload the server Extension
As discussed above, the Tris game comes with a Room Extension, which we need to deploy on the server so that it can be instantiated dynamically at runtime. In order to do this, open the AdminTool’s Extension Manager module.
Click on the root folder (extensions), then click the button to add a folder called Tris. Select the newly created folder and click the button to upload the TrisExtension.jar file contained under the /server/Extension_Java/deploy/Tris folder of the folder you previously extracted from the Unity examples package. The following image shows the end result of the operation.
4. Build the game client
You can now go back to the Unity Editor to configure and build the client. In the Project panel, browse the folders tree down to /Assets/TrisAssets/Scenes and open the Login scene. Click on the Controller object in the Hierarchy panel and take a look at the Inspector panel: it shows the SmartFoxServer connection parameters exposed by the game’s LoginController script.
In the Host field, enter the public IP address of the server displayed in the Overcast interface. In the Zone field, enter the Zone name set during the configuration (TrisGame). Leave the other settings unchanged, as they are already set to the default values for the Overcast environment.
You can now immediately test the game from inside the Unity Editor: click on the ► button, enter a username (or leave it empty to have one being generated automatically) and you will join the lobby Room, as logged in the Lobby Chat panel of the game’s UI.
You can then stop the execution, go to the Build Settings panel and click the Build button to generate the WebGL version of the game.
5. Upload the game client
As soon as the build process is over, go back to the AdminTool and open the Servlet Manager module. Select the ROOT folder and click on the button to add a folder called — guess what? — tris.
Under the newly created folder, rebuild the folders’ structure generated by Unity (subfolders Build and TemplateData) and upload the game files to the appropriate folders using the button (you can select multiple files at once). You should end up with the following structure:
Please note that this last step is not mandatory, as you are not forced to host your game client on SmartFoxServer itself.
Playing the game
You are now ready to play Tris! Open a WebGL-compatible browser (Firefox or Chrome for example) and enter the following URL:
(note that the path is the exact — case-sensitive — name of the top folder created in the AdminTool’s Servlet Manager module)
As soon as the game is loaded, perform the login and click the Start new game button at the bottom of the Current Games panel. You can now open the same URL in another browser window, login with a different username and join the available game for a compelling challenge against yourself at tic-tac-toe! 🙂
If you have further questions get in touch with us directly using the support email found on our website.