From 08686670d8eb147855eabdcf753b7c0457d7a14b Mon Sep 17 00:00:00 2001 From: yukirij Date: Fri, 4 Oct 2024 20:32:08 -0700 Subject: [PATCH] Add patch for play code changes. --- game/src/game/mod.rs | 6 ++++++ server/src/app/mod.rs | 4 ---- server/src/system/filesystem/mod.rs | 31 ++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/game/src/game/mod.rs b/game/src/game/mod.rs index ac30a0b..de924a9 100644 --- a/game/src/game/mod.rs +++ b/game/src/game/mod.rs @@ -144,6 +144,12 @@ impl Game { } else { false } } + // Player retired. + 0xF => { + self.status = GameStatus::Resign; + true + } + _ => false, } { self.history.push(*play); diff --git a/server/src/app/mod.rs b/server/src/app/mod.rs index c3cdcb3..ec69695 100644 --- a/server/src/app/mod.rs +++ b/server/src/app/mod.rs @@ -87,10 +87,6 @@ impl App { // Load session history if let Ok(history) = filesystem.session_history_fetch(id as u32) { - let mut history = history; - for play in &mut history { - if play.source == 3 { play.source = 2; } - } session.game.apply_history(&history).ok(); } diff --git a/server/src/system/filesystem/mod.rs b/server/src/system/filesystem/mod.rs index c7f1325..a1b4be6 100644 --- a/server/src/system/filesystem/mod.rs +++ b/server/src/system/filesystem/mod.rs @@ -253,7 +253,7 @@ impl FileSystem { .join(format!("{:08x}", dir_index)); // Open session history file - if let Ok(mut file) = File::options().read(true).open(bucket_path.join(GENERIC_HISTORY)) { + if let Ok(mut file) = File::options().write(true).read(true).open(bucket_path.join(GENERIC_HISTORY)) { // Read history length let mut buffer = [0u8; 2]; @@ -265,11 +265,36 @@ impl FileSystem { for _ in 0..length { file.read_exact(&mut buffer).map_err(|_| ())?; let data = unpack_u16(&buffer, &mut 0); - result.push(Play { + + let mut play = Play { source:(data & 0xF) as u8, from:((data >> 4) & 0x3F) as u8, to:((data >> 10) & 0x3F) as u8, - }); + }; + + match play.source { + 2 => { + play.source = 0xF; + file.seek(SeekFrom::Current(-2)).map_err(|_| ())?; + file.write(&mut pack_u16( + play.source as u16 + | ((play.from as u16) << 4) + | ((play.to as u16) << 10) + )).map_err(|_| ())?; + } + 3 => { + play.source = 2; + file.seek(SeekFrom::Current(-2)).map_err(|_| ())?; + file.write(&mut pack_u16( + play.source as u16 + | ((play.from as u16) << 4) + | ((play.to as u16) << 10) + )).map_err(|_| ())?; + } + _ => { } + } + + result.push(play); } Ok(result)