Multiplayer tutorial 1: concepts

Favourite 194 favourites
Tutorial written by AshleyOriginally published on 3rd, March 2014 - 4 revisions

Signalling

As noted in the previous section, for a peer to connect to the host, it needs to find out their IP address and determine how to connect to them. The host could be anyone, anywhere in the world, so it's impossible to know in advance who to connect to. So to allow players to find each other, there is a separate central server called the signalling server.

The signalling server does not host actual games: the first player in to a room hosts the game and transmits game data to the other peers. Signalling is simply a central place for players to go to find each other. When a peer wants to join a host, the signalling server relays information such as the IP addresses and connectivity details between the two. Once the peer has successfully connected to the host, the signalling server is no longer involved and the players are communicating between themselves directly.

How the signalling server helps set up multiplayer games
Scirra host a public dedicated signalling server at wss://multiplayer.scirra.com. (wss: indicates a secure WebSocket connection, since signalling data happens to be relayed over WebSockets. The games themselves still run using WebRTC.)

Signalling terminology

The signalling server needs to avoid mixing up players from unrelated games, and allow different groups of players to arrange separate games at the same time. To do this, players join a room in a game instance.

The signalling server separates players first in to each game. Your particular game should have a globally unique name on the server. Then everyone from your game joins the same game on the signalling server. This avoids players for your game getting mixed up with players from unrelated games that work completely differently! For each game you create, you should only use one game on the signalling server. To ensure your game name is unique on the server and never accidentally also chosen by someone else's game, include you or your company's name, e.g. "MyStudio-Asteroids" or "JohnSmith-Asteroids" instead of just "Asteroids". (This name is never displayed anywhere and is only used internally on the signalling server, so feel free to add other details to ensure uniqueness.)

Next the signalling server separates players in to a game instance. This allows you to run different isolated instances of your game. For example you may wish to have a "stable" instance which most players join, but a "beta" instance for testers using the next (and slightly different) version of your game. This would prevent beta testers connecting to the normal players who might have different game mechanics or features. For the same reason instances could be versions, like "v1.0", "v1.1", "v1.2", always ensuring players only see other players with the same version of the game as themselves. Alternatively another good use is having location-based instances, such as "Europe", "North America" and "Asia". Assuming players join the instance for their actual location, they will only see other players in their same location, improving the chance of a good quality connection to them. These purposes could even be combined such as "Europe-v1.1", "Europe-v1.2" etc.

Finally players can join a room. A room represents a group of players who are playing with each other. Players cannot see any other players other than those in the same room. The first player in to a room is assigned the host. Then the signalling server notifies the host of any other players who join the same room. They then connect to each other and can start playing the game, seeing each other's actions in real-time!

In Construct 2's Multiplayer object, all actions, conditions and expressions relating to the signalling server are in the Signalling category. All the other features relate to the games themselves.

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

10
stefanos 3,453 rep

Yeah that's nice :)

Monday, March 03, 2014 at 8:36:42 PM
12
Vallhalen 3,037 rep

This is FANTASTIC !

Monday, March 03, 2014 at 8:43:51 PM
7
Leandrus 5,871 rep

Excellent!!

Monday, March 03, 2014 at 8:55:27 PM
5
SgtConti 4,896 rep

Very interesting, hopefully the beta release comes tomorrow ;)

Monday, March 03, 2014 at 9:02:03 PM
7
DUTOIT 12.7k rep

Fantastic :)

Monday, March 03, 2014 at 9:05:34 PM
5
emoaeden 9,672 rep

I can't wait to try this !

Monday, March 03, 2014 at 9:07:53 PM
5
NeoBiel 4,566 rep

Meu sonho se realizando...

Monday, March 03, 2014 at 9:08:29 PM
3
albrektv 8,076 rep

Thank you for the lesson that you are waiting for him

Monday, March 03, 2014 at 9:11:31 PM
4
valdarko 6,277 rep

how it will handle data save, like itens and stuff?

Monday, March 03, 2014 at 9:33:35 PM
3
Joskin 6,089 rep

Yes ! Thanks a lot !

Monday, March 03, 2014 at 10:23:48 PM
3
jobel 14.6k rep

I'm very excited to go through this! thanks!

Monday, March 03, 2014 at 10:35:05 PM
5
DatapawWolf 30.7k rep

I notice this does not address the subject of host cheating. Preventing the clients is nice and all, but, for example, say the host hacks their client, they could now send whatever they want to the peers.

Now you could say that anti-cheating measures and checks could be implemented, but then you could apply that same logic to each client as well.

Thoughts, anyone?

Monday, March 03, 2014 at 11:17:34 PM
4
popyui 1,594 rep

Me gusta mucho esto y me da una mejor idea de como funcionan mis juegos de mis consolas

Monday, March 03, 2014 at 11:19:48 PM
2
DatapawWolf 30.7k rep

Also, not to spam, but addressing the "Lag Compensation" techniques. I'm sorry but if a player has a bad connection in a shooter game, too bad for them. Newer games in the Call of Duty series have notoriously infuriating lag comp which is responsible for all sorts of nonsense.

In my opinion it's a technique that is often overused and should not be looked as much as interpolation or other ways of synchronizing between peers.

Monday, March 03, 2014 at 11:29:12 PM
4
DatapawWolf 30.7k rep

"By default updates are sent 30 times a second"
We will be able to modify this, correct? Or send out updates only when needed? It'd be wasteful to constantly spew out that much data for something like a grid/turn based game, where movement may be as low as 1 grid square per 100ms, or not at all when a player is AFK.

Monday, March 03, 2014 at 11:32:42 PM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.