Struct RenetServer

Source
pub struct RenetServer { /* private fields */ }

Implementations§

Source§

impl RenetServer

Source

pub fn new(connection_config: ConnectionConfig) -> Self

Source

pub fn add_connection(&mut self, client_id: ClientId)

Adds a new connection to the server. If a connection already exits it does nothing.

Note: This should only be called by the transport layer.

Source

pub fn get_event(&mut self) -> Option<ServerEvent>

Returns a server event if available

§Usage
while let Some(event) = server.get_event() {
    match event {
        ServerEvent::ClientConnected { client_id } => {
            println!("Client {client_id} connected.")
        }
        ServerEvent::ClientDisconnected { client_id, reason } => {
            println!("Client {client_id} disconnected: {reason}");
        }
    }
}
Source

pub fn has_connections(&self) -> bool

Returns whether or not the server has connections

Source

pub fn disconnect_reason(&self, client_id: ClientId) -> Option<DisconnectReason>

Returns the disconnection reason for the client if its disconnected

Source

pub fn rtt(&self, client_id: ClientId) -> f64

Returns the round-time trip for the client or 0.0 if the client is not found

Source

pub fn packet_loss(&self, client_id: ClientId) -> f64

Returns the packet loss for the client or 0.0 if the client is not found

Source

pub fn bytes_sent_per_sec(&self, client_id: ClientId) -> f64

Returns the bytes sent per seconds for the client or 0.0 if the client is not found

Source

pub fn bytes_received_per_sec(&self, client_id: ClientId) -> f64

Returns the bytes received per seconds for the client or 0.0 if the client is not found

Source

pub fn network_info( &self, client_id: ClientId, ) -> Result<NetworkInfo, ClientNotFound>

Returns all network informations for the client

Source

pub fn remove_connection(&mut self, client_id: ClientId)

Removes a connection from the server, emits an disconnect server event. It does nothing if the client does not exits.

Note: This should only be called by the transport layer.

Source

pub fn disconnect(&mut self, client_id: ClientId)

Disconnects a client, it does nothing if the client does not exist.

Source

pub fn disconnect_all(&mut self)

Disconnects all client.

Source

pub fn broadcast_message<I: Into<u8>, B: Into<Bytes>>( &mut self, channel_id: I, message: B, )

Send a message to all clients over a channel.

Source

pub fn broadcast_message_except<I: Into<u8>, B: Into<Bytes>>( &mut self, except_id: ClientId, channel_id: I, message: B, )

Send a message to all clients, except the specified one, over a channel.

Source

pub fn channel_available_memory<I: Into<u8>>( &self, client_id: ClientId, channel_id: I, ) -> usize

Returns the available memory in bytes of a channel for the given client. Returns 0 if the client is not found.

Source

pub fn can_send_message<I: Into<u8>>( &self, client_id: ClientId, channel_id: I, size_bytes: usize, ) -> bool

Checks if can send a message with the given size in bytes over a channel for the given client. Returns false if the client is not found.

Source

pub fn send_message<I: Into<u8>, B: Into<Bytes>>( &mut self, client_id: ClientId, channel_id: I, message: B, )

Send a message to a client over a channel.

Source

pub fn receive_message<I: Into<u8>>( &mut self, client_id: ClientId, channel_id: I, ) -> Option<Bytes>

Receive a message from a client over a channel.

Source

pub fn clients_id_iter(&self) -> impl Iterator<Item = ClientId> + '_

Return ids for all connected clients (iterator)

Source

pub fn clients_id(&self) -> Vec<ClientId>

Return ids for all connected clients

Source

pub fn disconnections_id_iter(&self) -> impl Iterator<Item = ClientId> + '_

Return ids for all disconnected clients (iterator)

Source

pub fn disconnections_id(&self) -> Vec<ClientId>

Return ids for all disconnected clients

Source

pub fn connected_clients(&self) -> usize

Returns the current number of connected clients.

Source

pub fn is_connected(&self, client_id: ClientId) -> bool

Source

pub fn update(&mut self, duration: Duration)

Advances the server by the duration. Should be called every tick

Source

pub fn get_packets_to_send( &mut self, client_id: ClientId, ) -> Result<Vec<Vec<u8>>, ClientNotFound>

Returns a list of packets to be sent to the client.

Note: This should only be called by the transport layer.

Source

pub fn process_packet_from( &mut self, payload: &[u8], client_id: ClientId, ) -> Result<(), ClientNotFound>

Process a packet received from the client.

Note: This should only be called by the transport layer.

Source

pub fn new_local_client(&mut self, client_id: ClientId) -> RenetClient

Creates a local RenetClient, use this for testing. Use Self::process_local_client to update the local connection.

Source

pub fn disconnect_local_client( &mut self, client_id: ClientId, client: &mut RenetClient, )

Disconnects a local RenetClient, created with Self::new_local_client.

Source

pub fn process_local_client( &mut self, client_id: ClientId, client: &mut RenetClient, ) -> Result<(), ClientNotFound>

Given a local RenetClient, receive and send packets to/from it. Use this to update local client created from Self::new_local_client.

Trait Implementations§

Source§

impl Debug for RenetServer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.