pub struct Server<E>where
    E: Copy + Eq + Hash + Send + Sync,{ /* private fields */ }
Expand description

A server that uses either UDP or WebRTC communication to send/receive messages to/from connected clients, and syncs registered entities to clients to whom they are in-scope

Implementations§

source§

impl<E> Server<E>where E: Copy + Eq + Hash + Send + Sync,

source

pub fn new<P>(server_config: ServerConfig, protocol: P) -> Server<E>where P: Into<Protocol>,

Create a new Server

source

pub fn listen<S>(&mut self, socket: S)where S: Into<Box<dyn Socket + 'static, Global>>,

Listen at the given addresses

source

pub fn is_listening(&self) -> bool

Returns whether or not the Server has initialized correctly and is listening for Clients

source

pub fn socket_config(&self) -> &SocketConfig

Returns socket config

source

pub fn receive<W>(&mut self, world: W) -> Events<E>where W: WorldMutType<E>,

Must be called regularly, maintains connection to and receives messages from all Clients

source

pub fn accept_connection(&mut self, user_key: &UserKey)

Accepts an incoming Client User, allowing them to establish a connection with the Server

source

pub fn reject_connection(&mut self, user_key: &UserKey)

Rejects an incoming Client User, terminating their attempt to establish a connection with the Server

source

pub fn send_message<C, M>(&mut self, user_key: &UserKey, message: &M)where C: Channel, M: Message,

Queues up an Message to be sent to the Client associated with a given UserKey

source

pub fn broadcast_message<C, M>(&mut self, message: &M)where C: Channel, M: Message,

Sends a message to all connected users using a given channel

source

pub fn receive_tick_buffer_messages(&mut self, tick: &u16) -> TickBufferMessages

source

pub fn scope_checks(&self) -> Vec<(RoomKey, UserKey, E), Global>

Used to evaluate whether, given a User & Entity that are in the same Room, said Entity should be in scope for the given User.

While Rooms allow for a very simple scope to which an Entity can belong, this provides complete customization for advanced scopes.

Return a collection of Entity Scope Sets, being a unique combination of a related Room, User, and Entity, used to determine which Entities to replicate to which Users

source

pub fn send_all_updates<W>(&mut self, world: W)where W: WorldRefType<E>,

Sends all update messages to all Clients. If you don’t call this method, the Server will never communicate with it’s connected Clients

source

pub fn enable_replication(&mut self, entity: &E)

source

pub fn disable_replication(&mut self, entity: &E)

source

pub fn spawn_entity<W>(&mut self, world: W) -> EntityMut<'_, E, W>where W: WorldMutType<E>,

Creates a new Entity and returns an EntityMut which can be used for further operations on the Entity

source

pub fn spawn_entity_at(&mut self, entity: &E)

Creates a new Entity with a specific id

source

pub fn entity<W>(&self, world: W, entity: &E) -> EntityRef<E, W>where W: WorldRefType<E>,

Retrieves an EntityRef that exposes read-only operations for the Entity. Panics if the Entity does not exist.

source

pub fn entity_mut<W>(&mut self, world: W, entity: &E) -> EntityMut<'_, E, W>where W: WorldMutType<E>,

Retrieves an EntityMut that exposes read and write operations for the Entity. Panics if the Entity does not exist.

source

pub fn entities<W>(&self, world: W) -> Vec<E, Global>where W: WorldRefType<E>,

Gets a Vec of all Entities in the given World

source

pub fn entity_owner(&self, entity: &E) -> EntityOwner

source

pub fn user_exists(&self, user_key: &UserKey) -> bool

Returns whether or not a User exists for the given RoomKey

source

pub fn user(&self, user_key: &UserKey) -> UserRef<'_, E>

Retrieves an UserRef that exposes read-only operations for the User associated with the given UserKey. Panics if the user does not exist.

source

pub fn user_mut(&mut self, user_key: &UserKey) -> UserMut<'_, E>

Retrieves an UserMut that exposes read and write operations for the User associated with the given UserKey. Returns None if the user does not exist.

source

pub fn user_keys(&self) -> Vec<UserKey, Global>

Return a list of all currently connected Users’ keys

source

pub fn users_count(&self) -> usize

Get the number of Users currently connected

source

pub fn user_scope(&mut self, user_key: &UserKey) -> UserScopeMut<'_, E>

Returns a UserScopeMut, which is used to include/exclude Entities for a given User

source

pub fn make_room(&mut self) -> RoomMut<'_, E>

Creates a new Room on the Server and returns a corresponding RoomMut, which can be used to add users/entities to the room or retrieve its key

source

pub fn room_exists(&self, room_key: &RoomKey) -> bool

Returns whether or not a Room exists for the given RoomKey

source

pub fn room(&self, room_key: &RoomKey) -> RoomRef<'_, E>

Retrieves an RoomMut that exposes read and write operations for the Room associated with the given RoomKey. Panics if the room does not exist.

source

pub fn room_mut(&mut self, room_key: &RoomKey) -> RoomMut<'_, E>

Retrieves an RoomMut that exposes read and write operations for the Room associated with the given RoomKey. Panics if the room does not exist.

source

pub fn room_keys(&self) -> Vec<RoomKey, Global>

Return a list of all the Server’s Rooms’ keys

source

pub fn rooms_count(&self) -> usize

Get a count of how many Rooms currently exist

source

pub fn current_tick(&self) -> u16

Gets the current tick of the Server

source

pub fn average_tick_duration(&self) -> Duration

Gets the current average tick duration of the Server

source

pub fn outgoing_bandwidth_total(&mut self) -> f32

source

pub fn incoming_bandwidth_total(&mut self) -> f32

source

pub fn outgoing_bandwidth_to_client(&mut self, address: &SocketAddr) -> f32

source

pub fn incoming_bandwidth_from_client(&mut self, address: &SocketAddr) -> f32

source

pub fn rtt(&self, user_key: &UserKey) -> Option<f32>

Gets the average Round Trip Time measured to the given User’s Client

source

pub fn jitter(&self, user_key: &UserKey) -> Option<f32>

Gets the average Jitter measured in connection to the given User’s Client

source

pub fn despawn_entity_worldless(&mut self, entity: &E)

source

pub fn insert_component_worldless( &mut self, entity: &E, component: &mut (dyn Replicate + 'static) )

source

pub fn remove_component_worldless( &mut self, entity: &E, component_kind: &ComponentKind )

Trait Implementations§

source§

impl<E> EntityAndGlobalEntityConverter<E> for Server<E>where E: Copy + Eq + Hash + Send + Sync,

source§

fn global_entity_to_entity( &self, global_entity: &GlobalEntity ) -> Result<E, EntityDoesNotExistError>

source§

fn entity_to_global_entity( &self, entity: &E ) -> Result<GlobalEntity, EntityDoesNotExistError>

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for Server<E>

§

impl<E> Send for Server<E>

§

impl<E> Sync for Server<E>

§

impl<E> Unpin for Server<E>where E: Unpin,

§

impl<E> !UnwindSafe for Server<E>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Component for Twhere T: Send + Sync + 'static,