pub struct Host<StepT>{ /* private fields */ }
Expand description
The main host structure managing game logic and client connections.
Host handles the game session, processes client commands, and manages the state of each connection.
§Type Parameters
StepT
: The type representing a step in the game logic. Must implement Clone, Debug, Eq, Deserialize, Serialize, and Display.
Implementations§
Source§impl<StepT> Host<StepT>
impl<StepT> Host<StepT>
Sourcepub fn new(app_version: Version, tick_id: TickId) -> Host<StepT>
pub fn new(app_version: Version, tick_id: TickId) -> Host<StepT>
Creates a new Host instance with the specified application version and initial tick ID.
§Arguments
app_version
- The version of the application.tick_id
- The initial tick identifier.
Sourcepub const fn debug_logic(&self) -> &HostLogic<StepT>
pub const fn debug_logic(&self) -> &HostLogic<StepT>
Returns a reference to the internal HostLogic
for debugging purposes.
Sourcepub fn debug_get_logic(
&self,
connection_id: HostConnectionId,
) -> Option<&Connection<StepT>>
pub fn debug_get_logic( &self, connection_id: HostConnectionId, ) -> Option<&Connection<StepT>>
Retrieves a specific connection’s logic by its connection ID for debugging purposes.
Sourcepub const fn session(&self) -> &GameSession<StepT>
pub const fn session(&self) -> &GameSession<StepT>
Returns a reference to the current game session.
Sourcepub fn update(
&mut self,
connection_id: HostConnectionId,
now: Millis,
datagram: &[u8],
state_provider: &impl GameStateProvider,
) -> Result<Vec<Vec<u8>>, HostError>
pub fn update( &mut self, connection_id: HostConnectionId, now: Millis, datagram: &[u8], state_provider: &impl GameStateProvider, ) -> Result<Vec<Vec<u8>>, HostError>
Updates the host state based on incoming datagrams from a client.
Processes the datagram, updates game logic, and prepares outgoing datagrams to be sent back to the client.
§Arguments
connection_id
- The ID of the connection sending the datagram.now
- The current time in milliseconds.datagram
- The incoming datagram data.state_provider
- A reference to an implementation providing game state if needed.
§Returns
A Result
containing a vector of outgoing datagrams or a HostError
on failure.
§Errors
HostError
TODO:
Sourcepub fn get(&self, connection_id: HostConnectionId) -> Option<&HostConnection>
pub fn get(&self, connection_id: HostConnectionId) -> Option<&HostConnection>
Retrieves a reference to a HostConnection
by its connection ID.
§Arguments
connection_id
- The ID of the connection to retrieve.
Sourcepub fn create_connection(&mut self) -> Option<HostConnectionId>
pub fn create_connection(&mut self) -> Option<HostConnectionId>
Creates a new connection and adds it to the host.
§Returns
An Option
containing the new HostConnectionId
if successful, or None
if the connection could not be created.