- Home /
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
Answer by J3-Gaming · May 09, 2012 at 10:06 PM
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.
Thanks for the tips. You are talking about Host $$anonymous$$igration ("sever host" leaves and the game does not stop). How did you implement this?
Well I am almost done it, it is no small task. You definably need a strong program$$anonymous$$g background with basic networking knowledge (Like how a host and client should communicate)
Some tips is to wrap everything into 3 different classes (like i said above) in a very exact flow-chart method. If you can't draw it on paper without lines crossing, get another sheet of paper.
The secret of everything is the method OnPlayerConnected(NetworkPlayer player) This is called when a client connects. player.guid can be saved and sent over an RPC to notify everyone this will be the next host if something happens.
Answer by gecko938 · May 15, 2012 at 02:21 AM
My version of the play online button (quick match) works something like this:
User clicks the play online button
Game kicks off a query to the master server for existing matches (MasterServer.PollHostList())
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
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.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Networking Player Nametag 1 Answer
Best cross platform Http Library? 1 Answer
Console Application 0 Answers