Networking with master server - howto: get events and create game servers

Preamble:
I have downloaded the master server example and I am more than comfortable extending it.

I have 2 questions:

  1. How do I extend the example unity raknet master server to have it automatically put players into “game servers” (no user choice) that are distinct (no network traffic between them, only the clients within them).

  2. How do I extend the master server to capture events? I would like to be able to capture when a player joins, dies (and who they where killed by), and leaves so I can put it on a website for fun statistics.

Thanks for your time,

~Eric

The master server is not used for game logic (player dies, ect)

Master server is only used to register devices as their own hosts, or find host devices to connect too.

Once you have this:

GAME 1

Device A - Host

Device B - Client

Device C - Client

GAME 2

Device A - Client

Device B - Host

ect, then you can start putting the game logic on the hosts with security and cheating checks between the clients to make sure the host is not cheating also.

EDIT: The last and hardest step will be to add host ‘switching’, that way when the host disconnects you will not lose the game state, another client can take over. I found your question because of what I am doing, What I have described above had taken me 3 scripts, about 150-200 lines each that include delegate callbacks. Basically wrap the MasterServer class, wrap the Network class, and then create a class for interaction. Because this code is non-blocking, I used delegate and events (Example: Finger Gestures plugin) for control.

Good luck, enjoy the next 20 hours of life.

My version of the play online button (quick match) works something like this:

  1. User clicks the play online button

  2. Game kicks off a query to the master server for existing matches (MasterServer.PollHostList())

  3. Wait for your OnMasterServerEvent() callback to fire with the MasterServerEvent.HostListReceived event. If any matches were found with available player slots, then try to join them

  4. If no matches are found on the master server, or they are all full, or the client fails to join them, game eventually decides to host a new server locally

As noted by MightyGoob, you want to do all that stuff asynchronously (UI shouldn’t freeze while searching). You’ll want some sort of simple state machine to keep track of where you are in the search/join (automated matchmaking) process.

You’ll also want to ensure you’ve gone through connection tester (NAT type detection) before you start trying to join or host sessions.