Skip to content

Assambra/Master-Server-Unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License

Master-Server-Unity

Assambra Logo

Unity-Master-Server

Table of Contents

Key Features

  • Extending EzyFox Server's room management to launch a dedicated Unity server
  • One Unity-Server for all rooms/servers

(back to top)

Project Setup

Clone the repository:

git clone [email protected]:Assambra/Master-Server-Unity.git

Get submodules:

Open your Git command client, go to the Master-Server-Unity directory, and clone the submodules.

cd Master-Server-Unity
git submodule update --init --recursive

Now open both Unity projects, Unity-Server and Unity-Client, in your Unity editor. You will get a bunch of errors; ignore them for now as we will fix this in the next steps. Do the following step for both projects because it is identical in both projects.

Go to the folder Assets/EzyFox Server - C-Sharp Client - Unity in your Unity Editor, right-click -> Create -> Assembly Definition, and rename it to

com.tvd12.ezyfoxserver.client

Server: In the Unity Editor, open the folder and select the file Assets/Server/Scripts/Assambra.Server.

Client: In the Unity Editor, open the folder and select the file Assets/Client/Scripts/Assambra.Client.

In the Inspector under Assembly Definition Reference, there is some missing reference starting with GUID:. Delete this one and add a new one with the plus sign and select the earlier created com.tvd12.ezyfoxserver.client assembly definition. Don't forget to hit apply, then it should recompile and the errors should be gone.

(back to top)

Project Structure

A brief overview of the structure of the project. We use three projects: master-server (EzyFox Server), Unity-Server, and Unity-Client. It is important to know that the Unity-Servers are also clients for the master-server, and we always use the Ezyfox Client SDK for communication between Unity-Client <--> master-server and master-server <--> Unity-Server.

(back to top)

Master-Server

We use an EzyFox server that acts as a master server. Its tasks are user management, processing database requests, and starting and managing a Unity server for each room. The client makes a request to the master server, which forwards the request to the Unity-Server. Once these requests have been processed by the Unity server, they are sent to the master server and from there sent back to the client(s).

Setup Database

  1. Install mongoDB.
  2. Open your mongosh.
  3. Create your Database:
use master-server
  1. Create a new user and password and give it access to the created database:
db.createUser({user: "root", pwd: "123456", roles: [{role: "readWrite", db:"master-server" }] })
  1. Create the following collections:
db.createCollection("user", { collation: { locale: 'en_US', strength: 2 } })
db.user.createIndex({ username: 1 })
db.createCollection("character", { collation: { locale: 'en_US', strength: 2 } })
db.character.createIndex({ name: 1 })
db.createCollection("character_location", { collation: { locale: 'en_US', strength: 2 } })
  1. Use this file for the next step:

Location: master-server/master-server-common/src/main/resources/master-server-common-config.properties

  1. Insert the following values for your database and change them to your needs:
database.mongo.uri=mongodb:https://root:[email protected]:27017/master-server
database.mongo.database=master-server
database.mongo.collection.naming.case=UNDERSCORE
database.mongo.collection.naming.ignored_suffix=Entity

In this example file, we use:

  • user: root
  • password: 123456
  • database: master-server

(back to top)

Unity-Server

We use a single project for the Unity Servers. The server contains all server scenes that correspond to a room. When it starts, the server receives three parameters: username, password, and room. The server then uses our Module-GameManager to start the corresponding server scene. This has the advantage that, on the one hand, we only use one project and do not have to create another server project for each server and can therefore share the code that is the same for all servers. The Module GameManager uses a persistent scene where all manager classes/GameObjects are located. The room scene with the 3D objects such as terrain are additionally loaded.

(back to top)

Create the Unity Server

Open the Unity-Server project in Unity. Open Build Settings: File -> Build Settings. Be sure to include all server scenes in "Scenes In Build"; if not, add them. Select as Platform Dedicated Server and choose under Target Platform your platform, Windows or Linux, and build the project.

(back to top)

Setup Server Path

Open the master-server project in your IDE, edit the file: master-server/master-server-app-api/resources/application.properties and add the path to your server executables from the previous step where you saved them. E.g., D:/Game Builds/Unity-Server/Unity-Server.exe.

(back to top)

Unity-Client

Open the Unity-Client project in Unity and use the Persistent Unity Scene location Assets/Client/Scenes/Persistent. If the master-server is running, you can click Play in the Unity Editor.

(back to top)

Contact

Join us on Discord

(back to top)

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published