Skip to content

Commit

Permalink
RenetNetcode: expose set_max_clients to transport (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedtwo authored Dec 1, 2024
1 parent dae598f commit dd5660d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions renet_netcode/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 renetcode/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,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 dd5660d

Please sign in to comment.