Temporary fix for resign handling.

This commit is contained in:
yukirij 2024-10-05 12:57:13 -07:00
parent e19168411f
commit b9ba0bbefa
10 changed files with 34 additions and 41 deletions

View File

@ -49,7 +49,7 @@ impl Game {
{ {
self.init(); self.init();
for play in history { for play in history {
self.process(play)?; self.process(play).ok();
} }
Ok(()) Ok(())
} }
@ -72,6 +72,8 @@ impl Game {
// - Determine game state (check, checkmate). // - Determine game state (check, checkmate).
// //
println!("PLAY: {}", play.source);
if valid { if valid {
@ -146,6 +148,7 @@ impl Game {
// Player retired. // Player retired.
0xF => { 0xF => {
println!("RESIGN");
self.status = GameStatus::Resign; self.status = GameStatus::Resign;
true true
} }

View File

@ -555,15 +555,15 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
Some(QRPacket::new(qr.id, QRPacketData::RSessionView(response))) Some(QRPacket::new(qr.id, QRPacketData::RSessionView(response)))
} }
// SessionRetire // SessionResign
QRPacketData::QSessionRetire(request) => { QRPacketData::QSessionResign(request) => {
use game::history::Play; use game::history::Play;
println!("Request: Session Retire"); println!("Request: Session Resign");
let mut packets = Vec::<QRPacket>::new(); let mut packets = Vec::<QRPacket>::new();
let play = Play { let play = Play {
source: 2, source: 0xF,
from: 0, from: 0,
to: 0, to: 0,
}; };
@ -583,7 +583,7 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
packets.push(QRPacket::new( packets.push(QRPacket::new(
cid, cid,
QRPacketData::GameMessage(PacketGameMessage { QRPacketData::GameMessage(PacketGameMessage {
data: GameMessageData::Retire, data: GameMessageData::Resign,
}), }),
)); ));
} }
@ -741,7 +741,7 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
} }
} }
GameMessageData::Retire => { GameMessageData::Resign => {
if !session.game.is_complete() { if !session.game.is_complete() {
if (user_id == Some(session.p_dawn.user) && session.game.turn & 1 == 0) 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) { || (user_id == Some(session.p_dusk.user) && session.game.turn & 1 == 1) {

View File

@ -140,7 +140,7 @@ pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, args:HttpServiceAr
Ok(packet) => { Ok(packet) => {
args.bus.send( args.bus.send(
bus_ds, bus_ds,
QRPacket::new(conn_id, QRPacketData::QSessionRetire(packet)) QRPacket::new(conn_id, QRPacketData::QSessionResign(packet))
).ok(); ).ok();
} }
Err(_) => { println!("error: packet decode failed."); } Err(_) => { println!("error: packet decode failed."); }

View File

@ -35,7 +35,7 @@ pub enum QRPacketData {
QSessionView(PacketSessionView), QSessionView(PacketSessionView),
RSessionView(PacketSessionViewResponse), RSessionView(PacketSessionViewResponse),
QSessionRetire(PacketSessionRetire), QSessionResign(PacketSessionRetire),
QSessionLeave, QSessionLeave,

View File

@ -19,7 +19,7 @@ pub enum GameMessageData {
Online(u8, u32), Online(u8, u32),
Undo(u16, u8), Undo(u16, u8),
Retire, Resign,
Reaction(u16), Reaction(u16),
} }
@ -67,7 +67,7 @@ impl Packet for PacketGameMessage {
((data >> 24) & 0x1) as u8, ((data >> 24) & 0x1) as u8,
), ),
GMSG_RETIRE => GameMessageData::Retire, GMSG_RETIRE => GameMessageData::Resign,
GMSG_REACTION => GameMessageData::Reaction( GMSG_REACTION => GameMessageData::Reaction(
((data >> 8) & 0xFFFF) as u16, ((data >> 8) & 0xFFFF) as u16,
@ -113,7 +113,7 @@ impl Packet for PacketGameMessage {
| ((turn as u64) << 8) | ((turn as u64) << 8)
| ((state as u64) << 24) | ((state as u64) << 24)
} }
GameMessageData::Retire => { GameMessageData::Resign => {
GMSG_RETIRE as u64 GMSG_RETIRE as u64
} }

View File

@ -216,19 +216,19 @@ impl FileSystem {
let bucket_index = id & !HANDLE_BUCKET_MASK; let bucket_index = id & !HANDLE_BUCKET_MASK;
let dir_index = id & HANDLE_BUCKET_MASK; let dir_index = id & HANDLE_BUCKET_MASK;
println!("A");
let bucket_path = Path::new(DIR_SESSION) let bucket_path = Path::new(DIR_SESSION)
.join(format!("{:08x}", bucket_index)) .join(format!("{:08x}", bucket_index))
.join(format!("{:08x}", dir_index)); .join(format!("{:08x}", dir_index));
// Open session history file // Open session history file
if let Ok(mut file) = File::options().read(true).write(true).open(bucket_path.join(GENERIC_HISTORY)) { if let Ok(mut file) = File::options().read(true).write(true).open(bucket_path.join(GENERIC_HISTORY)) {
let mut buffer_size = [0u8; 2]; let mut buffer_size = [0u8; 2];
// Append history information // Append history information
file.seek(SeekFrom::End(0)).map_err(|_| ())?; file.seek(SeekFrom::End(0)).map_err(|_| ())?;
file.write(&pack_u16(play_data)).map_err(|_| ())?; file.write(&pack_u16(play_data)).map_err(|_| ())?;
// Update length // Update length
file.seek(SeekFrom::Start(0)).map_err(|_| ())?; file.seek(SeekFrom::Start(0)).map_err(|_| ())?;
file.read_exact(&mut buffer_size).map_err(|_| ())?; file.read_exact(&mut buffer_size).map_err(|_| ())?;
@ -253,7 +253,7 @@ impl FileSystem {
.join(format!("{:08x}", dir_index)); .join(format!("{:08x}", dir_index));
// Open session history file // 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 // Read history length
let mut buffer = [0u8; 2]; let mut buffer = [0u8; 2];
@ -272,28 +272,6 @@ impl FileSystem {
to:((data >> 10) & 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); result.push(play);
} }

View File

@ -68,6 +68,9 @@ body>nav>section>button:hover{
background-color:#383838; background-color:#383838;
color:hsl(0, 0%, 88%); color:hsl(0, 0%, 88%);
} }
body>nav>section>button:disabled{
color: #606060;
}
body>nav>header{ body>nav>header{
display:block; display:block;

View File

@ -71,7 +71,7 @@ const GameMessage = {
Online :0x08, Online :0x08,
Undo :0x10, Undo :0x10,
Retire :0x11, Resign :0x11,
Reaction :0x20, Reaction :0x20,
}; };

View File

@ -389,6 +389,15 @@ const INTERFACE = {
if(INTERFACE_DATA.Timeout.draw === null) { if(INTERFACE_DATA.Timeout.draw === null) {
INTERFACE.draw(); 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() { draw() {
@ -1337,9 +1346,9 @@ const INTERFACE = {
} }
} break; } break;
case GameMessage.Retire: { case GameMessage.Resign: {
GAME_DATA.state.code = GAME.Const.State.Resign; GAME_DATA.state.code = GAME.Const.State.Resign;
INTERFACE.redraw(); INTERFACE.step();
} break; } break;
case GameMessage.Reaction: { case GameMessage.Reaction: {

View File

@ -368,7 +368,7 @@ function MESSAGE(event) {
data.state = dat & 0x3; data.state = dat & 0x3;
} break; } break;
case GameMessage.Retire: { } break; case GameMessage.Resign: { } break;
case GameMessage.Reaction: { case GameMessage.Reaction: {
data.index = dat & 0xFFFF; data.index = dat & 0xFFFF;