5. Distinguishing servers by the flavor feature

Your game system may have servers of different roles while sharing most of data structure. For example, lobby servers, game servers, chat servers, and so on. Though you might consider a separate source tree for each server, it’s not very handy in terms of source code management.

On iFun Engine, it’s possible to share source code but to run servers differently based on the role. It’s called “server flavors”. Each server flavor has a separate MANIFEST.json, which is a configuration file on iFun Engine, and can be packaged into a separate package. (For packaging, see Packaging The Game Server.)

Specify flavors in the APP_FLAVORS cmake variable in hello_world-source/CMakeLists.txt like this:

# ADD A LINE BELOW
set(APP_FLAVORS lobby game)

...

# WE ALREADY HAVE LINES BELOW. APP_FLAVORS SHOULD APPEAR BEFORE THESE LINES.
set(CMAKE_MODULE_PATH "/usr/share/funapi/cmake")
include(Funapi)

Run make.

$ make

$ ls *local *launcher
hello_world-launcher*  hello_world-local*  hello_world.game-launcher*  hello_world.game-local*  hello_world.lobby-launcher*  hello_world.lobby-local*

$ ls ../../hello_world-source/src/MANIFEST.*
../../hello_world-source/src/MANIFEST.game.json  ../../hello_world-source/src/MANIFEST.json  ../../hello_world-source/src/MANIFEST.lobby.json

We had only hello_world-local and hello-world-launch before. But with flavors enabled, we now have launcher scripts and a MANIFEST file for each flavor.

Tip

Programmer can differentiate flavors by referring to a GFLAG variable FLAGS_app_flavor and make different flavors take different code paths. Please refer to the server flavor section in iFun Engine reference manual .