pub mod condition; pub mod interface; use crossbeam_channel::Sender; use interface::network_loop; use karlcommon::{ClientboundPacket, Condition, Property, ServerboundPacket, Task}; use log::{debug, info}; use std::{collections::HashMap, sync::RwLock}; fn main() { env_logger::init(); info!("logging"); TASKS.write().unwrap().insert( 0, Task { id: 0, name: "blub".to_string(), description: "blob".to_string(), tags: vec![], priority: 69.0, completed: None, scheduled: None, occurence: Some(Condition::And(vec![ Condition::Equal { modulus: None, prop: Property::Monthofyear, value: 1, }, Condition::Equal { modulus: None, prop: Property::Hour, value: 12, }, ])), deadline: None, }, ); network_loop(); } lazy_static::lazy_static! { static ref TASKS: RwLock> = RwLock::new(HashMap::new()); } pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender) { match packet { ServerboundPacket::Download => { let _ = responder.send(ClientboundPacket::DownloadResponse( TASKS.read().unwrap().values().map(|e| e.clone()).collect(), )); } ServerboundPacket::UpdateTask(t) => { TASKS.write().unwrap().insert(t.id, t); } ServerboundPacket::RemoveTask(i) => { TASKS.write().unwrap().remove(&i); } ServerboundPacket::Handshake { version } => { debug!("{client}: version {version}"); } } }