diff options
Diffstat (limited to 'karld/src/main.rs')
-rw-r--r-- | karld/src/main.rs | 101 |
1 files changed, 11 insertions, 90 deletions
diff --git a/karld/src/main.rs b/karld/src/main.rs index 22a12f7..2b95cb7 100644 --- a/karld/src/main.rs +++ b/karld/src/main.rs @@ -2,6 +2,7 @@ #![feature(fs_try_exists)] pub mod condition; +pub mod demo; pub mod helper; pub mod interface; pub mod savestate; @@ -11,12 +12,14 @@ use chrono::NaiveDateTime; use condition::ConditionFind; use crossbeam_channel::Sender; use helper::Overlaps; -use interface::network_loop; use karlcommon::{ ClientboundPacket, Condition, Property, ProtoError, Schedule, ServerboundPacket, Task, }; use log::{debug, error, info}; -use std::{collections::HashMap, sync::RwLock}; +use std::{ + collections::HashMap, + sync::{atomic::AtomicU32, RwLock}, +}; use crate::schedule::schedule_dynamic; @@ -26,104 +29,22 @@ fn main() { if let Err(e) = savestate::load() { error!("load failed: {}", e); } - TASKS.write().unwrap().insert( - 0, - Task { - id: 0, - name: "Mittagessen im Februar".to_string(), - description: None, - tags: vec!["Essen".to_string(), "Unwichtig".to_string()], - schedule: Schedule::Condition(Condition::And(vec![ - Condition::Equal { - modulus: None, - prop: Property::Monthofyear, - value: 1, - }, - Condition::Equal { - modulus: None, - prop: Property::Hour, - value: 12, - }, - ])), - }, - ); - TASKS.write().unwrap().insert( - 1, - Task { - id: 1, - name: "Abendessen oder Frühstück".to_string(), - description: Some("Nom nom nom".to_string()), - tags: vec!["Essen".to_string()], - schedule: Schedule::Condition(Condition::Or(vec![ - Condition::Equal { - modulus: None, - prop: Property::Hour, - value: 18, - }, - Condition::Equal { - modulus: None, - prop: Property::Hour, - value: 7, - }, - ])), - }, - ); - TASKS.write().unwrap().insert( - 2, - Task { - id: 2, - description: None, - name: "Wichtiger termin™".to_string(), - tags: vec![], - schedule: Schedule::Static(1654997366..1655007366), - }, - ); - - TASKS.write().unwrap().insert( - 3, - Task { - id: 3, - description: None, - name: "Staubsaugen".to_string(), - tags: vec!["Unwichtig".to_string()], - schedule: Schedule::Dynamic { - scheduled: None, - duration: 15 * 60, - priority: 2.0, - condition: Condition::Equal { - prop: Property::Monthofyear, - value: 6, - modulus: None, - }, - }, - }, - ); - TASKS.write().unwrap().insert( - 4, - Task { - id: 4, - description: Some("sollte ich wirklich mal machen".to_string()), - name: "Geschirrspüler ausräumen".to_string(), - tags: vec!["Unwichtig".to_string()], - schedule: Schedule::Dynamic { - scheduled: None, - duration: 15 * 60, - priority: 5.0, - condition: Condition::Never, - }, - }, - ); std::thread::spawn(move || { std::thread::sleep(std::time::Duration::from_secs_f64(0.1)); schedule_dynamic(); }); - network_loop(); + interface::start(); + + loop { + std::thread::sleep(std::time::Duration::from_secs_f64(100.0)); + } } lazy_static::lazy_static! { static ref TASKS: RwLock<HashMap<u64, Task>> = RwLock::new(HashMap::new()); + static ref CLIENT_ID_COUNTER: AtomicU32 = AtomicU32::new(0); } pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<ClientboundPacket>) { |