Skip to content

Conversation

@JonathSpirit
Copy link
Owner

This pull request introduces several significant changes to the networking components of the project, focusing on refactoring client and server internals, enhancing packet handling, and improving code modularity and clarity. The most notable changes include the introduction of a ClientContext to encapsulate per-client state, updates to the packet caching and reordering mechanisms, and the addition of new network command types and logic. These changes aim to make the networking layer more robust, extensible, and easier to maintain.

Networking Architecture and API Refactoring:

  • Introduced a new ClientContext struct that encapsulates per-client state such as PacketDefragmentation, PacketCache, PacketReorderer, and CommandQueue, and updated ClientList to use this context for each client. This change modularizes client state management and paves the way for cleaner networking logic. [1] [2]
  • Refactored the Client class to move packet cache and reorderer management into the new ClientContext, and changed the acknowledged packets container from a std::vector to a std::unordered_set with a custom hash for efficiency. [1] [2] [3]
  • Updated the ClientList event system: replaced the old ClientListEvent struct with a new Event struct using a strongly-typed enum, and updated all related methods. [1] [2]

Packet Handling Improvements:

  • Enhanced PacketCache with move semantics, a thread mutex for thread safety, and an enable/disable flag to control caching behavior. Added a custom hash function for packet labels to improve lookup performance. [1] [2]
  • Made PacketDefragmentation non-copyable but movable to prevent accidental copies and clarify ownership semantics.

Network Command System Enhancements:

  • Added a new CONNECT_HANDLER network command type and implemented the corresponding NetConnectHandlerCommand class, which manages multi-stage connection and handshake logic, including MTU discovery and (potentially) cryptographic handshakes. Refactored the base NetCommand interface to use void return types and internal state for command results, and updated command classes (NetMTUCommand, NetConnectCommand, NetDisconnectCommand) to be final and use the new interface. [1] [2] [3] [4]

Server and Client Example Updates:

  • Updated the client and server life simulator examples to use the new client context and packet handling APIs, and improved connection logging and authentication status reporting. [1] [2] [3] [4]

Build System Updates:

  • Added new source files (C_netServer.cpp, C_netClient.cpp) to the build system for both the server and client libraries. [1] [2]

These changes collectively improve the maintainability, performance, and extensibility of the networking subsystem.

…etter control it,

ClientList has no more Server only member,
Move out CryptInfo struct (still thinking about moving it again),
add FGE_SERVER_CLIENTS_MAP_GC_DELAY_MS,
remove allowUnknownClient flag as now the default flux will always accept unknown clients and flux never,
rename and make smarter notifyNewClient -> announceNewClient,
fix NetCommandTypes,
remove unnecessary callback _onClientMTUDiscovered,
remove unused checkCommands() private method,
re-implement missing _onClientConnected call
move ClientListEvent in ClientList,
free a bit Client class from complexity
- in order to know if we already send this event
@JonathSpirit JonathSpirit added this to the v0.9.5 milestone Dec 15, 2025
@JonathSpirit JonathSpirit self-assigned this Dec 15, 2025
- this avoid code duplication and allow a new loopbackReturnPacket() method
@JonathSpirit JonathSpirit merged commit a6d20b5 into master Dec 16, 2025
4 of 5 checks passed
@JonathSpirit JonathSpirit deleted the netPolishing branch December 16, 2025 14:23
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