2022-12-14 23:48:00 +11:00
|
|
|
use blastmud_interfaces::*;
|
2022-12-18 23:44:04 +11:00
|
|
|
use crate::db;
|
2022-12-16 20:48:24 +11:00
|
|
|
use MessageFromListener::*;
|
|
|
|
use uuid::Uuid;
|
2022-12-18 23:44:04 +11:00
|
|
|
use crate::DResult;
|
2022-12-24 13:43:28 +11:00
|
|
|
|
|
|
|
mod new_session;
|
2022-12-31 00:59:14 +11:00
|
|
|
pub mod user_commands;
|
2022-12-14 23:48:00 +11:00
|
|
|
|
2022-12-23 23:31:49 +11:00
|
|
|
#[derive(Clone,Debug)]
|
|
|
|
pub struct ListenerSession {
|
|
|
|
pub listener: Uuid,
|
|
|
|
pub session: Uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn handle(listener: Uuid, msg: MessageFromListener, pool: db::DBPool)
|
2022-12-18 23:44:04 +11:00
|
|
|
-> DResult<()> {
|
2022-12-16 20:48:24 +11:00
|
|
|
match msg {
|
2022-12-23 21:37:28 +11:00
|
|
|
ListenerPing { .. } => { pool.record_listener_ping(listener).await?; }
|
2022-12-24 13:43:28 +11:00
|
|
|
SessionConnected { session, source } => {
|
2022-12-24 21:16:23 +11:00
|
|
|
new_session::handle(
|
|
|
|
&ListenerSession { listener, session }, source, &pool).await?;
|
2022-12-23 23:31:49 +11:00
|
|
|
}
|
|
|
|
SessionDisconnected { session } => {
|
|
|
|
pool.end_session(ListenerSession { listener, session }).await?;
|
2022-12-23 21:37:28 +11:00
|
|
|
}
|
2022-12-16 20:48:24 +11:00
|
|
|
SessionSentLine { session, msg } => {
|
2022-12-24 21:16:23 +11:00
|
|
|
user_commands::handle(&ListenerSession { listener, session }, &msg, &pool).await?;
|
2022-12-16 20:48:24 +11:00
|
|
|
}
|
|
|
|
AcknowledgeMessage => {}
|
|
|
|
}
|
|
|
|
Ok(())
|
2022-12-14 23:48:00 +11:00
|
|
|
}
|