Advices for multiplayer game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Advices for multiplayer game

Post by Fenrir »

Hi guys,

I'm currently developping a multiplayer game with Love and I'm currently starting to prototype the master/slave architecture, but I must admit that I'm more a graphic developper, and it's the first time I work on that.

So the idea behind this topic should be to get some advices on what are the good practices to follow, or what are the common mistakes to avoid?
Here are some characteristics of my game :
- Top down view in quite small levels.
- Up to 4 players.
- IA controlled entites.
- No dedicated host (at least for the first version), one player will host.
- Should be possible to enter/leave a game at any moment (except for the host, if he leaves the game stops).
- Simple interactions with doors, switch, traps, etc...

For instance, what are the common practices for IA pathfinding? I was thinking to leave it to the host (as there's a bit of random to get more natural movements), and send the computed path to each client.
If you have some good readings about this topic, don't hesitate to share!

Thanks!
User avatar
RedHot
Citizen
Posts: 87
Joined: Mon May 27, 2013 2:43 pm
Location: Poland

Re: Advices for multiplayer game

Post by RedHot »

As for path-finding. If your game is tile based read about Djikstra or A* ("A star")
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:16 am, edited 1 time in total.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Advices for multiplayer game

Post by Plu »

It seems risky to me to rely on generating the same random numbers on each machine by matching the seed; it only works if each machine implements the exact same random number algorithm (which as far as I know is not a garuantuee?)
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Advices for multiplayer game

Post by miko »

Fenrir wrote:- No dedicated host (at least for the first version), one player will host.
I would implement the server in plain lua+luasocker, using UDP as a protocol, even if your final game will not use the dedicated server (i.e. one of the clients will act as a server). The reason is that it will guarantee logic separation: things will work if you decide later to make a dedicated server, and the "hosting client" will not have an advantage (except for lowest network delay).
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: Advices for multiplayer game

Post by Fenrir »

I would implement the server in plain lua+luasocker, using UDP as a protocol, even if your final game will not use the dedicated server (i.e. one of the clients will act as a server). The reason is that it will guarantee logic separation: things will work if you decide later to make a dedicated server, and the "hosting client" will not have an advantage (except for lowest network delay).
Well the logic separation is actually what I'm currently working on, and as I'm keeping in mind that it should be nice to have a dedicated server, I'm trying to design it the most autonomous way possible, but I don't want to add a new layer of complexity right now by doing it in a separated software.
As for path-finding. If your game is tile based read about Djikstra or A* ("A star")
Pathfinding is already implemented, I was just wondering how to manage it in a server/client architecture.

For instance, let's say I compute the IA paths on the server and send it to all clients, it raises to me some questions :
- Should I send the whole path when computed and let the clients apply it without sending back IA positions for validation ?
- Or should I just send the current IA position at each frame without sending the whole path ?
Is there any recommendation on packet size or frequency I should rely on ?

Thanks!
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Advices for multiplayer game

Post by Germanunkol »

miko wrote:
Fenrir wrote:- No dedicated host (at least for the first version), one player will host.
I would implement the server in plain lua+luasocker, using UDP as a protocol, even if your final game will not use the dedicated server (i.e. one of the clients will act as a server). The reason is that it will guarantee logic separation: things will work if you decide later to make a dedicated server, and the "hosting client" will not have an advantage (except for lowest network delay).
I agree for the most part. Using plain Lua will also allow you to host the game on computers without a graphics card (internet server) and is much cleaner. You'll also be framerate-independent etc. But I would not use UDP. The only reason I can see for using UDP is when you're streaming huge amounts of data (VOIP, Webcams, Streaming video). UDP is unreliable, so you can never be sure if the packets arrive or if they are in the right order.
Usually, in a LAN case, the packets will probably arrive in order, but just to make sure, I'd go for TCP. It'll save you a lot of trouble later on, and you'll only have 4 players, so speed should be less of a problem in your LAN/WLAN.
Fenrir wrote: - Should be possible to enter/leave a game at any moment (except for the host, if he leaves the game stops).
This will probably be the most difficult part. I've made a multiplayer game once where it was possible to join at any time and noticed that it made things much more difficult.
One solution (that I didn't use at the time, but should have) would be to have a table called "gameState" on your server, which holds all the necessary information about the current round. Whenever something changes, the change is sent to all players AND written to the table.
Then when a new player arrives, the table is serialized (either fully, or compressed or similar) and sent to the new player. The new player can then reconstruct the current state of the game from this server.

My main advice would be: make a solid multiplayer framework for the game first. Don't get much into gameplay before you have managed to detect and handle issues like:
- joining/leaving of new player
- no response from player (timeout - kick player)
- no response from server (timeout)
Once these work well, you should start to build the gameplay ontop of this. If you do it the other way around (coding player movement before the multiplayer part, for example), you'll most likely have to skip back and forth and change things all the time.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Advices for multiplayer game

Post by ivan »

Fenrir wrote:Pathfinding is already implemented, I was just wondering how to manage it in a server/client architecture.
This turns out to be somewhat complicated especially for games with more than 2 players.
I suggest taking a look at:
https://developer.valvesoftware.com/wik ... Networking
Fenrir wrote:For instance, let's say I compute the IA paths on the server and send it to all clients, it raises to me some questions :
- Should I send the whole path when computed and let the clients apply it without sending back IA positions for validation ?
- Or should I just send the current IA position at each frame without sending the whole path ?
Is there any recommendation on packet size or frequency I should rely on ?
Usually, you want all the computation and game rules to be done on the server in order to prevent cheating.
On the client side, you send all of your input commands to the server and perform "prediction".
Prediction is necessary because you want the clients to APPEAR to move/shoot as soon as they press a button instead of waiting for confirmation from the server.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: Advices for multiplayer game

Post by Fenrir »

I suggest taking a look at:
https://developer.valvesoftware.com/wik ... Networking
Thanks it's exactly what I was looking for, it will probably save me some troubles.
About the protocol, as I'm using Love 0.9.0, I was planning to use the available lua-enet module, it seems to be a good mix between speed and reliability.

After reading Valve's paper, I think I'll go for providing step-by-step data to the clients (and not a complete path for instance). So the first step will be to build a good state database to be able to produce full or partial snapshots of the game state and managing lag compensation (it will be a lot of fun... :/).

Thanks!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 8 guests