Temporary fix for resign handling.
This commit is contained in:
parent
e19168411f
commit
b9ba0bbefa
@ -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
|
||||
}
|
||||
|
@ -555,15 +555,15 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
|
||||
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::<QRPacket>::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<protocol::QRPacket>)
|
||||
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<protocol::QRPacket>)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -140,7 +140,7 @@ pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, 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."); }
|
||||
|
@ -35,7 +35,7 @@ pub enum QRPacketData {
|
||||
QSessionView(PacketSessionView),
|
||||
RSessionView(PacketSessionViewResponse),
|
||||
|
||||
QSessionRetire(PacketSessionRetire),
|
||||
QSessionResign(PacketSessionRetire),
|
||||
|
||||
QSessionLeave,
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -71,7 +71,7 @@ const GameMessage = {
|
||||
|
||||
Online :0x08,
|
||||
Undo :0x10,
|
||||
Retire :0x11,
|
||||
Resign :0x11,
|
||||
|
||||
Reaction :0x20,
|
||||
};
|
||||
|
@ -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: {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user