alvyxaz / barebones-masterserver

Master Server framework for Unity
476 stars 106 forks source link

How to create multiple rooms per Unity instance? #153

Open spvn opened 6 years ago

spvn commented 6 years ago

In the v2.0 update, it was stated that the ability to create multiple rooms per instance was added. However there are no examples or docs regarding this topic and I would really like to find out how.

From what I understand, a master server creates a spawner, which spawns a unity instance (game server) which (after switching to the right scene), creates a "room" and registers the room to the master server. Thus, 1 spawned game server is tied to 1 game server scene which is tied to 1 room.

How do I create multiple rooms within a server instance, when that server instance can only run one "game server scene" at a time? I'm pretty sure I understand how to get a client connected to a room based on a roomID, but how do I distinguish between multiple rooms on the same unity instance to operate a unique "server" for each room?

EDIT: After further reading. I have ascertained there are two options.

1) each player has their own unity instance (which will take up a lot of resources in my case as each player is going to have their own instance where they face a server-controlled boss-enemy)

2) I create multiple virtual rooms on one unity process and do my own gameplay synchronisation. Anybody can point me in the right direction for this? After a client connects to a specific room in a unity instance, how should I go about synchronising the game state from there? I can no longer use unity's high level networking solutions right?

joaoborks commented 6 years ago

It's simpler than that. The Spawner Server can hold as much instances as you set (and your hardware support), so it could create for example 10 Game Server instances (each tied to a room) on 1 machine. Once the player connects to this Room, you can use Unity's HLAPI as if you got there connecting by their NetworkManager. It's the same thing, MSF just changes the way the servers work and gives more control over multiple servers.