Master Server Kit Setup
The best way to introduce the functionality provided by Master Server Kit is to play with the included demo.
You can launch it on your computer in order to be prompted with the intro screen:
You can register a new user:
And log in with an existing user:
You can also log in as a guest.
Once successfully logged into the master server, you will enter the lobby screen:
From this screen, you can perform the following actions by clicking on the appropriate buttons:
You can see this functionality is fundamentally equivalent to the one provided by Unity Multiplayer Services's matchmaking, with the difference that everything is running on a dedicated server here.
If you try to join a private game you will be prompted with this dialog, where you need to introduce the game's password:
Once you have successfully joined a game, you will enter the game screen:
This screen is just a placeholder for demonstration purposes; you would implement your authoritative game logic here. You can chat with the other players in the game/match/room and also have the option to exit the game and return to the lobby. When no players are left in a game server, it is automatically shut down by the master server.
How to build the demo
The best way to understand how Master Server Kit is structured and how it works is to build the accompanying demo and run it locally on your machine. In order to do that, you will need to generate four binaries:
You should generally be able to use the provided master server and zone server mostly with no changes for your game, although you always have the option of extending or customizing them if needed because the kit comes with its complete source code included. The game server and game client are where you come in: it is your responsibility to program the multiplayer logic specific to your game server and client. The demo provides an example game server and client that you can use as an official reference for your own game.
In order to build the demo so that it can run locally on your development machine, follow these steps:
It is also a good idea to make sure the Display Resolution Dialog option in Build Settings/Player Settings/Standalone Player Options is disabled for convenience, but this is not strictly required.
If you decide you want to use a different database implementation and remove the files related to SQLite from your project, you will be able to use the .NET 2.0 Subset option as is usual in most Unity projects.
If you want to completely remove SQLite from your project, you will need to delete the following files: the SQLiteDatabaseProvider.cs file and the DLLs needed by SQLite (Mono.Data.Sqlite.dll, System.Data.dll, sqlite3.dll, sqlite3.def, libsqlite3.so).
This menu option is provided via an editor script located in Demo/Scripts/Editor/Builder.cs. You can change the build target specified in this script if you are targeting a different platform than Windows (which is the default).
You can also generate the builds manually from the build settings by selecting the appropriate scenes for each binary:
More specifically, you will need:
By default, the players' data is stored in a SQLite database, but the kit also provides implementations for MongoDB and LiteDB (you can find more information here). You do not generally need to worry about the details of interacting with the database, as this is something handled by the kit.
Deploying to a production server
When deploying the server binaries to a production environment, we recommend building the master server, zone server and game server as Linux headless. This allows you to launch them as command line programs with no graphics, which is particularly convenient for servers (where no graphics are required).
Please note the Headless Mode setting only exists for Linux builds and you need to disable the Development Build option in order to be able to enable it.
Master Server Kit is known to work on a Digital Ocean VPS, but any well-respected cloud service able to run Unity instances should be fine. Please note that we do not provide technical support for deployment issues. If you are using AWS, a kind user provided us with this helpful tip to get the kit working on this platform: "The trick was to set the server IP addresses to the internal IP address of the server, so not 127.0.0.1 but the private IP address".
In order to get the servers deployed to a Digital Ocean VPS, you can follow these steps:
To Action From -- ------ ---- OpenSSH ALLOW Anywhere 8000 ALLOW Anywhere 9000:9100/tcp ALLOW Anywhere 9000:9100/udp ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 8000 (v6) ALLOW Anywhere (v6) 9000:9100/tcp (v6) ALLOW Anywhere (v6) 9000:9100/udp (v6) ALLOW Anywhere (v6)
scp DigitalOceanBuilds.zip root@DIGITAL_OCEAN_IP:~/DigitalOceanBuilds.zip
chmod +x master_server.x86_64 chmod +x zone_server.x86_64 chmod +x game_server.x86_64
./master_server.x86_64 & ./zone_server.x86_64 &
The game server instances will be spawned and destroyed automatically by the zone server as appropriate.
With non-root users, you may need to use the sudo command as appropriate at some of the steps mentioned above.