[][src]Struct naia_server::NaiaServer

pub struct NaiaServer<T: EventType, U: EntityType> { /* fields omitted */ }

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

Implementations

impl<T: EventType, U: EntityType> NaiaServer<T, U>[src]

pub async fn new(
    address: SocketAddr,
    manifest: Manifest<T, U>,
    config: Option<Config>
) -> Self
[src]

Create a new Server, given an address to listen at, an Event/Entity manifest, and an optional Config

pub async fn receive<'_>(
    &'_ mut self
) -> Result<ServerEvent<T>, NaiaServerError>
[src]

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

pub fn queue_event(&mut self, user_key: &UserKey, event: &impl Event<T>)[src]

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

pub async fn send_all_updates<'_>(&'_ mut self)[src]

Sends all Entity/Event messages to all Clients. If you don't call this method, the Server will never communicate with it's connected Clients

pub fn register_entity(
    &mut self,
    entity: Rc<RefCell<dyn Entity<U>>>
) -> EntityKey
[src]

Register an Entity with the Server, whereby the Server will sync the state of the Entity to all connected Clients for which the Entity is in scope. Gives back an EntityKey which can be used to get the reference to the Entity from the Server once again

pub fn deregister_entity(&mut self, key: EntityKey)[src]

Deregisters an Entity with the Server, deleting local copies of the Entity on each Client

pub fn get_entity(
    &mut self,
    key: EntityKey
) -> Option<&Rc<RefCell<dyn Entity<U>>>>
[src]

Given an EntityKey, get a reference to a registered Entity being tracked by the Server

pub fn create_room(&mut self) -> RoomKey[src]

Creates a new Room on the Server, returns a Key which can be used to reference said Room

pub fn delete_room(&mut self, key: RoomKey)[src]

Deletes the Room associated with a given RoomKey on the Server

pub fn get_room(&self, key: RoomKey) -> Option<&Room>[src]

Gets a Room given an associated RoomKey

pub fn get_room_mut(&mut self, key: RoomKey) -> Option<&mut Room>[src]

Gets a mutable Room given an associated RoomKey

pub fn rooms_iter(&self) -> Iter<RoomKey, Room>[src]

Iterate through all the Server's current Rooms

pub fn room_add_entity(&mut self, room_key: &RoomKey, entity_key: &EntityKey)[src]

Add an Entity to a Room, given the appropriate RoomKey & EntityKey Entities will only ever be in-scope for Users which are in a Room with them

pub fn room_add_user(&mut self, room_key: &RoomKey, user_key: &UserKey)[src]

Add an User to a Room, given the appropriate RoomKey & UserKey Entities will only ever be in-scope for Users which are in a Room with them

pub fn on_scope_entity(
    &mut self,
    scope_func: Rc<Box<dyn Fn(&RoomKey, &UserKey, &EntityKey, U) -> bool>>
)
[src]

Registers a closure which is 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 closure provides complete customization for advanced scopes.

This closure will be called every Tick of the Server, for every User & Entity in a Room together, so try to keep it performant

pub fn on_auth(&mut self, auth_func: Rc<Box<dyn Fn(&UserKey, &T) -> bool>>)[src]

Registers a closure which will be called during the handshake process with a new Client

The Event evaluated in this closure should match the Event used client-side in the NaiaClient::new() method

pub fn get_rtt(&mut self, user_key: &UserKey) -> Option<f32>[src]

Get the current measured Round Trip Time to the Server

pub fn users_iter(&self) -> Iter<UserKey, User>[src]

Iterate through all currently connected Users

pub fn get_user(&self, user_key: &UserKey) -> Option<&User>[src]

Get a User, given the associated UserKey

Auto Trait Implementations

impl<T, U> !RefUnwindSafe for NaiaServer<T, U>

impl<T, U> !Send for NaiaServer<T, U>

impl<T, U> !Sync for NaiaServer<T, U>

impl<T, U> Unpin for NaiaServer<T, U> where
    T: Unpin

impl<T, U> !UnwindSafe for NaiaServer<T, U>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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