Skip to content

Commit

Permalink
Renet: add methods to return client addr from server/client
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspoffo committed Jul 14, 2023
1 parent 08f1d95 commit 1ce104b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions renet/src/transport/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl NetcodeClientTransport {
})
}

pub fn addr(&self) -> io::Result<SocketAddr> {
self.socket.local_addr()
}

pub fn client_id(&self) -> u64 {
self.netcode_client.client_id()
}
Expand Down
9 changes: 9 additions & 0 deletions renet/src/transport/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,31 @@ impl NetcodeServerTransport {
})
}

/// Returns the server public address
pub fn addr(&self) -> SocketAddr {
self.netcode_server.address()
}

/// Returns the maximum number of clients that can be connected.
pub fn max_clients(&self) -> usize {
self.netcode_server.max_clients()
}

/// Returns current number of clients connected.
pub fn connected_clients(&self) -> usize {
self.netcode_server.connected_clients()
}

/// Returns the user data for client if connected.
pub fn user_data(&self, client_id: u64) -> Option<[u8; NETCODE_USER_DATA_BYTES]> {
self.netcode_server.user_data(client_id)
}

/// Returns the client address if connected.
pub fn client_addr(&self, client_id: u64) -> Option<SocketAddr> {
self.netcode_server.client_addr(client_id)
}

/// Disconnects all connected clients.
/// This sends the disconnect packet instantly, use this when closing/exiting games,
/// should use [RenetServer::disconnect_all][crate::RenetServer::disconnect_all] otherwise.
Expand Down
2 changes: 1 addition & 1 deletion renetcode/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl NetcodeServer {
self.max_clients
}

/// Returns the maximum number of clients that can be connected.
/// Returns current number of clients connected.
pub fn connected_clients(&self) -> usize {
self.clients.iter().filter(|slot| slot.is_some()).count()
}
Expand Down

0 comments on commit 1ce104b

Please sign in to comment.