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