1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-20 14:47:45 +00:00

Pass GameData into Zone, stop loading the same zone twice on login

This commit is contained in:
Joshua Goins 2025-03-30 19:13:24 -04:00
parent 243d94c586
commit caf70ea469
5 changed files with 12 additions and 20 deletions

View file

@ -213,11 +213,11 @@ async fn client_loop(
let mut lua_player = LuaPlayer::default(); let mut lua_player = LuaPlayer::default();
let mut buf = [0; 2056]; let mut buf = [0; 4096];
loop { loop {
tokio::select! { tokio::select! {
Ok(n) = connection.socket.read(&mut buf) => { Ok(n) = connection.socket.read(&mut buf) => {
if n != 0 { if n > 0 {
let (segments, connection_type) = connection.parse_packet(&buf[..n]).await; let (segments, connection_type) = connection.parse_packet(&buf[..n]).await;
for segment in &segments { for segment in &segments {
match &segment.segment_type { match &segment.segment_type {
@ -318,9 +318,6 @@ async fn client_loop(
.await; .await;
} }
let zone_id = connection.player_data.zone_id;
connection.zone = Some(Zone::load(zone_id));
// Player Setup // Player Setup
{ {
let ipc = ServerZoneIpcSegment { let ipc = ServerZoneIpcSegment {
@ -354,6 +351,7 @@ async fn client_loop(
.await; .await;
} }
let zone_id = connection.player_data.zone_id;
connection.change_zone(zone_id).await; connection.change_zone(zone_id).await;
let lua = lua.lock().unwrap(); let lua = lua.lock().unwrap();
@ -692,7 +690,8 @@ async fn client_loop(
.unwrap(); .unwrap();
// find the pop range on the other side // find the pop range on the other side
let new_zone = Zone::load(exit_box.territory_type); let mut game_data = game_data.lock().unwrap();
let new_zone = Zone::load(&mut game_data.game_data, exit_box.territory_type);
let (destination_object, _) = new_zone let (destination_object, _) = new_zone
.find_pop_range(exit_box.destination_instance_id) .find_pop_range(exit_box.destination_instance_id)
.unwrap(); .unwrap();

View file

@ -4,7 +4,7 @@ use crate::{common::Attributes, config::get_config};
/// Convenient methods built on top of Physis to access data relevant to the server /// Convenient methods built on top of Physis to access data relevant to the server
pub struct GameData { pub struct GameData {
game_data: physis::gamedata::GameData, pub game_data: physis::gamedata::GameData,
} }
impl GameData { impl GameData {

View file

@ -168,10 +168,7 @@ pub async fn send_packet<T: ReadWriteIpcSegment>(
let buffer = cursor.into_inner(); let buffer = cursor.into_inner();
socket socket.write_all(&buffer).await.unwrap();
.write_all(&buffer)
.await
.expect("Failed to write packet!");
} }
// temporary // temporary

View file

@ -321,7 +321,10 @@ impl ZoneConnection {
} }
pub async fn change_zone(&mut self, new_zone_id: u16) { pub async fn change_zone(&mut self, new_zone_id: u16) {
self.zone = Some(Zone::load(new_zone_id)); {
let mut game_data = self.gamedata.lock().unwrap();
self.zone = Some(Zone::load(&mut game_data.game_data, new_zone_id));
}
self.player_data.zone_id = new_zone_id; self.player_data.zone_id = new_zone_id;
// Player Class Info // Player Class Info

View file

@ -22,19 +22,12 @@ pub struct Zone {
} }
impl Zone { impl Zone {
pub fn load(id: u16) -> Self { pub fn load(game_data: &mut GameData, id: u16) -> Self {
let config = get_config();
let mut zone = Self { let mut zone = Self {
id, id,
..Default::default() ..Default::default()
}; };
let Some(mut game_data) = GameData::from_existing(Platform::Win32, &config.game_location)
else {
return zone;
};
let Some(exh) = game_data.read_excel_sheet_header("TerritoryType") else { let Some(exh) = game_data.read_excel_sheet_header("TerritoryType") else {
return zone; return zone;
}; };