Custom Multiplayer Room in TCP/UDP Server

Hi all, I’d like to know the basic ideas of how to implement a multiplayer room system.
I’m currently building a server solution from scratch using raw TCP/UDP.

Think about the game as that one from Super Cell, Brawl Stars. You have the lobby, then after 6 players join the lobby, it moves them to a room. Currently my server takes care of the movement and collisions, so the “worlds” with colliders are in the server side. Also I’d like to keep every world/room/arena inside the same server instance.

What are my choices?

My thought was to create scenes with SceneFactory and spawn players inside their scenes (worlds)

I’m not entirely sure what you’re actually asking for. If you build your network code from scratch, you possibilities are endless since it’s completely up to you how you want to implement it and what features you want.

The the whole “room” / lobby implementation I would probably use TCP since you don’t have to worry about lost packets. So all basic management stuff just works. However when you want to have your game using a single port / protocol type there are already some considerations to take care of. For any realtime FPS game you usually want to use UDP to get a better reaction time. If the game isn’t that fast paced TCP would probably work as well and would be a bit simpler. Using UDP can be quite challanging since you have to keep a reasonable PDU size to avoid / minimize the risk of fragmentation due to the MTU size.

So it highly depends on your requiremens and specifications for your network application which approach is the best one. The question is do you want to build “Yet Another General Network Solution” or do you want to create one that is optimised for your usecase? Many basic decisions have to be made upfront.

Another thing to consider is how robust your protocol is against forged packets or if you actually need a protection against it. We all know the general rule “never trust a client”. So for public games your receiving code on the server has to expect receiving literally “anything” from a client. So your code should be able to detect malformed packets / messages / steams and act in a safe way (usually dropping the client).

Building a straight forward protocol is kinda trivial, making it robust is another story. Just have a look at the example I’ve posted over here. It’s one of the most primitive implementations of a message protocol on TCP. However it completely relies on the fact that no data is dropped or goes out of sync since it always sends the size of a message, followed by the message itself. In such a unicast example that isn’t really an issue.

When talking about “rooms” it also depends on what such a room should represent. If you just want seperate game sessions on the same server or if you have “instance servers” (either dedicated or client hosted servers) where the members of a room get send to once the game starts. Each approach has it’s own limitations and difficulties.

Depends on your platform. I have to say that Mirror is great at multiplayer room systems, however, I’ve found multiple problems with using LAN or matchmaking for mobile devices. Photon PUN on the other hand, is a bit harder to get started with, but provides great solutions for mobile multiplayer as well as many many other platforms. Personally, I use Photon PUN (free on the asset store). Their tutorials and documentation are great to get started with.