flatland_client_lib/
session.rs1use flatland_protocol::{
4 ChatMessage, EntityId, HarvestResult, Intent, Seq, SessionId, Snapshot, Tick, TickDelta,
5};
6
7#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
8pub enum SessionEvent {
9 Welcome {
10 session_id: SessionId,
11 entity_id: EntityId,
12 snapshot: Snapshot,
13 },
14 ContentUpdated {
16 snapshot: Snapshot,
17 },
18 Tick(TickDelta),
19 IntentAck {
20 entity_id: EntityId,
21 seq: Seq,
22 tick: Tick,
23 },
24 Chat(ChatMessage),
25 HarvestResult(HarvestResult),
26 CraftResult(flatland_protocol::CraftResult),
27 Death(flatland_protocol::DeathNotice),
28 Interaction(flatland_protocol::InteractionNotice),
29 UseResult(flatland_protocol::UseResult),
30 Disconnected {
31 reason: Option<String>,
32 },
33}
34
35#[async_trait::async_trait]
37pub trait PlayConnection: Send {
38 fn session_id(&self) -> SessionId;
39 fn entity_id(&self) -> EntityId;
40 async fn submit_intent(&self, intent: Intent) -> anyhow::Result<()>;
41 fn try_next_event(&mut self) -> Option<SessionEvent>;
42 async fn next_event(&mut self) -> Option<SessionEvent>;
43 fn disconnect(&self);
44}