Skip to content

ZaviiNet-Studios/MasterServer-Controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MasterServer-Controller

Introduction: This project contains scripts for managing game servers using Docker containers. The scripts are written in C# and are intended to be used in a Unity project.

Features

  • Start and stop Docker containers running game servers
  • Connect to a MySQL database to store and retrieve data about the game servers
  • Remove idle game servers (i.e. servers with 0 players)

Prerequisites

  • Docker must be installed on the machine running the scripts
  • A MySQL server must be running and accessible from the machine running the scripts

Getting Started

  1. Clone the repository and open the project in Unity
  2. Modify the connection string in the DatabaseManager script to match your MySQL server setup
  3. Modify the ImagePath and PortPoolStart variables in the ServerStarter script to match your desired Docker image and starting port for the game servers
  4. Attach the ServerStarter and ServerStopper scripts to a game object in your scene
  5. Use the AddSever() To Add a new Server and RemoveServer() to remove idle Servers.
  6. Make the Table in MYSQL
CREATE TABLE game_servers (
  id INT PRIMARY KEY AUTO_INCREMENT,
  ip_address VARCHAR(15) NOT NULL,
  port INT NOT NULL,
  player_count INT NOT NULL,
  max_capacity INT NOT NULL,
  instanceid VARCHAR(255) NOT NULL
);

API Reference

The ServerStarter script is responsible for starting Docker containers running game servers.

Parameter Type Description
ImagePath string Required. The path to the Docker image to use for the game servers
PortPoolStart int Required. The starting port number for the game server containers. Each subsequent game server will use the next available port in the pool.
_client DockerClient A client for interacting with the Docker daemon
_addedServers List<> A list of game servers that have been started by this script

Starting A Server (Recommended to use the AddServer Command)

  StartServer() //Starts a new game server in a Docker container

Usage

To start a new game server, use the StartServer method in the ServerStarter class. This will create a new Docker container for the game server and add it to the _addedServers list.

To remove idle game servers, use the RemoveIdleServers method in the ServerStopper class. This will stop and remove any game servers that have a player count of 0, and delete the corresponding records from the MySQL database.

To save data about game servers to the database, use the SaveGameServerData method in the Database class. This will insert new game servers into the database or update the player count of existing game servers.

To retrieve data about game servers from the database, use the GetPlayerCount method in the Database class. This will return the player count for the specified game server.

Conclusion

This server management system provides an easy way to host and manage multiple game servers in Docker containers, and saves and retrieves data about the servers from a MySQL database.

Authors

Contributing

Contributions are always welcome!

Open an Issue to get started, Pull Requests welcome!

Please adhere to this project's code of conduct.

License

gpl-3.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages