use dreamwell_fabric::packets::ClientIntent;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionState {
Disconnected,
Connecting,
Connected,
Desynced,
}
#[derive(Debug, Clone)]
pub enum AuthorityEvent {
Ack { seq: u64 },
Reject { seq: u64, reason: String },
CanonEvent {
tick: u64,
event_type: String,
payload: Vec<u8>,
},
SnapshotChunk {
chunk_id: u32,
total_chunks: u32,
data: Vec<u8>,
},
}
pub trait AuthorityClient: Send {
fn submit_intents(&mut self, intents: &[ClientIntent]);
fn poll_events(&mut self, out: &mut Vec<AuthorityEvent>);
fn request_snapshot(&mut self);
fn connection_state(&self) -> ConnectionState;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn connection_state_variants() {
let states = [
ConnectionState::Disconnected,
ConnectionState::Connecting,
ConnectionState::Connected,
ConnectionState::Desynced,
];
assert_eq!(states.len(), 4);
}
#[test]
fn authority_event_variants() {
let _ack = AuthorityEvent::Ack { seq: 1 };
let _reject = AuthorityEvent::Reject {
seq: 2,
reason: "test".into(),
};
let _canon = AuthorityEvent::CanonEvent {
tick: 100,
event_type: "move".into(),
payload: vec![],
};
let _snapshot = AuthorityEvent::SnapshotChunk {
chunk_id: 0,
total_chunks: 1,
data: vec![],
};
}
}