[−][src]Struct naia_server::NaiaServer
A server that uses either UDP or WebRTC communication to send/receive events to/from connected clients, and syncs registered actors to clients to whom those actors are in-scope
Implementations
impl<T: EventType, U: ActorType> NaiaServer<T, U>
[src]
pub async fn new(
address: SocketAddr,
manifest: Manifest<T, U>,
server_config: Option<ServerConfig>,
shared_config: SharedConfig
) -> Self
[src]
address: SocketAddr,
manifest: Manifest<T, U>,
server_config: Option<ServerConfig>,
shared_config: SharedConfig
) -> Self
Create a new Server, given an address to listen at, an Event/Actor manifest, and an optional Config
pub async fn receive<'_>(
&'_ mut self
) -> Result<ServerEvent<T>, NaiaServerError>
[src]
&'_ mut self
) -> Result<ServerEvent<T>, NaiaServerError>
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 Actor/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_actor(&mut self, actor: U) -> ActorKey
[src]
Register an Actor with the Server, whereby the Server will sync the state of the Actor to all connected Clients for which the Actor is in scope. Gives back an ActorKey which can be used to get the reference to the Actor from the Server once again
pub fn deregister_actor(&mut self, key: ActorKey)
[src]
Deregisters an Actor with the Server, deleting local copies of the Actor on each Client
pub fn get_actor(&mut self, key: ActorKey) -> Option<&U>
[src]
Given an ActorKey, get a reference to a registered Actor being tracked by the Server
pub fn actors_iter(&self) -> Iter<'_, ActorKey, U>
[src]
Iterate through all the Server's Actors
pub fn get_actors_count(&self) -> usize
[src]
Get the number of Actors 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 get_rooms_count(&self) -> usize
[src]
Get the number of Rooms in the Server
pub fn room_add_actor(&mut self, room_key: &RoomKey, actor_key: &ActorKey)
[src]
Add an Actor to a Room, given the appropriate RoomKey & ActorKey Actors will only ever be in-scope for Users which are in a Room with them
pub fn room_remove_actor(&mut self, room_key: &RoomKey, actor_key: &ActorKey)
[src]
Remove an Actor from a Room, given the appropriate RoomKey & ActorKey
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 Actors will only ever be in-scope for Users which are in a Room with them
pub fn room_remove_user(&mut self, room_key: &RoomKey, user_key: &UserKey)
[src]
Removes a User from a Room
pub fn on_scope_actor(
&mut self,
scope_func: Rc<Box<dyn Fn(&RoomKey, &UserKey, &ActorKey, U) -> bool>>
)
[src]
&mut self,
scope_func: Rc<Box<dyn Fn(&RoomKey, &UserKey, &ActorKey, U) -> bool>>
)
Registers a closure which is used to evaluate whether, given a User & Actor that are in the same Room, said Actor should be in scope for the given User.
While Rooms allow for a very simple scope to which an Actor can belong, this closure provides complete customization for advanced scopes.
This closure will be called every Tick of the Server, for every User & Actor 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 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
pub fn get_users_count(&self) -> usize
[src]
Get the number of Users currently connected
pub fn get_client_tick(&self, user_key: &UserKey) -> Option<u16>
[src]
Gets the last received tick from the Client
pub fn get_server_tick(&self) -> u16
[src]
Gets the current tick of the Server
pub fn assign_pawn(&mut self, user_key: &UserKey, actor_key: &ActorKey)
[src]
Assigns an Actor to a specific User, making it a Pawn for that User (meaning that the User will be able to issue Commands to that Pawn)
pub fn unassign_pawn(&mut self, user_key: &UserKey, actor_key: &ActorKey)
[src]
Unassigns a Pawn from a specific User (meaning that the User will be unable to issue Commands to that Pawn)
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,
U: Unpin,
T: Unpin,
U: Unpin,
impl<T, U> !UnwindSafe for NaiaServer<T, U>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,