Struct naia_server::Server
source · [−]pub struct Server<P: Protocolize, E: Copy + Eq + Hash + Send + Sync, C: ChannelIndex> { /* 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
sourceimpl<P: Protocolize, E: Copy + Eq + Hash + Send + Sync, C: ChannelIndex> Server<P, E, C>
impl<P: Protocolize, E: Copy + Eq + Hash + Send + Sync, C: ChannelIndex> Server<P, E, C>
sourcepub fn new(server_config: &ServerConfig, shared_config: &SharedConfig<C>) -> Self
pub fn new(server_config: &ServerConfig, shared_config: &SharedConfig<C>) -> Self
Create a new Server
sourcepub fn listen(&mut self, server_addrs: &ServerAddrs)
pub fn listen(&mut self, server_addrs: &ServerAddrs)
Listen at the given addresses
sourcepub fn is_listening(&self) -> bool
pub fn is_listening(&self) -> bool
Returns whether or not the Server has initialized correctly and is listening for Clients
sourcepub fn receive(&mut self) -> VecDeque<Result<Event<P, C>, NaiaServerError>>
pub fn receive(&mut self) -> VecDeque<Result<Event<P, C>, NaiaServerError>>
Must be called regularly, maintains connection to and receives messages from all Clients
sourcepub fn accept_connection(&mut self, user_key: &UserKey)
pub fn accept_connection(&mut self, user_key: &UserKey)
Accepts an incoming Client User, allowing them to establish a connection with the Server
sourcepub fn reject_connection(&mut self, user_key: &UserKey)
pub fn reject_connection(&mut self, user_key: &UserKey)
Rejects an incoming Client User, terminating their attempt to establish a connection with the Server
sourcepub fn send_message<R: ReplicateSafe<P>>(
&mut self,
user_key: &UserKey,
channel: C,
message: &R
)
pub fn send_message<R: ReplicateSafe<P>>(
&mut self,
user_key: &UserKey,
channel: C,
message: &R
)
Queues up an Message to be sent to the Client associated with a given UserKey
sourcepub fn scope_checks(&self) -> Vec<(RoomKey, UserKey, E)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn scope_checks(&self) -> Vec<(RoomKey, UserKey, E)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
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
sourcepub fn send_all_updates<W: WorldRefType<P, E>>(&mut self, world: W)
pub fn send_all_updates<W: WorldRefType<P, E>>(&mut self, world: W)
Sends all update messages to all Clients. If you don’t call this method, the Server will never communicate with it’s connected Clients
sourcepub fn spawn_entity<W: WorldMutType<P, E>>(
&mut self,
world: W
) -> EntityMut<'_, P, E, W, C>
pub fn spawn_entity<W: WorldMutType<P, E>>(
&mut self,
world: W
) -> EntityMut<'_, P, E, W, C>
Creates a new Entity and returns an EntityMut which can be used for further operations on the Entity
sourcepub fn spawn_entity_at(&mut self, entity: &E)
pub fn spawn_entity_at(&mut self, entity: &E)
Creates a new Entity with a specific id
sourcepub fn entity<W: WorldRefType<P, E>>(
&self,
world: W,
entity: &E
) -> EntityRef<P, E, W>
pub fn entity<W: WorldRefType<P, E>>(
&self,
world: W,
entity: &E
) -> EntityRef<P, E, W>
Retrieves an EntityRef that exposes read-only operations for the Entity. Panics if the Entity does not exist.
sourcepub fn entity_mut<W: WorldMutType<P, E>>(
&mut self,
world: W,
entity: &E
) -> EntityMut<'_, P, E, W, C>
pub fn entity_mut<W: WorldMutType<P, E>>(
&mut self,
world: W,
entity: &E
) -> EntityMut<'_, P, E, W, C>
Retrieves an EntityMut that exposes read and write operations for the Entity. Panics if the Entity does not exist.
sourcepub fn entities<W: WorldRefType<P, E>>(&self, world: W) -> Vec<E>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn entities<W: WorldRefType<P, E>>(&self, world: W) -> Vec<E>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Gets a Vec of all Entities in the given World
sourcepub fn user_exists(&self, user_key: &UserKey) -> bool
pub fn user_exists(&self, user_key: &UserKey) -> bool
Returns whether or not a User exists for the given RoomKey
sourcepub fn user(&self, user_key: &UserKey) -> UserRef<'_, P, E, C>
pub fn user(&self, user_key: &UserKey) -> UserRef<'_, P, E, C>
Retrieves an UserRef that exposes read-only operations for the User associated with the given UserKey. Panics if the user does not exist.
sourcepub fn user_mut(&mut self, user_key: &UserKey) -> UserMut<'_, P, E, C>
pub fn user_mut(&mut self, user_key: &UserKey) -> UserMut<'_, P, E, C>
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.
sourcepub fn user_keys(&self) -> Vec<UserKey>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn user_keys(&self) -> Vec<UserKey>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Return a list of all currently connected Users’ keys
sourcepub fn users_count(&self) -> usize
pub fn users_count(&self) -> usize
Get the number of Users currently connected
sourcepub fn user_scope(&mut self, user_key: &UserKey) -> UserScopeMut<'_, P, E, C>
pub fn user_scope(&mut self, user_key: &UserKey) -> UserScopeMut<'_, P, E, C>
Returns a UserScopeMut, which is used to include/exclude Entities for a given User
sourcepub fn make_room(&mut self) -> RoomMut<'_, P, E, C>
pub fn make_room(&mut self) -> RoomMut<'_, P, E, C>
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
sourcepub fn room_exists(&self, room_key: &RoomKey) -> bool
pub fn room_exists(&self, room_key: &RoomKey) -> bool
Returns whether or not a Room exists for the given RoomKey
sourcepub fn room(&self, room_key: &RoomKey) -> RoomRef<'_, P, E, C>
pub fn room(&self, room_key: &RoomKey) -> RoomRef<'_, P, E, C>
Retrieves an RoomMut that exposes read and write operations for the Room associated with the given RoomKey. Panics if the room does not exist.
sourcepub fn room_mut(&mut self, room_key: &RoomKey) -> RoomMut<'_, P, E, C>
pub fn room_mut(&mut self, room_key: &RoomKey) -> RoomMut<'_, P, E, C>
Retrieves an RoomMut that exposes read and write operations for the Room associated with the given RoomKey. Panics if the room does not exist.
sourcepub fn room_keys(&self) -> Vec<RoomKey>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn room_keys(&self) -> Vec<RoomKey>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Return a list of all the Server’s Rooms’ keys
sourcepub fn rooms_count(&self) -> usize
pub fn rooms_count(&self) -> usize
Get a count of how many Rooms currently exist
sourcepub fn client_tick(&self, user_key: &UserKey) -> Option<Tick>
pub fn client_tick(&self, user_key: &UserKey) -> Option<Tick>
Gets the last received tick from the Client
sourcepub fn server_tick(&self) -> Option<Tick>
pub fn server_tick(&self) -> Option<Tick>
Gets the current tick of the Server