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 ShopOpened(flatland_protocol::ShopCatalog),
30 BankOpened(flatland_protocol::BankPanel),
31 StorageOpened(flatland_protocol::StoragePanel),
32 NpcTalkOpened(flatland_protocol::NpcTalkOpened),
33 NpcTalkPending(flatland_protocol::NpcTalkPending),
34 NpcTalkReply(flatland_protocol::NpcTalkReply),
35 NpcTalkClosed(flatland_protocol::NpcTalkClosed),
36 NpcTalkError(flatland_protocol::NpcTalkError),
37 UseResult(flatland_protocol::UseResult),
38 QuestOffer(flatland_protocol::QuestOffer),
39 QuestAccepted(flatland_protocol::QuestNotice),
40 QuestWithdrawn(flatland_protocol::QuestNotice),
41 QuestStepCompleted(flatland_protocol::QuestNotice),
42 QuestCompleted(flatland_protocol::QuestNotice),
43 Disconnected {
44 reason: Option<String>,
45 },
46}
47
48#[async_trait::async_trait]
50pub trait PlayConnection: Send {
51 fn session_id(&self) -> SessionId;
52 fn entity_id(&self) -> EntityId;
53 async fn submit_intent(&self, intent: Intent) -> anyhow::Result<()>;
54 fn try_next_event(&mut self) -> Option<SessionEvent>;
55 async fn next_event(&mut self) -> Option<SessionEvent>;
56 fn disconnect(&self);
57}