1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
pub mod condition;
pub mod interface;
pub mod protocol;
use crossbeam_channel::{Receiver, Sender};
use interface::network_loop;
use protocol::{ClientboundPacket, ServerboundPacket};
use std::time::Duration;
use crate::{
condition::{Condition, Property},
protocol::Task,
};
fn main() {
let (s, r) = crossbeam_channel::unbounded();
std::thread::spawn(move || network_loop(s));
main_loop(r)
}
fn main_loop(packets: Receiver<(u32, ServerboundPacket, Sender<ClientboundPacket>)>) {
loop {
for (client_id, packet, responder) in packets.try_iter() {
println!("{:?}, {:?}, {:?}", client_id, packet, responder);
match packet {
ServerboundPacket::Download => {
let _ = responder.send(ClientboundPacket::DownloadResponse(vec![Task {
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,
}]));
}
}
}
std::thread::sleep(Duration::from_secs_f64(10.0 / 30.0));
}
}
|