Enable entity subsystem

This commit is contained in:
Nobody 2022-02-04 22:58:55 +05:00
parent 3cf1b4719b
commit c5bd44e747

View File

@ -7,7 +7,7 @@ use crate::server::GameWorld;
use packet_processor::PacketProcessor; use packet_processor::PacketProcessor;
use crate::server::IpcMessage; use crate::server::IpcMessage;
use crate::DatabaseManager; use crate::{DatabaseManager, EntitySubsystem};
use crate::JsonManager; use crate::JsonManager;
use crate::LuaManager; use crate::LuaManager;
use crate::server::LoginManager; use crate::server::LoginManager;
@ -20,6 +20,7 @@ pub struct GameServer {
login_manager: LoginManager, login_manager: LoginManager,
database_manager: Arc<DatabaseManager>, database_manager: Arc<DatabaseManager>,
json_manager: Arc<JsonManager>, json_manager: Arc<JsonManager>,
processors: Vec<Box<PacketProcessor>>,
} }
impl GameServer { impl GameServer {
@ -28,6 +29,7 @@ impl GameServer {
let jm = Arc::new(JsonManager::new("./data/json")); let jm = Arc::new(JsonManager::new("./data/json"));
let lm = LoginManager::new(db.clone(), jm.clone(), packets_to_send_tx.clone()); let lm = LoginManager::new(db.clone(), jm.clone(), packets_to_send_tx.clone());
let lum = Arc::new(LuaManager::new("./data/lua")); let lum = Arc::new(LuaManager::new("./data/lua"));
let em = EntitySubsystem::new(packets_to_send_tx.clone());
let gs = GameServer { let gs = GameServer {
packets_to_process_rx: packets_to_process_rx, packets_to_process_rx: packets_to_process_rx,
@ -36,6 +38,7 @@ impl GameServer {
login_manager: lm, login_manager: lm,
database_manager: db.clone(), database_manager: db.clone(),
json_manager: jm.clone(), json_manager: jm.clone(),
processors: vec![Box::new(em)],
}; };
return gs; return gs;
@ -59,12 +62,22 @@ impl GameServer {
let world = match self.worlds.entry(user_id) { let world = match self.worlds.entry(user_id) {
Occupied(world) => world.into_mut(), Occupied(world) => world.into_mut(),
Vacant(entry) => { Vacant(entry) => {
let mut world = GameWorld::new(self.database_manager.clone(),self.json_manager.clone(), self.packets_to_send_tx.clone()); let world = GameWorld::new(self.database_manager.clone(),self.json_manager.clone(), self.packets_to_send_tx.clone());
entry.insert(world) entry.insert(world)
}, },
}; };
world.process(user_id, packet_id, metadata, data); if world.is_supported(&packet_id) {
world.process(user_id, packet_id.clone(), metadata.clone(), data.clone());
}
for processor in self.processors.iter_mut() {
if processor.is_supported(&packet_id) {
processor.process(user_id, packet_id.clone(), metadata.clone(), data.clone());
}
}
//println!("No handler found for packet {:#?}", packet_id);
} }
} }
} }