Trait valence::prelude::NetworkCallbacks
source · pub trait NetworkCallbacks:
Send
+ Sync
+ 'static {
// Provided methods
fn server_list_ping<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
remote_addr: SocketAddr,
handshake_data: &'life2 HandshakeData,
) -> Pin<Box<dyn Future<Output = ServerListPing<'life0>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn server_list_legacy_ping<'life0, 'life1, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
remote_addr: SocketAddr,
payload: ServerListLegacyPingPayload,
) -> Pin<Box<dyn Future<Output = ServerListLegacyPing> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn broadcast_to_lan<'life0, 'life1, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
) -> Pin<Box<dyn Future<Output = BroadcastToLan<'life0>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn login<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
info: &'life2 NewClientInfo,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn FnOnce() + Sync + Send>, Text>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn session_server<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
username: &'life2 str,
auth_digest: &'life3 str,
player_ip: &'life4 IpAddr,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait { ... }
}
Expand description
This trait uses async_trait
.
Provided Methods§
sourcefn server_list_ping<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
remote_addr: SocketAddr,
handshake_data: &'life2 HandshakeData,
) -> Pin<Box<dyn Future<Output = ServerListPing<'life0>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn server_list_ping<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
remote_addr: SocketAddr,
handshake_data: &'life2 HandshakeData,
) -> Pin<Box<dyn Future<Output = ServerListPing<'life0>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Called when the server receives a Server List Ping query. Data for the response can be provided or the query can be ignored.
This function is called from within a tokio runtime.
§Default Implementation
A default placeholder response is returned.
sourcefn server_list_legacy_ping<'life0, 'life1, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
remote_addr: SocketAddr,
payload: ServerListLegacyPingPayload,
) -> Pin<Box<dyn Future<Output = ServerListLegacyPing> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn server_list_legacy_ping<'life0, 'life1, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
remote_addr: SocketAddr,
payload: ServerListLegacyPingPayload,
) -> Pin<Box<dyn Future<Output = ServerListLegacyPing> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Called when the server receives a Server List Legacy Ping query. Data for the response can be provided or the query can be ignored.
This function is called from within a tokio runtime.
§Default Implementation
server_list_ping
re-used.
sourcefn broadcast_to_lan<'life0, 'life1, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
) -> Pin<Box<dyn Future<Output = BroadcastToLan<'life0>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn broadcast_to_lan<'life0, 'life1, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
) -> Pin<Box<dyn Future<Output = BroadcastToLan<'life0>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
This function is called every 1.5 seconds to broadcast a packet over the local network in order to advertise the server to the multiplayer screen with a configurable MOTD.
§Default Implementation
The default implementation returns BroadcastToLan::Disabled
,
disabling LAN discovery.
sourcefn login<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
info: &'life2 NewClientInfo,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn FnOnce() + Sync + Send>, Text>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn login<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
info: &'life2 NewClientInfo,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn FnOnce() + Sync + Send>, Text>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Called for each client (after successful authentication if online mode is enabled) to determine if they can join the server.
-
If
Err(reason)
is returned, then the client is immediately disconnected withreason
as the displayed message. -
Otherwise,
Ok(f)
is returned and the client will continue the login process. This may result in a new client being spawned with theClientBundle
components.f
is stored along with the client and is called when the client is disconnected.f
is a callback function used for handling resource cleanup when the client is dropped. This is useful because a new client entity is not necessarily spawned into the world after a successful login.
This method is called from within a tokio runtime, and is the appropriate place to perform asynchronous operations such as database queries which may take some time to complete.
§Default Implementation
TODO
sourcefn session_server<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
username: &'life2 str,
auth_digest: &'life3 str,
player_ip: &'life4 IpAddr,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
fn session_server<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
shared: &'life1 SharedNetworkState,
username: &'life2 str,
auth_digest: &'life3 str,
player_ip: &'life4 IpAddr,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
Called upon every client login to obtain the full URL to use for session server requests. This is done to authenticate player accounts. This method is not called unless online mode is enabled.
It is assumed that upon successful request, a structure matching the description in the wiki was obtained. Providing a URL that does not return such a structure will result in a disconnect for every client that connects.
The arguments are described in the linked wiki article.
§Default Implementation
Uses the official Minecraft session server. This is formatted as
https://sessionserver.mojang.com/session/minecraft/hasJoined?username=<username>&serverId=<auth-digest>&ip=<player-ip>
.
Implementations on Foreign Types§
impl NetworkCallbacks for ()
The default network callbacks. Useful as a placeholder.