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