server: 0012-rules-restart
TICKET-286: the rules restart (0x54-0x58): Prepare / ack / Commit barrier, a replacement server opened by the bootstrap secret, Reserved seats with tokens and a deadline. Replayed from Tools/YGOLegacy/patches/0012-rules-restart.patch in the Unity repo. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
9dbe0437f6
commit
cea91450f2
7 files changed
+906
-48
No files matched your search
+322
-24
@@ -68,7 +68,7 @@ void SingleDuel::Dialogue(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
void SingleDuel::SendServerCapability(DuelPlayer* dp) {
|
||||
CTOS_Capability cap;
|
||||
cap.protocol = FEATURE_PROTOCOL;
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN; // YGOL setup pairs + host seats
|
||||
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART; // YGOL setup pairs + host seats + rules restart
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&cap, sizeof cap, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_CAPABILITY, buf, size);
|
||||
@@ -130,9 +130,20 @@ int SingleDuel::FreeOpenSeat() {
|
||||
}
|
||||
int SingleDuel::ClaimedSeat(DuelPlayer* dp) {
|
||||
const auto& req = dp->seat_request;
|
||||
static const uint8_t zero_id[16]{};
|
||||
if(std::memcmp(req.restart_id, zero_id, sizeof zero_id) != 0)
|
||||
return -1;
|
||||
if(!IsZeroId(req.restart_id)) {
|
||||
// YGOL rules restart: a returning seat, only for this server's restart and only while reserved
|
||||
if(!has_restart_id || std::memcmp(req.restart_id, restart_id, sizeof restart_id) != 0)
|
||||
return -1;
|
||||
if(req.seat == SEAT_WATCHERS)
|
||||
return has_observer_token && std::memcmp(req.token, observer_token, SEAT_TOKEN_LEN) == 0 ? -2 : -1;
|
||||
if(req.seat >= 2 || players[req.seat])
|
||||
return -1;
|
||||
if(seat_kind[req.seat] == SEAT_KIND_RESERVED ? !has_restart_plan : seat_kind[req.seat] != SEAT_KIND_CPU)
|
||||
return -1;
|
||||
if(std::memcmp(req.token, seat_token[req.seat], SEAT_TOKEN_LEN) != 0)
|
||||
return -1;
|
||||
return req.seat;
|
||||
}
|
||||
if(req.seat >= 2 || players[req.seat] || seat_kind[req.seat] != SEAT_KIND_CPU)
|
||||
return -1;
|
||||
if(std::memcmp(req.token, seat_token[req.seat], SEAT_TOKEN_LEN) != 0)
|
||||
@@ -143,34 +154,50 @@ void SingleDuel::ClearSeatPlan() {
|
||||
std::memset(seat_kind, 0, sizeof seat_kind);
|
||||
std::memset(seat_token, 0, sizeof seat_token);
|
||||
has_seat_plan = false;
|
||||
has_restart_plan = false; // YGOL rules restart
|
||||
}
|
||||
void SingleDuel::SeatPlan(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
if(dp != host_player || duel_stage != DUEL_STAGE_BEGIN)
|
||||
return;
|
||||
CTOS_SeatPlan plan;
|
||||
std::memcpy(&plan, pdata, sizeof plan);
|
||||
static const uint8_t zero_id[16]{};
|
||||
bool accepted = plan.seat_count == 2 && plan.deadline_ms == 0 && std::memcmp(plan.restart_id, zero_id, sizeof zero_id) == 0;
|
||||
// YGOL rules restart: the bootstrap host's first plan reserves the returning humans' seats for deadline_ms
|
||||
const bool restart_plan = !IsZeroId(plan.restart_id);
|
||||
bool accepted = plan.seat_count == 2 && restart_phase == 0;
|
||||
if(restart_plan)
|
||||
accepted = accepted && dp->ygol_bootstrap && bootstrap_closed && has_restart_id && !has_restart_plan && plan.deadline_ms > 0
|
||||
&& std::memcmp(plan.restart_id, restart_id, sizeof restart_id) == 0;
|
||||
else
|
||||
accepted = accepted && plan.deadline_ms == 0;
|
||||
for(int i = 0; i < 2 && accepted; ++i) {
|
||||
if(plan.kind[i] > SEAT_KIND_CPU)
|
||||
if(plan.kind[i] > SEAT_KIND_RESERVED)
|
||||
accepted = false;
|
||||
else if(plan.kind[i] == SEAT_KIND_CPU && players[i] && !players[i]->ygol_cpu)
|
||||
accepted = false;
|
||||
else if(plan.kind[i] == SEAT_KIND_RESERVED && (players[i] || (!restart_plan && seat_kind[i] != SEAT_KIND_RESERVED)))
|
||||
accepted = false;
|
||||
}
|
||||
if(!accepted) {
|
||||
SendSeatPlan(dp, plan.revision); // the host alone sees its revision come back with the kinds unchanged
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < 2; ++i) {
|
||||
if(!restart_plan && seat_kind[i] == SEAT_KIND_RESERVED && !players[i])
|
||||
continue; // a reservation is ended only by Complete, Release or its deadline, never by a later plan
|
||||
seat_kind[i] = plan.kind[i];
|
||||
std::memcpy(seat_token[i], plan.token[i], SEAT_TOKEN_LEN);
|
||||
}
|
||||
if(restart_plan) {
|
||||
has_restart_plan = true;
|
||||
reserve_ticks = (plan.deadline_ms + 999) / 1000;
|
||||
NetServer::StartDuelTimer();
|
||||
}
|
||||
seat_revision = plan.revision;
|
||||
has_seat_plan = true;
|
||||
BroadcastSeatPlan();
|
||||
}
|
||||
void SingleDuel::SeatSwap(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
if(dp != host_player || duel_stage != DUEL_STAGE_BEGIN)
|
||||
if(dp != host_player || duel_stage != DUEL_STAGE_BEGIN || restart_phase != 0)
|
||||
return;
|
||||
CTOS_SeatSwap swap;
|
||||
std::memcpy(&swap, pdata, sizeof swap);
|
||||
@@ -182,7 +209,7 @@ void SingleDuel::SeatSwap(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
SwapSeats(a, b);
|
||||
}
|
||||
void SingleDuel::SeatMove(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
if(duel_stage != DUEL_STAGE_BEGIN)
|
||||
if(duel_stage != DUEL_STAGE_BEGIN || restart_phase != 0)
|
||||
return;
|
||||
CTOS_SeatMove move;
|
||||
std::memcpy(&move, pdata, sizeof move);
|
||||
@@ -256,6 +283,219 @@ void SingleDuel::SwapSeats(int first, int second) {
|
||||
if(has_seat_plan)
|
||||
BroadcastSeatPlan();
|
||||
}
|
||||
// YGOL rules restart
|
||||
template<typename F> void SingleDuel::ForEachParticipant(F f) {
|
||||
for(int i = 0; i < 2; ++i)
|
||||
if(players[i] && !players[i]->ygol_cpu)
|
||||
f(players[i], (uint8_t)i);
|
||||
for(auto pit = observers.begin(); pit != observers.end(); ++pit)
|
||||
f(*pit, SEAT_WATCHERS);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(host_player && host_player->type == 9)
|
||||
f(host_player, SEAT_WATCHERS); // a watching host joined as the recorder
|
||||
#endif
|
||||
}
|
||||
bool SingleDuel::RestartCompatible() {
|
||||
bool ok = true;
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t) {
|
||||
if(!p->has_capability || p->capability.protocol < 2 || !(p->capability.flags & FEATURE_RULES_RESTART))
|
||||
ok = false;
|
||||
});
|
||||
return ok;
|
||||
}
|
||||
void SingleDuel::SendRestarting(DuelPlayer* dp, uint8_t phase, const uint8_t* token) {
|
||||
STOC_RoomRestarting msg;
|
||||
msg.phase = phase;
|
||||
std::memcpy(msg.restart_id, restart_id, sizeof msg.restart_id);
|
||||
msg.seat = dp->type < 2 ? dp->type : SEAT_WATCHERS;
|
||||
if(token)
|
||||
std::memcpy(msg.token, token, sizeof msg.token);
|
||||
msg.timeout_ms = phase == RESTART_PHASE_PREPARE ? restart_timeout_ms : 0;
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&msg, sizeof msg, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_ROOM_RESTARTING, buf, size);
|
||||
}
|
||||
void SingleDuel::SendRestartStatus(DuelPlayer* dp, uint8_t phase, const uint8_t* id, uint8_t complete, uint8_t reason) {
|
||||
STOC_RestartStatus msg;
|
||||
msg.phase = phase;
|
||||
std::memcpy(msg.restart_id, id, sizeof msg.restart_id);
|
||||
uint8_t expected = 0, acked = 0;
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t) {
|
||||
++expected;
|
||||
if(p->restart_acked == phase)
|
||||
++acked;
|
||||
});
|
||||
msg.acked = acked;
|
||||
msg.expected = expected;
|
||||
msg.complete = complete;
|
||||
msg.reason = reason;
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&msg, sizeof msg, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_RESTART_STATUS, buf, size);
|
||||
}
|
||||
void SingleDuel::SendResumeResult(DuelPlayer* dp, const uint8_t* id, bool accepted, uint8_t reason) {
|
||||
STOC_SeatResumeResult msg;
|
||||
std::memcpy(msg.restart_id, id, sizeof msg.restart_id);
|
||||
msg.accepted = accepted ? 1 : 0;
|
||||
msg.seat = dp->type < 2 ? dp->type : SEAT_WATCHERS;
|
||||
msg.reason = reason;
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&msg, sizeof msg, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_SEAT_RESUME_RESULT, buf, size);
|
||||
}
|
||||
void SingleDuel::ClearRestart() {
|
||||
restart_phase = 0;
|
||||
restart_ticks = 0;
|
||||
ForEachParticipant([](DuelPlayer* p, uint8_t) { p->restart_acked = 0; });
|
||||
}
|
||||
// Prepare: the host asks; every participant (humans and watchers, never the host's own CPUs) must speak protocol 2 + 0x10
|
||||
void SingleDuel::RestartPrepare(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
if(dp != host_player)
|
||||
return;
|
||||
CTOS_RestartPrepare req;
|
||||
std::memcpy(&req, pdata, sizeof req);
|
||||
if(duel_stage != DUEL_STAGE_BEGIN || ygol_started) {
|
||||
SendRestartStatus(dp, RESTART_PHASE_PREPARE, req.restart_id, 0, RESTART_REASON_NOT_LOBBY);
|
||||
return;
|
||||
}
|
||||
if(restart_phase != 0) {
|
||||
SendRestartStatus(dp, RESTART_PHASE_PREPARE, req.restart_id, 0, RESTART_REASON_BUSY);
|
||||
return;
|
||||
}
|
||||
if(req.seat_count != 2 || IsZeroId(req.restart_id)) {
|
||||
SendRestartStatus(dp, RESTART_PHASE_PREPARE, req.restart_id, 0, RESTART_REASON_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
if(!RestartCompatible()) {
|
||||
SendRestartStatus(dp, RESTART_PHASE_PREPARE, req.restart_id, 0, RESTART_REASON_INCOMPATIBLE);
|
||||
return;
|
||||
}
|
||||
std::memcpy(restart_id, req.restart_id, sizeof restart_id);
|
||||
has_restart_id = true;
|
||||
for(int i = 0; i < 2; ++i)
|
||||
std::memcpy(restart_seat_token[i], req.seat_token[i], SEAT_TOKEN_LEN);
|
||||
std::memcpy(restart_observer_token, req.observer_token, SEAT_TOKEN_LEN);
|
||||
restart_phase = RESTART_PHASE_PREPARE;
|
||||
restart_timeout_ms = req.timeout_ms;
|
||||
restart_ticks = 0;
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t seat) {
|
||||
p->restart_acked = 0;
|
||||
SendRestarting(p, RESTART_PHASE_PREPARE, seat < 2 ? restart_seat_token[seat] : restart_observer_token);
|
||||
});
|
||||
NetServer::StartDuelTimer();
|
||||
SendRestartStatus(dp, RESTART_PHASE_PREPARE, restart_id, 0, RESTART_REASON_NONE);
|
||||
}
|
||||
void SingleDuel::RestartAck(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
if(restart_phase == 0)
|
||||
return;
|
||||
CTOS_RestartAck ack;
|
||||
std::memcpy(&ack, pdata, sizeof ack);
|
||||
if(std::memcmp(ack.restart_id, restart_id, sizeof restart_id) != 0 || ack.phase != restart_phase || dp->restart_acked == restart_phase)
|
||||
return;
|
||||
dp->restart_acked = restart_phase;
|
||||
bool all = true;
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t) {
|
||||
if(p->restart_acked != restart_phase)
|
||||
all = false;
|
||||
});
|
||||
if(all)
|
||||
restart_ticks = 0; // the host has another 5 s to Commit (or tear down)
|
||||
if(host_player)
|
||||
SendRestartStatus(host_player, restart_phase, restart_id, all ? 1 : 0, RESTART_REASON_NONE);
|
||||
}
|
||||
// Commit only after every Prepare ack; Abort unfreezes the room with nothing changed
|
||||
void SingleDuel::RestartControl(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
if(dp != host_player || restart_phase == 0)
|
||||
return;
|
||||
CTOS_RestartControl control;
|
||||
std::memcpy(&control, pdata, sizeof control);
|
||||
if(std::memcmp(control.restart_id, restart_id, sizeof restart_id) != 0)
|
||||
return;
|
||||
if(control.action == RESTART_PHASE_ABORT) {
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t) { SendRestarting(p, RESTART_PHASE_ABORT, nullptr); });
|
||||
ClearRestart();
|
||||
return;
|
||||
}
|
||||
if(control.action != RESTART_PHASE_COMMIT || restart_phase != RESTART_PHASE_PREPARE)
|
||||
return;
|
||||
bool all = true;
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t) {
|
||||
if(p->restart_acked != RESTART_PHASE_PREPARE)
|
||||
all = false;
|
||||
});
|
||||
if(!all) {
|
||||
SendRestartStatus(dp, RESTART_PHASE_COMMIT, restart_id, 0, RESTART_REASON_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
restart_phase = RESTART_PHASE_COMMIT;
|
||||
restart_ticks = 0;
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t) { SendRestarting(p, RESTART_PHASE_COMMIT, nullptr); });
|
||||
SendRestartStatus(dp, RESTART_PHASE_COMMIT, restart_id, 0, RESTART_REASON_NONE);
|
||||
}
|
||||
// Complete / Release end a restoring seat: READY stays false; a Reserved seat becomes Open (consumed or given back)
|
||||
void SingleDuel::SeatResume(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
CTOS_SeatResume resume;
|
||||
std::memcpy(&resume, pdata, sizeof resume);
|
||||
if(!has_restart_id || std::memcmp(resume.restart_id, restart_id, sizeof restart_id) != 0) {
|
||||
SendResumeResult(dp, resume.restart_id, false, RESUME_REASON_NO_RESTART);
|
||||
return;
|
||||
}
|
||||
if(!dp->ygol_restoring || (resume.action != SEAT_RESUME_COMPLETE && resume.action != SEAT_RESUME_RELEASE)) {
|
||||
SendResumeResult(dp, resume.restart_id, false, RESUME_REASON_NOT_RESTORING);
|
||||
return;
|
||||
}
|
||||
dp->ygol_restoring = false;
|
||||
if(dp->type < 2 && seat_kind[dp->type] == SEAT_KIND_RESERVED) {
|
||||
seat_kind[dp->type] = SEAT_KIND_OPEN;
|
||||
std::memset(seat_token[dp->type], 0, SEAT_TOKEN_LEN);
|
||||
BroadcastSeatPlan();
|
||||
}
|
||||
SendResumeResult(dp, resume.restart_id, true, RESTART_REASON_NONE);
|
||||
}
|
||||
// The bootstrap host installed its plan: store the observers' token and open admission
|
||||
void SingleDuel::RestartOpen(DuelPlayer* dp, unsigned char* pdata, int len) {
|
||||
CTOS_RestartOpen open;
|
||||
std::memcpy(&open, pdata, sizeof open);
|
||||
STOC_RestartOpen reply;
|
||||
std::memcpy(reply.restart_id, open.restart_id, sizeof reply.restart_id);
|
||||
reply.opened = 0;
|
||||
if(dp == host_player && dp->ygol_bootstrap && bootstrap_closed && has_restart_id && std::memcmp(open.restart_id, restart_id, sizeof restart_id) == 0) {
|
||||
std::memcpy(observer_token, open.observer_token, sizeof observer_token);
|
||||
has_observer_token = !IsZeroId(observer_token);
|
||||
bootstrap_closed = false;
|
||||
reply.opened = 1;
|
||||
}
|
||||
unsigned char buf[SIZE_STOC_FEATURE];
|
||||
const auto size = NetServer::CreateStampedPacket((unsigned char*)&reply, sizeof reply, buf, FEATURE_SENDER_SERVER);
|
||||
NetServer::SendBufferToPlayer(dp, STOC_RESTART_OPEN, buf, size);
|
||||
}
|
||||
// One tick per second in the lobby: the 5 s ack deadline, then the reservation window
|
||||
void SingleDuel::LobbyTick() {
|
||||
if(restart_phase == RESTART_PHASE_PREPARE || restart_phase == RESTART_PHASE_COMMIT) {
|
||||
if(++restart_ticks >= RESTART_ACK_TIMEOUT_TICKS) {
|
||||
if(host_player)
|
||||
SendRestartStatus(host_player, restart_phase, restart_id, 0, RESTART_REASON_ACK_TIMEOUT);
|
||||
ForEachParticipant([&](DuelPlayer* p, uint8_t) { SendRestarting(p, RESTART_PHASE_ABORT, nullptr); });
|
||||
ClearRestart();
|
||||
}
|
||||
}
|
||||
if(has_restart_plan && reserve_ticks > 0 && --reserve_ticks == 0)
|
||||
ExpireReservations();
|
||||
if(restart_phase == 0 && !has_restart_plan)
|
||||
NetServer::StopDuelTimer();
|
||||
}
|
||||
void SingleDuel::ExpireReservations() {
|
||||
bool changed = false;
|
||||
for(int i = 0; i < 2; ++i)
|
||||
if(!players[i] && seat_kind[i] == SEAT_KIND_RESERVED) {
|
||||
seat_kind[i] = SEAT_KIND_OPEN;
|
||||
std::memset(seat_token[i], 0, SEAT_TOKEN_LEN);
|
||||
changed = true;
|
||||
}
|
||||
has_restart_plan = false;
|
||||
if(changed)
|
||||
BroadcastSeatPlan();
|
||||
}
|
||||
void SingleDuel::JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) {
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
bool is_recorder = false;
|
||||
@@ -263,18 +503,46 @@ void SingleDuel::JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater)
|
||||
// YGOL host seats: a claim is honoured exactly or refused, never dropped into the next free seat
|
||||
int seat = -1;
|
||||
bool claimed = false;
|
||||
if(dp->has_seat_request) {
|
||||
bool resumed_observer = false;
|
||||
// YGOL rules restart: a frozen room admits nobody; a closed replacement server admits only the bootstrap secret's holder
|
||||
bool refuse = restart_phase != 0;
|
||||
if(!refuse && bootstrap_closed) {
|
||||
const auto& req = dp->seat_request;
|
||||
if(dp->has_seat_request && !IsZeroId(bootstrap_secret) && !IsZeroId(req.restart_id)
|
||||
&& std::memcmp(req.token, bootstrap_secret, SEAT_TOKEN_LEN) == 0 && (req.seat == SEAT_WATCHERS || req.seat < 2)) {
|
||||
dp->has_seat_request = false;
|
||||
std::memset(bootstrap_secret, 0, sizeof bootstrap_secret); // one use
|
||||
std::memcpy(restart_id, req.restart_id, sizeof restart_id);
|
||||
has_restart_id = true;
|
||||
dp->ygol_bootstrap = true;
|
||||
if(req.seat < 2) {
|
||||
seat = req.seat;
|
||||
claimed = true;
|
||||
dp->ygol_restoring = true;
|
||||
}
|
||||
} else
|
||||
refuse = true;
|
||||
}
|
||||
if(!refuse && dp->has_seat_request) {
|
||||
dp->has_seat_request = false;
|
||||
seat = ClaimedSeat(dp);
|
||||
if(seat < 0) {
|
||||
STOC_ErrorMsg scem;
|
||||
scem.msg = ERRMSG_JOINERROR;
|
||||
scem.code = 0;
|
||||
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
|
||||
NetServer::DisconnectAfterFlush(dp);
|
||||
return;
|
||||
if(seat == -2) {
|
||||
seat = -1;
|
||||
resumed_observer = true;
|
||||
} else if(seat < 0)
|
||||
refuse = true;
|
||||
else {
|
||||
claimed = true;
|
||||
dp->ygol_restoring = !IsZeroId(dp->seat_request.restart_id);
|
||||
}
|
||||
claimed = true;
|
||||
}
|
||||
if(refuse) {
|
||||
STOC_ErrorMsg scem;
|
||||
scem.msg = ERRMSG_JOINERROR;
|
||||
scem.code = 0;
|
||||
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
|
||||
NetServer::DisconnectAfterFlush(dp);
|
||||
return;
|
||||
}
|
||||
if(!is_creater) {
|
||||
if(dp->game && dp->type != 0xff) {
|
||||
@@ -301,6 +569,7 @@ void SingleDuel::JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater)
|
||||
wchar_t jpass[20];
|
||||
BufferIO::NullTerminate(pkt->pass);
|
||||
BufferIO::CopyCharArray(pkt->pass, jpass);
|
||||
// stub: password -- compare jpass with the room's password here (TICKET-286; owner: stubs only, 2026-10-05)
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(!std::wcscmp(jpass, L"the Big Brother") && !cache_recorder) {
|
||||
is_recorder = true;
|
||||
@@ -322,8 +591,25 @@ void SingleDuel::JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater)
|
||||
}
|
||||
#endif //YGOPRO_SERVER_MODE
|
||||
}
|
||||
if(!claimed)
|
||||
if(!claimed && !resumed_observer)
|
||||
seat = FreeOpenSeat(); // YGOL host seats: the lowest empty Open seat, never a Cpu one
|
||||
// YGOL rules restart: watchers off refuses every observer but the room's host and a watcher resuming with its token
|
||||
bool empty_room = observers.size() == 0;
|
||||
for(int i = 0; i < 2; ++i)
|
||||
if(players[i])
|
||||
empty_room = false;
|
||||
if(seat < 0 && !dp->ygol_bootstrap && !resumed_observer && !empty_room && !WatchersAllowed()
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
&& !is_recorder
|
||||
#endif
|
||||
) {
|
||||
STOC_ErrorMsg scem;
|
||||
scem.msg = ERRMSG_JOINERROR;
|
||||
scem.code = 0;
|
||||
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
|
||||
NetServer::DisconnectAfterFlush(dp);
|
||||
return;
|
||||
}
|
||||
dp->game = this;
|
||||
if(!players[0] && !players[1] && observers.size() == 0)
|
||||
host_player = dp;
|
||||
@@ -359,7 +645,7 @@ void SingleDuel::JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater)
|
||||
players[seat] = dp;
|
||||
dp->type = (uint8_t)seat;
|
||||
sctc.type |= seat;
|
||||
dp->ygol_cpu = claimed;
|
||||
dp->ygol_cpu = claimed && seat_kind[seat] == SEAT_KIND_CPU; // YGOL rules restart: a reserved human is not a CPU
|
||||
} else {
|
||||
observers.insert(dp);
|
||||
dp->type = NETPLAYER_TYPE_OBSERVER;
|
||||
@@ -529,7 +815,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
|
||||
}
|
||||
}
|
||||
void SingleDuel::ToDuelist(DuelPlayer* dp) {
|
||||
if(dp->type != NETPLAYER_TYPE_OBSERVER)
|
||||
if(dp->type != NETPLAYER_TYPE_OBSERVER || restart_phase != 0)
|
||||
return;
|
||||
const int seat = FreeOpenSeat(); // YGOL host seats: the lowest empty Open seat, never a Cpu one
|
||||
if(seat < 0)
|
||||
@@ -570,7 +856,9 @@ void SingleDuel::SeatObserver(DuelPlayer* dp, int seat) {
|
||||
NetServer::SendPacketToPlayer(dp, STOC_TYPE_CHANGE, sctc);
|
||||
}
|
||||
void SingleDuel::ToObserver(DuelPlayer* dp) {
|
||||
if(dp->type > 1)
|
||||
if(dp->type > 1 || restart_phase != 0)
|
||||
return;
|
||||
if(!WatchersAllowed() && dp != host_player) // YGOL rules restart: watchers off is enforced here too
|
||||
return;
|
||||
STOC_HS_PlayerChange scpc;
|
||||
scpc.status = (dp->type << 4) | PLAYERCHANGE_OBSERVE;
|
||||
@@ -600,6 +888,8 @@ void SingleDuel::PlayerReady(DuelPlayer* dp, bool is_ready) {
|
||||
return;
|
||||
if(ready[dp->type] == is_ready)
|
||||
return;
|
||||
if(is_ready && dp->ygol_restoring) // YGOL rules restart: READY waits for SeatResume Complete
|
||||
return;
|
||||
if(is_ready) {
|
||||
uint32_t deckerror = 0;
|
||||
if(!host_info.no_check_deck) {
|
||||
@@ -636,7 +926,7 @@ void SingleDuel::PlayerReady(DuelPlayer* dp, bool is_ready) {
|
||||
#endif
|
||||
}
|
||||
void SingleDuel::PlayerKick(DuelPlayer* dp, unsigned char pos) {
|
||||
if(pos > 1 || dp != host_player || dp == players[pos] || !players[pos])
|
||||
if(pos > 1 || dp != host_player || dp == players[pos] || !players[pos] || restart_phase != 0)
|
||||
return;
|
||||
LeaveGame(players[pos]);
|
||||
}
|
||||
@@ -673,7 +963,8 @@ void SingleDuel::UpdateDeck(DuelPlayer* dp, unsigned char* pdata, unsigned int l
|
||||
if(duel_count == 0) {
|
||||
deck_error[dp->type] = DeckManager::LoadDeck(pdeck[dp->type], deckbuf, mainc, sidec);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
PlayerReady(dp, true);
|
||||
if(!dp->ygol_restoring) // YGOL rules restart: a returning seat readies only after SeatResume Complete
|
||||
PlayerReady(dp, true);
|
||||
#endif
|
||||
} else {
|
||||
if(DeckManager::LoadSide(pdeck[dp->type], deckbuf, mainc, sidec)) {
|
||||
@@ -698,6 +989,9 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
|
||||
return;
|
||||
if(!ready[0] || !ready[1])
|
||||
return;
|
||||
if(restart_phase != 0) // YGOL rules restart: frozen until Commit or Abort
|
||||
return;
|
||||
ygol_started = true; // YGOL rules restart: no Prepare after the first accepted START
|
||||
#ifndef YGOPRO_SERVER_MODE
|
||||
NetServer::StopListen(); // [YGOL] late watcher: the server keeps accepting so a watcher can join mid-duel
|
||||
#endif
|
||||
@@ -2666,6 +2960,10 @@ uint32_t SingleDuel::MessageHandler(intptr_t fduel, uint32_t type) {
|
||||
return 0;
|
||||
}
|
||||
void SingleDuel::TimerTick() {
|
||||
if(duel_stage == DUEL_STAGE_BEGIN) { // YGOL rules restart: the lobby's own clock
|
||||
LobbyTick();
|
||||
return;
|
||||
}
|
||||
time_elapsed++;
|
||||
if(time_elapsed >= time_limit[last_response]) {
|
||||
unsigned char wbuf[3];
|
||||
|
||||
Reference in new issue
Block a user