From b9ba0bbefab3895cdbb32b4dc30c8f40dc3502de Mon Sep 17 00:00:00 2001 From: yukirij Date: Sat, 5 Oct 2024 12:57:13 -0700 Subject: [PATCH] Temporary fix for resign handling. --- game/src/game/mod.rs | 5 +++- server/src/manager/data.rs | 12 +++++----- server/src/manager/ws.rs | 2 +- server/src/protocol/mod.rs | 2 +- server/src/protocol/packet/game_message.rs | 6 ++--- server/src/system/filesystem/mod.rs | 28 +++------------------- www/css/main.css | 3 +++ www/js/const.js | 2 +- www/js/interface.js | 13 ++++++++-- www/js/system.js | 2 +- 10 files changed, 34 insertions(+), 41 deletions(-) diff --git a/game/src/game/mod.rs b/game/src/game/mod.rs index de924a9..d96b3c2 100644 --- a/game/src/game/mod.rs +++ b/game/src/game/mod.rs @@ -49,7 +49,7 @@ impl Game { { self.init(); for play in history { - self.process(play)?; + self.process(play).ok(); } Ok(()) } @@ -72,6 +72,8 @@ impl Game { // - Determine game state (check, checkmate). // + println!("PLAY: {}", play.source); + if valid { @@ -146,6 +148,7 @@ impl Game { // Player retired. 0xF => { + println!("RESIGN"); self.status = GameStatus::Resign; true } diff --git a/server/src/manager/data.rs b/server/src/manager/data.rs index 4d03451..845b946 100644 --- a/server/src/manager/data.rs +++ b/server/src/manager/data.rs @@ -555,15 +555,15 @@ pub async fn thread_system(mut app:App, bus:Bus) Some(QRPacket::new(qr.id, QRPacketData::RSessionView(response))) } - // SessionRetire - QRPacketData::QSessionRetire(request) => { + // SessionResign + QRPacketData::QSessionResign(request) => { use game::history::Play; - println!("Request: Session Retire"); + println!("Request: Session Resign"); let mut packets = Vec::::new(); let play = Play { - source: 2, + source: 0xF, from: 0, to: 0, }; @@ -583,7 +583,7 @@ pub async fn thread_system(mut app:App, bus:Bus) packets.push(QRPacket::new( cid, QRPacketData::GameMessage(PacketGameMessage { - data: GameMessageData::Retire, + data: GameMessageData::Resign, }), )); } @@ -741,7 +741,7 @@ pub async fn thread_system(mut app:App, bus:Bus) } } - GameMessageData::Retire => { + GameMessageData::Resign => { if !session.game.is_complete() { if (user_id == Some(session.p_dawn.user) && session.game.turn & 1 == 0) || (user_id == Some(session.p_dusk.user) && session.game.turn & 1 == 1) { diff --git a/server/src/manager/ws.rs b/server/src/manager/ws.rs index b8a812d..5ac94c3 100644 --- a/server/src/manager/ws.rs +++ b/server/src/manager/ws.rs @@ -140,7 +140,7 @@ pub async fn handle_ws(ws:WebSocketStream>, args:HttpServiceAr Ok(packet) => { args.bus.send( bus_ds, - QRPacket::new(conn_id, QRPacketData::QSessionRetire(packet)) + QRPacket::new(conn_id, QRPacketData::QSessionResign(packet)) ).ok(); } Err(_) => { println!("error: packet decode failed."); } diff --git a/server/src/protocol/mod.rs b/server/src/protocol/mod.rs index 5edb1b5..4a84150 100644 --- a/server/src/protocol/mod.rs +++ b/server/src/protocol/mod.rs @@ -35,7 +35,7 @@ pub enum QRPacketData { QSessionView(PacketSessionView), RSessionView(PacketSessionViewResponse), - QSessionRetire(PacketSessionRetire), + QSessionResign(PacketSessionRetire), QSessionLeave, diff --git a/server/src/protocol/packet/game_message.rs b/server/src/protocol/packet/game_message.rs index f92eb7e..e703447 100644 --- a/server/src/protocol/packet/game_message.rs +++ b/server/src/protocol/packet/game_message.rs @@ -19,7 +19,7 @@ pub enum GameMessageData { Online(u8, u32), Undo(u16, u8), - Retire, + Resign, Reaction(u16), } @@ -67,7 +67,7 @@ impl Packet for PacketGameMessage { ((data >> 24) & 0x1) as u8, ), - GMSG_RETIRE => GameMessageData::Retire, + GMSG_RETIRE => GameMessageData::Resign, GMSG_REACTION => GameMessageData::Reaction( ((data >> 8) & 0xFFFF) as u16, @@ -113,7 +113,7 @@ impl Packet for PacketGameMessage { | ((turn as u64) << 8) | ((state as u64) << 24) } - GameMessageData::Retire => { + GameMessageData::Resign => { GMSG_RETIRE as u64 } diff --git a/server/src/system/filesystem/mod.rs b/server/src/system/filesystem/mod.rs index b350ad7..a10bac3 100644 --- a/server/src/system/filesystem/mod.rs +++ b/server/src/system/filesystem/mod.rs @@ -216,19 +216,19 @@ impl FileSystem { let bucket_index = id & !HANDLE_BUCKET_MASK; let dir_index = id & HANDLE_BUCKET_MASK; + println!("A"); + let bucket_path = Path::new(DIR_SESSION) .join(format!("{:08x}", bucket_index)) .join(format!("{:08x}", dir_index)); // Open session history file if let Ok(mut file) = File::options().read(true).write(true).open(bucket_path.join(GENERIC_HISTORY)) { - let mut buffer_size = [0u8; 2]; // Append history information file.seek(SeekFrom::End(0)).map_err(|_| ())?; file.write(&pack_u16(play_data)).map_err(|_| ())?; - // Update length file.seek(SeekFrom::Start(0)).map_err(|_| ())?; file.read_exact(&mut buffer_size).map_err(|_| ())?; @@ -253,7 +253,7 @@ impl FileSystem { .join(format!("{:08x}", dir_index)); // Open session history file - if let Ok(mut file) = File::options().write(true).read(true).open(bucket_path.join(GENERIC_HISTORY)) { + if let Ok(mut file) = File::options().read(true).open(bucket_path.join(GENERIC_HISTORY)) { // Read history length let mut buffer = [0u8; 2]; @@ -272,28 +272,6 @@ impl FileSystem { 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); } diff --git a/www/css/main.css b/www/css/main.css index 10af453..7558e15 100644 --- a/www/css/main.css +++ b/www/css/main.css @@ -68,6 +68,9 @@ body>nav>section>button:hover{ background-color:#383838; color:hsl(0, 0%, 88%); } +body>nav>section>button:disabled{ + color: #606060; +} body>nav>header{ display:block; diff --git a/www/js/const.js b/www/js/const.js index caf3d74..858108b 100644 --- a/www/js/const.js +++ b/www/js/const.js @@ -71,7 +71,7 @@ const GameMessage = { Online :0x08, Undo :0x10, - Retire :0x11, + Resign :0x11, Reaction :0x20, }; diff --git a/www/js/interface.js b/www/js/interface.js index 51f4722..5d732d1 100644 --- a/www/js/interface.js +++ b/www/js/interface.js @@ -389,6 +389,15 @@ const INTERFACE = { if(INTERFACE_DATA.Timeout.draw === null) { INTERFACE.draw(); } + + if(INTERFACE_DATA.mode == INTERFACE.Mode.Player) { + let b_resign = document.getElementById("button-resign"); + if(GAME_DATA.state.code == 0 && (GAME_DATA.turn & 1) == INTERFACE_DATA.player) { + b_resign.removeAttribute("disabled"); + } else { + b_resign.setAttribute("disabled", ""); + } + } }, draw() { @@ -1337,9 +1346,9 @@ const INTERFACE = { } } break; - case GameMessage.Retire: { + case GameMessage.Resign: { GAME_DATA.state.code = GAME.Const.State.Resign; - INTERFACE.redraw(); + INTERFACE.step(); } break; case GameMessage.Reaction: { diff --git a/www/js/system.js b/www/js/system.js index 96137e1..c09cc1b 100644 --- a/www/js/system.js +++ b/www/js/system.js @@ -368,7 +368,7 @@ function MESSAGE(event) { data.state = dat & 0x3; } break; - case GameMessage.Retire: { } break; + case GameMessage.Resign: { } break; case GameMessage.Reaction: { data.index = dat & 0xFFFF;