aboutsummaryrefslogtreecommitdiff
path: root/karld/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'karld/src/main.rs')
-rw-r--r--karld/src/main.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/karld/src/main.rs b/karld/src/main.rs
index 2d0c9e9..181c2be 100644
--- a/karld/src/main.rs
+++ b/karld/src/main.rs
@@ -1,6 +1,7 @@
pub mod condition;
pub mod helper;
pub mod interface;
+pub mod savestate;
pub mod schedule;
use chrono::NaiveDateTime;
@@ -11,12 +12,15 @@ use interface::network_loop;
use karlcommon::{
ClientboundPacket, Condition, Instance, Property, ProtoError, Schedule, ServerboundPacket, Task,
};
-use log::{debug, info};
+use log::{debug, error, info};
use std::{collections::HashMap, sync::RwLock};
fn main() {
env_logger::init();
info!("logging");
+ if let Err(e) = savestate::load() {
+ error!("load failed: {}", e);
+ }
TASKS.write().unwrap().insert(
0,
Task {
@@ -88,11 +92,13 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<C
}
ServerboundPacket::UpdateTask(t) => {
TASKS.write().unwrap().insert(t.id, t);
+ savestate::save();
}
ServerboundPacket::RemoveTask(i) => {
if TASKS.write().unwrap().remove(&i).is_none() {
let _ = responder.send(ClientboundPacket::Error(ProtoError::UnknownTask));
}
+ savestate::save();
}
ServerboundPacket::Handshake { version } => {
debug!("{client}: version {version}");