Skip to content
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

RoRnet UDP networking via ENet #143

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

ohlidalp
Copy link
Member

Until now RoRnet protocol worked on top of raw TCP. This worked decently but limited the number of players/vehicles. For a good read on why TCP doesn't make good game networking, see https://gafferongames.com/post/udp_vs_tcp/.

This branch replaces raw TCP with ENet protocol (http://enet.bespin.org/) which works over UDP and provides reliable in-order delivery, so RoRnet can work with it out-of-the-box. At the moment, all communication uses the reliable mode, but in the future we'll make use of the unreliable, too.

To be done:

  • Bundled enet sources should be replaced with system/conan dep management.
  • A client couterpart needs to be finished.

Dumped full .tar.gz download of enet to /dependencies/enet/.
Tested to build and link.
For maximum backwards compatibility, RoRnet version was bumped, SocketW is kept and server still listens for TCP connections on ip/port advertised on master server. Integration with master server is unchanged. Client version check is also unchanged. Only if client version matches, the server instructs the client to reconnect using ENet (using pre-existing unused RoRnet message MSG2_VERSION).

ENet communication is exactly the same as legacy TCP connection, with only one cosmetic detail - server info is sent to client using pre-existing unused RoRnet message MSG2_SERVER_SETTINGS rather than MSG2_HELLO. Server listens for ENet connections on the same IP as TCP and port+1.

This is a prototype done with minimum code changes, for easy understanding. Breakdown:
* listener.cpp (class Listner) - removed all TCP connection handling except version check and master server info query. Compatible clients are instructed to reconnect via ENet.
* dispatcher_enet.h/cpp (class DispatcherENet) - took over all connection handling logic from legacy Listener, except master server integration. Client version is checked again.
* sequencer.h/cpp (class User) - removed TCP socket and send/recv threads (classes Broadcaster, Receiver), deleted "FLOW mode" system ('m_is_receiving_data' flag and `SetReceiveData()` func - related to recv thrad). Added ENetPeer and DispatcherENet. Created function `MessageReceived()` which processes all incoming packets for this user, including intial HELLO.
* receiver.h/cpp (class Receiver) - deleted tcp recv thread, replaced by ENet.
* broadcaster.h/cpp (class Broadcaster) - deleted tcp send thread, replaced by ENet.
* sequencer.h/cpp (class Sequencer) - deleted killer thread and crash statistics, useless with ENet. Deleted "FLOW mode" system (function `enableFlow()` - related to send/recv threads). Function `createClient()` changed to `registerClient()` because the client object is now created early inside DispatcherENet.
* rorserver.cpp - use new DispatcherEnet, keep existing Listener
This was referenced Apr 29, 2022
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.

2 participants