Skip to content

Commit f1e142b

Browse files
committed
Incorporated ENet (reliable UDP protocol)
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
1 parent cf182ea commit f1e142b

File tree

14 files changed

+462
-753
lines changed

14 files changed

+462
-753
lines changed

source/protocol/rornet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace RoRnet {
3030
#define RORNET_LAN_BROADCAST_PORT 13000 //!< port used to send the broadcast announcement in LAN mode
3131
#define RORNET_MAX_USERNAME_LEN 40 //!< port used to send the broadcast announcement in LAN mode
3232

33-
#define RORNET_VERSION "RoRnet_2.45"
33+
#define RORNET_VERSION "RoRnet_2.50"
3434

3535
enum MessageType
3636
{
@@ -44,7 +44,7 @@ enum MessageType
4444
MSG2_WELCOME, //!< we can proceed
4545

4646
// Technical
47-
MSG2_VERSION, //!< server responds with its version
47+
MSG2_VERSION, //!< (repurposed) TCP only; instructs client to reconnect using ENet
4848
MSG2_SERVER_SETTINGS, //!< server send client the terrain name: server_info_t
4949
MSG2_USER_INFO, //!< user data that is sent from the server to the clients
5050
MSG2_MASTERINFO, //!< master information response

source/server/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_executable(${PROJECT_NAME} ${server_src})
55

66
target_include_directories(
77
${PROJECT_NAME} PRIVATE
8+
${CMAKE_SOURCE_DIR}/dependencies/enet/include
89
${CMAKE_SOURCE_DIR}/source/protocol/
910
${CMAKE_SOURCE_DIR}/source/common/
1011
)
@@ -20,10 +21,11 @@ if (RORSERVER_WITH_CURL)
2021
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)
2122
endif ()
2223

23-
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads SocketW::SocketW jsoncpp_lib)
24+
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads SocketW::SocketW jsoncpp_lib enet)
2425

2526
IF (WIN32)
2627
target_compile_definitions(${PROJECT_NAME} PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
28+
target_link_libraries(${PROJECT_NAME} PRIVATE winmm)
2729
ELSEIF (UNIX)
2830
#add_definitions("-DAS_MAX_PORTABILITY")
2931
target_link_libraries(${PROJECT_NAME} PRIVATE dl)

source/server/broadcaster.cpp

Lines changed: 0 additions & 166 deletions
This file was deleted.

source/server/broadcaster.h

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)