Reduced backend resposibility to emmit game events, whole addon logic implemented in python side

This commit is contained in:
Wiktor Mazur
2020-02-18 16:55:33 +01:00
parent d73f34a33b
commit 133975cd77
78 changed files with 3203 additions and 1331 deletions
+59
View File
@@ -0,0 +1,59 @@
use std::fs::File;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread;
use log::*;
use simplelog::*;
use packet_sniffer::UdpPacket;
use photon_decode::Photon;
use crate::game::World;
use crate::publisher::Publisher;
pub use crate::publisher::Subscribers;
use crate::translate::udp_packet_to_game_events;
pub enum InitializationError {
NetworkInterfaceListMissing,
}
pub fn initialize(subscribers: Subscribers) -> Result<(), InitializationError> {
initialize_logging();
if let Ok(interfaces) = packet_sniffer::network_interfaces() {
thread::spawn(move || {
let (tx, rx): (Sender<UdpPacket>, Receiver<UdpPacket>) = channel();
let mut photon = Photon::new();
let mut world = World::new();
let mut publisher = Publisher::new(subscribers);
packet_sniffer::receive(interfaces, tx);
info!("Listening to network packets...");
loop {
if let Ok(packet) = rx.recv() {
udp_packet_to_game_events(&mut world, &mut photon, &packet)
.into_iter()
.for_each(|e| {
publisher.publish(&e);
});
}
}
});
} else {
return Err(InitializationError::NetworkInterfaceListMissing);
}
Ok(())
}
fn initialize_logging() {
CombinedLogger::init(vec![WriteLogger::new(
LevelFilter::Info,
Config::default(),
File::create("damage-meter.log").unwrap(),
)]).unwrap();
}