cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
901 stars 115 forks source link

LAN multiplayer #293

Closed cxong closed 8 years ago

cxong commented 10 years ago

As part of #36 and after implementing #37 , we can build simple LAN multiplayer by having clients send commands to the server as if they are input devices. A POC of this has already been done so it should be feasible.

One nice feature to have would be a game browser; clients will search for existing servers on the LAN and the server will reply with details. Instructions for doing this: https://en.wikipedia.org/wiki/Broadcast_address http://lists.cubik.org/pipermail/enet-discuss/2009-August/001230.html

DavidKnight247 commented 10 years ago

For gcw zero it would be great if this was included and compatible with the D-Pad style controller for LAN (and WAN?).

cxong commented 8 years ago

Here's some more details about how to find LAN servers, via UDP broadcast:

http://lists.cubik.org/pipermail/enet-discuss/2009-March/001072.html

Every server binds a UDP info socket (just used for pinging the server) to the same exact port. Game traffic is done on a different port which differs per server, only the info socket is the same port value for all servers. The SO_REUSEADDR option is set on this info socket before the address bind is done, which allows multiple info sockets to live on the same ip address and port. SO_REUSEADDR causes any packets sent to the broadcast address to be delivered to ALL sockets bound to that port. This allows multiple servers to coexist on the same computer and be pinged properly, so long as their game traffic is at least on different ports. The server then replies back with information about which port its actual game traffic is on and other info back to the client that pinged it.