Skip to content

Commit

Permalink
expose set_max_clients to transport; see renet lucaspoffo#164
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB committed Dec 22, 2024
1 parent 2893a16 commit 7c32630
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions renet2_netcode/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ impl NetcodeServerTransport {
self.netcode_server.max_clients()
}

/// Update the maximum numbers of clients that can be connected.
///
/// Changing the `max_clients` to a lower value than the current number of connect clients
/// does not disconnect clients. So [`NetcodeServerTransport::connected_clients()`] can
/// return a higher value than [`NetcodeServerTransport::max_clients()`].
pub fn set_max_clients(&mut self, max_clients: usize) {
self.netcode_server.set_max_clients(max_clients);
}

/// Returns current number of clients connected.
pub fn connected_clients(&self) -> usize {
self.netcode_server.connected_clients()
Expand Down
6 changes: 5 additions & 1 deletion renetcode2/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,12 @@ impl NetcodeServer {
/// Update the maximum numbers of clients that can be connected
///
/// Changing the `max_clients` to a lower value than the current number of connect clients
/// does not disconnect clients. So [`NetcodeServer::connected_clients()`] can return a higher value than [`NetcodeServer::max_clients()`].
/// does not disconnect clients. So [`NetcodeServer::connected_clients()`] can return a
/// higher value than [`NetcodeServer::max_clients()`].
pub fn set_max_clients(&mut self, max_clients: usize) {
let max_clients = max_clients.min(NETCODE_MAX_CLIENTS);
log::debug!("Netcode max_clients set to {}", max_clients);

self.max_clients = max_clients;
}

Expand Down

0 comments on commit 7c32630

Please sign in to comment.