I want to share my custom unet architecture that i made for my multiplayer network games. i will write all details here. i will update documentation regarding your questions. I did this to have an authoritative server.
Glossary
Windows Server : A computer with Windows Server operation system (OS)
IIS : Internet Information Services. It is an web application container that comes with Windows Operating System.
Windows Service : A background application running on Windows OS
Game : A unity build that contains both server and client code. Server code will run on Windows Standalone Build. It will be run as Instance on Game Server. Client part will be run client devices like phones.
Game Server : A computer that hosts unity game server parts.
MVC : Model View Controller framework. It is used for GUI for web pages, desktop applications etc.
Web Service (WS) : Communication services that generally uses xml as data format.
Rest Services : Communication services that generally uses JSON as data format.
WCF : Windows Communication Framework. It is used to build communication services as many different protocols(ws, rest, tcp, etc)
File Repository : A folder that contains files to process.
Instance : A running copy of an application. In this case it is Unity Game Windows Build.
CCU : Concurrent user
System Parts
Control Center
It manages all user, game, session, instance, versioning processes.
Center File Repository : It contains all game file versions to deploy it to game servers.
System Database : It is used to save all user, game, room, session data.
Admin Pages : It is an web application. It supplies pages to add/remove game, server definition and see some statistics about session, room counts.
Web Services : They are used to upload new game version files to Control Center Repository. All web services uses https to have secure transport and uses username/password for authentication/authorization.
Rest Services : Because they are Unity friendly it is used by Unity game server and game clients. All rest services uses https to have secure transport and uses username/password for authentication/authorization.
Game Server Node
It hosts all Unity Game Server parts. For this system there should be several nodes. It depends on CCU count. A server node can host several games and several server node can host a single game. It depends on your design.
Agent : It is a windows service that always runs. It starts and kills instances. There is a single agent per server. It has a WCF host to publish Web Services. Control center uses these services to control agents. Agents can collect statistics from instances.
Agent File Repository : It contains unity game build files. There should be different build versions like one for Android devices one for iOS devices because you cannot release new game version on both store at the same time. Agent will run xxx.exe file in this repository to start an instance.
Unity Game Instance : Running version of a game’s Windows Build executable. In my design an instance can handle several rooms and sessions. In many case you can do it. If your game levels are complex you should run an instance per level to handle specific level. For turn based games like chess, it is easy to use single instance to handle several rooms.
Admin Console : It is web pages to manage this system.
Game Version Uploader : After you build a new version you can upload new files to Control Center via this application.
Unity Game Client : It is build of your game for several platforms like Andoid, iOS, Window Universal etc. Thanks to UNET, a build contains both client and server code. If you have server specific code like hard coded passwords you can disable this code by using Unity platform defines.
Coding
This system uses UNET. You write your code for both server and client side in the same NetworkBehaviour classes. You use Rpc methods to call client side from serverside. You use Command methods to call server side from client side. Both calls are one way you cannot get return value. So you can accept them as triggers. You can use syncvars to sync values on both side. Even you can use the same NetworkBehaviour class on both server and client side, These classes are isolated. So you must trigger other side or sync variables. Trigger calls received in order and syncvars are synced at the end of the update method. So i prefer triggers to sync values and states. There should be a player prefab on the scene to manage network process. I prefer having single player object per client. For a chess game there are 2 player prefabs on the server side. If you use Unity’s standard network classes like network manager, you will get 2 player prefab on each client. I use my custom network manager to have single player prefab on each client. This single player prefab manages game. If your game is not an MMO, single player will be enough to manage a network game. I use server side player prefabs to manage authoritative processes. I use client side player prefabs to manage GUI processes. In that way client devices become dummy terminal. I set room classes on the server side. When a player make a move, it sends a command to server and server process this. Then server calls rpc on all client prefabs that saved in the room class.
Sequence
Registration
New clients calls RegisterDevice rest service. Control Center keeps all devices as a user in the System Database. Service generate a passcode and returns it to the device on registration call. Device uses this passcode for further service calls. System uses device’s unique id and some hardware information to define it unique.
Joining Room
Client calls JoinRoom rest service for a specific game. When a registered device calls a service function for a game, system creates a game registration for this device automatically. Control Center checks Game Server Nodes and their loads. If there is no Unity Game Instance for this game or current one if full, it creates a new Unity Game Instance by calling Agent. JoinRoom call returns IP, Port address and created session passcode.
Creating New Unity Game Instance (UGI)
Control Center(CC) calls Agent’s Web Service to create a new UGI. CC sends executable file location on the disk and send executable arguments. UGI uses arguments for setting port, persistence location, log file location. Each instance uses different log file that has name as instance id. Each instance has different socket listener port. Agent uses this port to communicate with the instance. Because Agent is an windows service written by pure .net, i cannot communicate with an Unity Windows Build. UGI starts a SocketListener and accepts Agent’s commands via this socket connection. When the computer or the Agent restart, Agent gets all instances information from Control Center and it starts these UGIs.