Struct naia_server::Server
source · [−]pub struct Server<P: ProtocolType, E: Copy + Eq + Hash> { /* 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
Create a new Server
Listen at the given addresses
Must be called regularly, maintains connection to and receives messages from all Clients
Accepts an incoming Client User, allowing them to establish a connection with the Server
Rejects an incoming Client User, terminating their attempt to establish a connection with the Server
pub fn send_message<R: ReplicateSafe<P>>(
&mut self,
user_key: &UserKey,
message: &R,
guaranteed_delivery: bool
)
pub fn send_message<R: ReplicateSafe<P>>(
&mut self,
user_key: &UserKey,
message: &R,
guaranteed_delivery: bool
)
Queues up an Message to be sent to the Client associated with a given UserKey
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
Sends all update messages to all Clients. If you don’t call this method, the Server will never communicate with it’s connected Clients
pub fn spawn_entity<'s, W: WorldMutType<P, E>>(
&'s mut self,
world: W
) -> EntityMut<'s, P, E, W>
pub fn spawn_entity<'s, W: WorldMutType<P, E>>(
&'s mut self,
world: W
) -> EntityMut<'s, P, E, W>
Creates a new Entity and returns an EntityMut which can be used for further operations on the Entity
Creates a new Entity with a specific id
pub fn entity<'s, W: WorldRefType<P, E>>(
&'s self,
world: W,
entity: &E
) -> EntityRef<'s, P, E, W>
pub fn entity<'s, W: WorldRefType<P, E>>(
&'s self,
world: W,
entity: &E
) -> EntityRef<'s, P, E, W>
Retrieves an EntityRef that exposes read-only operations for the Entity. Panics if the Entity does not exist.
pub fn entity_mut<'s, 'w, W: WorldMutType<P, E>>(
&'s mut self,
world: W,
entity: &E
) -> EntityMut<'s, P, E, W>
pub fn entity_mut<'s, 'w, W: WorldMutType<P, E>>(
&'s mut self,
world: W,
entity: &E
) -> EntityMut<'s, P, E, W>
Retrieves an EntityMut that exposes read and write operations for the Entity. Panics if the Entity does not exist.
Retrieves a WorldlessEntityMut that exposes read and write operations on the Entity, but with no references allowed to the World. This is a very niche use case. Panics if the Entity does not exist.
Gets a Vec of all Entities in the given World
Returns whether or not a User exists for the given RoomKey
Retrieves an UserRef that exposes read-only operations for the User associated with the given UserKey. Panics if the user does not exist.
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.
Return a list of all currently connected Users’ keys
Get the number of Users currently connected
Returns a UserScopeMut, which is used to include/exclude Entities for a given User
Returns whether a given User has a particular Entity in-scope currently
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
Returns whether or not a Room exists for the given RoomKey
Retrieves an RoomMut that exposes read and write operations for the Room associated with the given RoomKey. Panics if the room does not exist.
Retrieves an RoomMut that exposes read and write operations for the Room associated with the given RoomKey. Panics if the room does not exist.
Return a list of all the Server’s Rooms’ keys
Get a count of how many Rooms currently exist
Gets the last received tick from the Client
Gets the current tick of the Server