server: 0017-coin-toss

TICKET-328: the server rolls the coin: STOC 0x5B to every seat and watcher, the stock SELECT_TP to the chooser, a one-shot 10 s timer that answers FIRST for them; game 2+ sends face 0xFF. Capability bit 0x80, protocol 5.

Replayed from Tools/YGOLegacy/patches/0017-coin-toss.patch in the Unity repo.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
donnyandClaude Fable 5.1 committed 2026-10-14 20:58:58 -07:00
1 parent 06391120b5
commit 2c081162ff
7 files changed
+132 -105

No files matched your search

+21
View File
@@ -19,6 +19,7 @@ namespace{
event_base* net_evbase{};
event* broadcast_ev{};
event* duel_etimer{};
event* choose_etimer{}; // YGOL coin toss
evconnlistener* listener{};
DuelMode* duel_mode{};
bool broadcast_enabled{};
@@ -27,6 +28,10 @@ namespace{
void DuelTimer(EventSocket, short, void* arg) {
static_cast<DuelMode*>(arg)->TimerTick();
}
// YGOL coin toss: the first-turn choice ran out of time
void ChooseTimer(EventSocket, short, void* arg) {
static_cast<DuelMode*>(arg)->ChooseTimeout();
}
}
unsigned char NetServer::net_server_write[SIZE_NETWORK_BUFFER]{};
@@ -190,6 +195,19 @@ void NetServer::StopDuelTimer() {
if(duel_etimer)
event_del(duel_etimer);
}
// YGOL coin toss: one shot, armed when SELECT_TP goes out; dropped by TPResult, the lobby reset and the duel end
void NetServer::StartChooseTimer(int seconds) {
if(!net_evbase || !duel_mode)
return;
if(!choose_etimer)
choose_etimer = evtimer_new(net_evbase, ChooseTimer, duel_mode);
timeval timeout = { seconds, 0 };
evtimer_add(choose_etimer, &timeout);
}
void NetServer::StopChooseTimer() {
if(choose_etimer)
evtimer_del(choose_etimer);
}
void NetServer::BroadcastEvent(EventSocket fd, short events, void* arg) {
sockaddr_in bc_addr;
socklen_t sz = sizeof(sockaddr_in);
@@ -286,6 +304,9 @@ void NetServer::ServerThread() {
if(duel_etimer)
event_free(duel_etimer);
duel_etimer = nullptr;
if(choose_etimer) // YGOL coin toss
event_free(choose_etimer);
choose_etimer = nullptr;
if(duel_mode)
delete duel_mode;
duel_mode = nullptr;