Skip to content

P2P LAN online multiplayer using UDP #3285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ist1106037
Copy link
Contributor

We have implemented a P2P connection over LAN using UDP to enable online multiplayer functionality in SuperTux. This feature allows multiple players to connect directly to each other without requiring a central server.

To do this we added some variables to the Config, added a new Controller that serves as a dummy for the online handling of the character, added a new menu, a new class for ip management and another for sending and receiving messages.

This messages use the UDP protocol and threads to make a peer to peer connection for the handling of the LAN communication.

We only did LAN communication as other types of communication would require a server and this would require money or other resourses that we dont think the suppertux community wants, although there is a way to use this program for true online multiplayer, all it takes is putting the public ip of the host and both who is joining and who is hosting need to forward their routters to their computers.

To access online multiplayer you have to go to the multiplayer menu where the new option is added, then just host and another person writes your ip as join and you're ready to play together.

We have implemented a P2P connection over LAN using UDP to enable
online multiplayer functionality in SuperTux. This feature allows
multiple players to connect directly to each other without requiring a
central server.

To do this we added some variables to the Config, added a new
Controller that serves as a dummy for the online handling of the
character, added a new menu, a new class for ip management and another
for sending and receiving messages.

This messages use the UDP protocol and threads to make a peer to peer
connection for the handling of the LAN communication.

We only did LAN communication as other types of communication would
require a server and this would require money or other resourses that
we dont think the suppertux community wants, although there is a way to
use this program for true online multiplayer, all it takes is putting
the public ip of the host and both who is joining and who is hosting
need to forward their routters to their computers.

To access online multiplayer you have to go to the multiplayer menu
where the new option is added, then just host and another person
writes your ip as join and you're ready to play together.

Co-authored-by: Gonçalo Rocha <goncalo.r.f.rocha@tecnico.ulisboa.pt>
@tobbi
Copy link
Member

tobbi commented Jun 17, 2025

Please fix the initialization order:

/home/runner/work/supertux/supertux/src/supertux/gameconfig.cpp:119:3: error: field 'level' will be initialized after field 'multiplayer_buzz_controllers' [-Werror,-Wreorder-ctor]

@tobbi
Copy link
Member

tobbi commented Jun 17, 2025

One more thing:

2025-06-17T14:35:06.9490474Z D:\a\supertux\supertux\src\supertux\online_session_manager.hpp(26,10): error C1083: Cannot open include file: 'netinet/in.h': No such file or directory [D:\a\supertux\supertux\build\supertux2_lib.vcxproj]

It appears that that include file isn't available on Windows. Are there any dependencies that might need to get installed?

@swagtoy
Copy link
Contributor

swagtoy commented Jun 18, 2025

You should consider binary serializing the data. String serializing is fine, however binary serializing is easier to work with in the future and more compact. Consider using something like ENet which Vankata used in the editor-remote-level-networking branch, which could prevent very rare desyncs (though probably not a big deal). In fact, better error handling overall using dialogs would be nice.

Also use the logger instead of std::cerr please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants