alvyxaz / barebones-masterserver

Master Server framework for Unity
476 stars 106 forks source link

New to MSF, trying to understand Server Architecture #158

Open shubhank008 opened 6 years ago

shubhank008 commented 6 years ago

I am new to MSF and must say, fantastic project, specially being free and opensource now (the CCU limits on UNET/Photon were a bummer).
I have checked the quick start and getting started wiki pages but wanted to better understand the server setup and clarify a few doubts.

If I understand correctly, if one is to setup a proper server setup (vps/dedicated), then there are basically 3 different Game Builds (Client, MasterServer, GameServer).
Now, is SpawnServer a separate entity or GameServer and SpawnServer are one and all, with SpawnServer launching instances of GameServer ?

Furthermore, my other doubts and queries are:

  1. I understand that MasterServer and Spawn/GameServer can be hosted on the same server, but for the sake of it, I want that as a last ditch effort and want to keep my MasterServer and GameServers separate, since I want to introduce Region based game servers for better latency (its a real time action game).
    To do that, what DefaultMachine IP(s) and ServerIP(s) do I need to use and setup ?
  2. Does the spawner only spawns gameinstances on same server or can it spawn full servers too (cloud like digital ocean or AWS) to scale the network infrastructure as and when needed ? How do one detect the need to spawn new server or shut it down ? Again, I am a little confused on difference between SpawnServer, Spawner, gameServer and Lobbies/Rooms.
  3. Are GameInstances (what spawner launches/runs) similar to the concept of "Photon Rooms" where you specify a fixed number of players and create multiple rooms till you reach your server/hardware limit ?
  4. Can LAN (local-only, self hosted) be incorporated in this so that the player has option of LAN (local network only), Online (self-hosted server) and Dedicated (region-specific our servers) ? I understand there might be NAT issues, but again, I am a bit confused on how to dynamically setup IPs or manage these stuff.
  5. Can we use hostnames whenever and wherever IPs are required ? I believe using hostnames gives better reliability in case of changing servers or using a loadbalancer/proxy (RoundRobin).

PS: Sorry for so many questions, I am a quick learner but just a bit confused here at start. Anyone taking their time to answer, you have my regards and thanks.

joaoborks commented 6 years ago

I'll answer your first question within the question number 2. 1- As far as I know, if we want to use region-based we need to create something above the Master Server (I'd even suggest the community to build it as this is an open source project). On the ideal approach, we'd have a server with only the Master Server, and then other servers with the Spawner/Game Servers. 2- Yes, the spawner only spawns intances on the same servers (so far). Whenever a Spawner Server is created, it registers itself on the Master Server, along with its max instances property, so the Master Server can ask this spawner to spawn game instances. The Game Servers will terminate themselves after no more players are connected or when the match is over (it will depend on your game type). I'm not sure about lobbies and rooms, because I didn't dig on that too much, but I'm aware that there's a demo for that on the framework, I'm sure you'll get it once you try it. 3- Yes, it's the same concept, and what defines this limit is the Spawner Server. 4- I managed to do this using UNet's LAN components, so it is possible. Self hosted servers are likely to have NAT issues, and they could be done with pure UNet too. 5- No clue on that one, sorry 😞

shubhank008 commented 6 years ago
  1. Yep yep, thats what I think too. Basically I think one can keep a single-region based master server(s) since latency to master server doesn't really affects actual game play, while you can keep game servers in multiple regions and then its the master server (or matchmaker) which decides on which game server (or perhaps lobby) to connect to based on geolocation or user-selected Region.
    I think this can be even more simplified to setup without modifying Master Server a lot. Instead of Master Server managing the region-server selection, we can introduce a proxy server or load balancer in front of master server and then use reverseProxy to make that server select and connect to each region's master server. It will be that proxy/load balancer server which will handle location/region detection to auto-select the master server of that region. So basically if you have 3 regions, you can have multiple game servers in each region and one master server per region to manage GS's of that region.

    Last but not the least, I was thinking to use If/Else/Switch within my game code itself to make the client act sort of pseudo-server selector. For that, I would use hostnames of servers instead of IP and switch between which master server (hostname) to use based on user's selection.


  2. Yeah aware of NAT issues but I wanted to add LAN for local play and single player (with bots) if only 1 player playing. I will play around with UNET LAN implementation for this I guess, since my purpose is to use LAN for Wifi/same network based play and for Single Player game.
    I am aware of the fact that player-hosted GameServer will/can have NAT issues as well, is there any way to detect such issues to guide players to fix them or just let them know they can't host ? Telling them about NAT issue and to use dedicated server is better than them waiting to connect or for players to join unaware of the issue.
    Can simply checking if the user has a public IP or if they can connect to master server detect NAT issues ?

  3. I will test this out too I guess, this will open a lot of flexibility and scalability to my other needs and queries above :D

I use GIT for plain versioning and commits so no idea how PULL requests or contributing to open source works, but if I end up creating the Load Balancer/Region functionality and the dynamic whole server spawning (create new cloud server, transfer game server, run it, shut down cloud server), I will make sure to submit my code snippets and guide on how to do it. I hope someone else can then pick them up and submit/contribute to the MSF project as PULL request or whatever.

joaoborks commented 6 years ago

It's pretty simple to make pull requests, you just need to fork the repository, then make a commit on your end and a pull request here. 1- If you manage to start this, please share with us so we can help and push it further! 4- LAN has no NAT issues, it's actually works pretty straight-forward. Most games that does the player hosting approach suggests the players to port-forward the given server port. There are ways to determine if one is able to host a public match following your ideas.

shubhank008 commented 6 years ago

@JoaoBorks @JadeWhite I would really appreciate if you could help me a bit, I played around with MSF a bit over the last 2 weeks and integrated with my game.

  1. Dedicated server (vps/linux) works fine if I host both master server and spawner/gameserver on it. I am able to connect from my PC and play.
  2. I was trying to create a LAN implementation so the players can play with Bots, for which I wanted to just start a master server and game server locally, for that I just changed both MS IP and Spawner IP to localhost and it worked. (So client was both client, MS, GS and Spawner).
  3. Now to expand on that, I also wanted clients to be able to act as Spawners/GameServers and host their own servers and connect to our main Master Server. For this, I changed ConnectionToMaster object's ServerIP to my remote Linux Server (running as both master and spawner) and changed Spawner's DefautltMachineIP to my own public IP (the build running on masterserver uses its own IP for its spawner).
    However, this part is not working. On my client, I am not running MasterServer (StartServer()) but instead directly called StartSpawner once I detect that ConnectionToMasterServer is done. But nothing happens, no log, no error, just nothing. In RoomsList I can only see the MasterServer's Game Room (its not mine but the one spawned by MS).
  4. Furthermore, once I try to do the above, I am unable to use my LAN approach as well (for which I was changing both IPs to localhost via code and then calling StartServer()).

I am really confused and clueless where I am going wrong.
What I want is to be able to host our own servers, let users also host their own servers/lobbies (well rooms perhaps) and users being able to do LAN (in case no internet or offline play)