-
Notifications
You must be signed in to change notification settings - Fork 2
Master Server And Modules
In general, Master Server is a type of server to which everything connects (a central server).
Master Server Framework is a framework designed to kick-start the development of such server.
Master Server itself is actually a pretty simple script, which:
- Listens to a specific port for clients, so that clients can connect to master server
- Looks for modules in the scene and initializes them.
You can add the Master Server to any scene by creating a game object and adding Master
component to it. Here's an example of the most simple Master Server you can have:
To add modules, you simply add new game objects and attach module components (scripts) to them. It doesn't matter where you place your modules in the scene, for example:
.Initialize(IMaster master)
method will not be called.
There are three ways in which you can start the Master Server:
- In the editor:
Master
component has a flag in the inspector called "Auto Start In Editor". When it's set, Master Server will be started automatically when you hit the Play button in the editor. - Through command line arguments: 🔗 Command Line Arguments
- By manually calling
Master.Start()
in your scripts.
You'll probably want to start the server in editor when you're developing, through command line in production, and manually - if you have something special planned (a UI, for example).
ℹ️ Master
component has a flag in the inspector called "Auto Start In Editor". When it's set, Master Server will be started automatically when you hit the Play button in the editor.
ℹ️ Master
component also looks for a special command line argument
You can connect to master server simply by calling
Connections.ClientToMaster.Connect(IpAddress, Port)
Or you can do it manually by creating a socket 🔗 More info on Networking
Modules are simple unity scripts (MonoBehaviours) intended to add functionality to Master Server.
As described above, master server merely initializes other modules. You can find modules in the Barebones/MasterModules/
folder.
Let's say you've decided to add a shop to your game. Shop processes (buy/sell, etc.) should be handled in the central server (master server).
So, to add new functionality (shop) to the master server, you can create a ShopModule, which will handle buy / sell requests from clients.
When working on a game, your Master Server will be a combination of custom modules and modules from the framework
🔗 More info about creating modules
ℹ️ Its recommended to have modules as children of Master
component, because then you can save it as a prefab and use in other scenes when developing.
Modules are unity components, and can be extended/modified by overriding their virtual methods