Difference between revisions of "Dedicated Server Kit Demo Setup"

From gamevanilla wiki
Jump to: navigation, search
(Opening your server ports)
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{| style="width: 920px; horizontal-align: left;"  
 
{| style="width: 920px; horizontal-align: left;"  
 
|
 
|
 +
 +
= Introduction =
 +
 +
Dedicated Server Kit has four main components:
 +
 +
* The Go server.
 +
* The MySQL database.
 +
* The Unity game server (using Mirror).
 +
* The Unity game client (using Mirror).
 +
 +
How do these components interact between each other? It all starts with the Unity game client, which is your actual game. Upon starting the game, your player will register a new account with the system (if he does not have one yet) and log into it. Once logged in, he can create new games and join existing ones as well. Communication with the Go server happens via REST calls. The Go server is responsible for spawning new instances of the Unity game server as players create new games. The player's data is safely stored in a MySQL database (passwords are hashed using Argon2 encryption and clients do not have access to the database; only the Go server does).
 +
 +
= Setup =
  
 
In order to play the Dedicated Server Kit demo, please follow these steps:
 
In order to play the Dedicated Server Kit demo, please follow these steps:
  
* Open the Unity Hub and create a new, empty 2D project with Unity 2019.4.0 LTS or higher.
+
* Open the Unity Hub and create a new, empty 2D project with <strong>Unity 2019.4.0 LTS</strong> or higher.
  
* Download and import the [https://assetstore.unity.com/packages/tools/network/mirror-129321?aid=1100l3nzZ Mirror] networking asset into your project.
+
* Download and import the <strong>[https://assetstore.unity.com/packages/tools/network/mirror-129321?aid=1100l3nzZ Mirror]</strong> networking asset into your project.
  
* Download and import the [https://assetstore.unity.com/packages/tools/network/dedicated-server-kit-173263?aid=1100l3nzZ Dedicated Server Kit] networking asset into your project.
+
* Download and import the <strong>[https://assetstore.unity.com/packages/tools/network/dedicated-server-kit-173263?aid=1100l3nzZ Dedicated Server Kit]</strong> networking asset into your project.
  
* Install the latest version of the [https://www.mysql.com MySQL] database on your machine.
+
* Install the latest version of the <strong>[https://www.mysql.com MySQL]</strong> database on your machine.
  
* Install the latest version of the [https://golang.org Go] programming language on your machine.
+
* Install the latest version of the <strong>[https://golang.org Go]</strong> programming language on your machine.
  
* Unzip the contents of the ''dsk.zip'' file located in the ''DedicatedServerKit/Core/Go'' folder on your machine. Run the ''create_database.sql'' script to create the database (this is only needed the first time) and run go build on the uncompressed dsk folder to generate the Go server binary. Finally, you can launch the Go server binary.
+
* Unzip the contents of the ''dsk.zip'' file located in the ''DedicatedServerKit/Core/Go'' folder on your machine.
 +
 
 +
* Run the ''create_database.sql'' script to create the database (this is only needed the first time). We highly recommend installing MySQL Workbench on your computer to make sure the ''dsk'' database is correctly installed on your machine.
 +
 
 +
* Start the [https://dev.mysql.com/doc/mysql-startstop-excerpt/8.0/en/ MySQL server] on your machine. You can easily do this via MySQL Workbench as well, as described [https://database.guide/how-to-stopstart-mysql-using-mysql-workbench/ here].
 +
 
 +
* Run '''go build''' on the uncompressed ''dsk'' folder to generate the Go server binary. Finally, you can launch the Go server binary on the command line. Make sure to leave it running for as long as you want the server to be available. '''Always run the Go binary from the command line and not by double-clicking over it, so that you can see the output on the command line in case there is an error.'''
  
 
* Build the game client and game server binaries by selecting the ''Build all'' option in the ''Tools/Dedicated Server Kit'' menu option.
 
* Build the game client and game server binaries by selecting the ''Build all'' option in the ''Tools/Dedicated Server Kit'' menu option.
  
 
* At this point, you should be able to run the demo by launching the game client build.
 
* At this point, you should be able to run the demo by launching the game client build.
 +
 +
= Go server's configuration file =
 +
 +
The Go server is the heart of the Dedicated Server Kit. You can easily configure it via the ''conf.json'' configuration file:
 +
 +
{
 +
    "ip_address": "127.0.0.1",
 +
    "port": 8000,
 +
    "db_connection_string": "root:@tcp(127.0.0.1:3306)/dsk",
 +
    "game_server_bin_path": "INSERT_THE_ABSOLUTE_PATH_TO_YOUR_GAME_SERVER_BINARY_HERE",
 +
    "game_server_port": 9000,
 +
    "jwt_key": "my_secret_key"
 +
}
 +
 +
This is the meaning of each field:
 +
 +
* '''ip_address:''' The IP address of the dedicated server.
 +
* '''port:''' The port number of the dedicated server.
 +
* '''db_connection_string:''' The MySQL database connection string. We use the default one for MySQL, which should work on any default installation of the database. Make sure to change the '''username:password''' part of the string to match your MySQL installation.
 +
* '''game_server_bin_path:''' The absolute path to your game server binary. '''If you are on Windows, make sure to use / as your separator character or, alternatively, escape the \ characters in your path so they look like this \\. The default configuration file we provide was written on a Mac OS machine, so it uses \ as the separator character.'''
 +
* '''game_server_port:''' The starting port number for every spawned game server instance. For example, if you use 9000 here, spawned game server instances will use ports 9000, 9001, 9002 and so on.
 +
* '''jwt_key:''' The encryption key used to generate the hashed passwords for your users. Make sure to use a unique, private value here.
 +
 +
= Opening your server ports =
 +
 +
Make sure your Go server port is open (TCP port 8000 by default and as specified in the conf.json configuration file) and your game server binary ports are open as well (TCP port 9000 and so on by default and as specified in the conf.json configuration file). Please note Mirror's default transport Telepathy uses TCP; if you use a UDP transport you need to make sure the ports you open on the game server binary side are the UDP ones instead of the TCP ones.
 +
 +
= Need any help? =
 +
 +
Are you running into issues trying to run the demo? Please [https://www.gamevanilla.com reach us] and we will be happy to assist!
  
 
|}
 
|}

Latest revision as of 21:41, 9 August 2020

Introduction

Dedicated Server Kit has four main components:

  • The Go server.
  • The MySQL database.
  • The Unity game server (using Mirror).
  • The Unity game client (using Mirror).

How do these components interact between each other? It all starts with the Unity game client, which is your actual game. Upon starting the game, your player will register a new account with the system (if he does not have one yet) and log into it. Once logged in, he can create new games and join existing ones as well. Communication with the Go server happens via REST calls. The Go server is responsible for spawning new instances of the Unity game server as players create new games. The player's data is safely stored in a MySQL database (passwords are hashed using Argon2 encryption and clients do not have access to the database; only the Go server does).

Setup

In order to play the Dedicated Server Kit demo, please follow these steps:

  • Open the Unity Hub and create a new, empty 2D project with Unity 2019.4.0 LTS or higher.
  • Download and import the Mirror networking asset into your project.
  • Install the latest version of the MySQL database on your machine.
  • Install the latest version of the Go programming language on your machine.
  • Unzip the contents of the dsk.zip file located in the DedicatedServerKit/Core/Go folder on your machine.
  • Run the create_database.sql script to create the database (this is only needed the first time). We highly recommend installing MySQL Workbench on your computer to make sure the dsk database is correctly installed on your machine.
  • Start the MySQL server on your machine. You can easily do this via MySQL Workbench as well, as described here.
  • Run go build on the uncompressed dsk folder to generate the Go server binary. Finally, you can launch the Go server binary on the command line. Make sure to leave it running for as long as you want the server to be available. Always run the Go binary from the command line and not by double-clicking over it, so that you can see the output on the command line in case there is an error.
  • Build the game client and game server binaries by selecting the Build all option in the Tools/Dedicated Server Kit menu option.
  • At this point, you should be able to run the demo by launching the game client build.

Go server's configuration file

The Go server is the heart of the Dedicated Server Kit. You can easily configure it via the conf.json configuration file:

{
    "ip_address": "127.0.0.1",
    "port": 8000,
    "db_connection_string": "root:@tcp(127.0.0.1:3306)/dsk",
    "game_server_bin_path": "INSERT_THE_ABSOLUTE_PATH_TO_YOUR_GAME_SERVER_BINARY_HERE",
    "game_server_port": 9000,
    "jwt_key": "my_secret_key"
}

This is the meaning of each field:

  • ip_address: The IP address of the dedicated server.
  • port: The port number of the dedicated server.
  • db_connection_string: The MySQL database connection string. We use the default one for MySQL, which should work on any default installation of the database. Make sure to change the username:password part of the string to match your MySQL installation.
  • game_server_bin_path: The absolute path to your game server binary. If you are on Windows, make sure to use / as your separator character or, alternatively, escape the \ characters in your path so they look like this \\. The default configuration file we provide was written on a Mac OS machine, so it uses \ as the separator character.
  • game_server_port: The starting port number for every spawned game server instance. For example, if you use 9000 here, spawned game server instances will use ports 9000, 9001, 9002 and so on.
  • jwt_key: The encryption key used to generate the hashed passwords for your users. Make sure to use a unique, private value here.

Opening your server ports

Make sure your Go server port is open (TCP port 8000 by default and as specified in the conf.json configuration file) and your game server binary ports are open as well (TCP port 9000 and so on by default and as specified in the conf.json configuration file). Please note Mirror's default transport Telepathy uses TCP; if you use a UDP transport you need to make sure the ports you open on the game server binary side are the UDP ones instead of the TCP ones.

Need any help?

Are you running into issues trying to run the demo? Please reach us and we will be happy to assist!