Advertisement

Multiplayer concept for LAN based RPG

Started by August 22, 2016 07:32 AM
1 comment, last by hplus0603 8 years, 3 months ago

Hey

for my open world RPG project I'm planing a multiplayer component primary for LAN sessions (but maybe could also run on server in the www) and currently struggling on finding the right protocol and so the right structure of the network code for it. The game is a real time first person RPG where each player will handle his own character and save games on his local maschine so there is no need for any databases or (less) plausibility checks because its not primary a network game but should have the ability to build small parties of 2 to 3 players.

I read the FAQ and know how to setup network environments (udp/ tcp) on different models (peer-to-peer, client/server) but just need some adice arround the topic especialy for my game concept. I have had two different variants in mind:

TCP Server

A central TCP server any player is connecting to (even hosting player) that will handle whole gameplay and tell each client what happened. Pro on here is the facts that I would now when a client disconnects, try to cheat and could handle the whole game safely without double checks. Con would be to handle all gameplay inside the server

UDP hive mind

A de-centralized hive mind concept in what each player knows his own gameplay and tells each other player in the network what he is doing at the moment, what changed ... . Pro on here is that you do not need a huge server just some udp messages telling everyone else current game state. Con is except the fact that cheating may be happen that anything needs to be double checked, does enemy X attacking me and player Y at the same time, who gets loot and what happened in some RPG I played some time ago having different store inventory.

So now my qestion, what do you think about that toppic, which concept would you prefer or have you any other ideas, situations I did not thought about?

The TCP vs UDP issue is irrelevant here.

For such a small number of players they could all connect with each other, so you don't need a server, especially if you think there is little motivation for people to cheat. You will need to consider NAT issues, however.

Advertisement
I think the simplest and most robust option is to elect one of the game instances as "host," and have the other instances connect to that.
The connection can be TCP, or UDP, depending on how bad a "lag spike" will be, compared to how bad a "missed notification" will be.
The benefit of "host a game on LAN" options is that savvy players can then use port forwarding to also host on the Internet on their own, without you having to do any extra work.

To actually "find" the host, you probably want to make the clients and host listen for UDP broadcasts on some known port (remember SO_BROADCAST!)
Typically, when a client looks for hosts, it will broadcast a "are there any hosts" message, and each host on the network will respond with a broadcast.
Additionally, you may want to have servers re-broadcast their state every 5 seconds or so.
The benefit of adding client-query in addition to server-beacon is that the client will, 99% of the time, find the server right away (because of the initial request generating an immediate response.)

You can use UDP discovery with TCP connections, too, as long as you use a consistent TCP port number, and/or the UDP response packet contains the TCP port number to connect to.
You get the actual host address to respond to as the source of the broadcast packet you receive (recvfrom()).
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement