server: 0005-late-watcher-field-resync
TICKET-152: the server keeps listening after StartDuel and a late observer gets STOC_DUEL_START plus the field resync. Replayed from Tools/YGOLegacy/patches/0005-late-watcher-field-resync.patch in the Unity repo. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
6480fd778d
commit
d84fab84ed
2 files changed
+86
-8
No files matched your search
@@ -175,6 +175,18 @@ void SingleDuel::JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater)
|
||||
scwc.watch_count = (unsigned short)observers.size();
|
||||
NetServer::SendPacketToPlayer(dp, STOC_HS_WATCH_CHANGE, scwc);
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
// [YGOL] late watcher: a joiner after StartDuel is an observer with no board.
|
||||
if(dp->type == NETPLAYER_TYPE_OBSERVER && duel_stage != DUEL_STAGE_BEGIN) {
|
||||
dp->state = CTOS_LEAVE_GAME;
|
||||
if(duel_stage == DUEL_STAGE_DUELING && pduel)
|
||||
RequestField(dp);
|
||||
else if(duel_stage == DUEL_STAGE_SIDING)
|
||||
NetServer::SendPacketToPlayer(dp, STOC_WAITING_SIDE);
|
||||
else if(duel_stage != DUEL_STAGE_END)
|
||||
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void SingleDuel::LeaveGame(DuelPlayer* dp) {
|
||||
if(dp == host_player) {
|
||||
@@ -448,7 +460,9 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
|
||||
return;
|
||||
if(!ready[0] || !ready[1])
|
||||
return;
|
||||
NetServer::StopListen();
|
||||
#ifndef YGOPRO_SERVER_MODE
|
||||
NetServer::StopListen(); // [YGOL] late watcher: the server keeps accepting so a watcher can join mid-duel
|
||||
#endif
|
||||
//NetServer::StopBroadcast();
|
||||
NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START);
|
||||
NetServer::ReSendToPlayer(players[1]);
|
||||
@@ -1974,9 +1988,10 @@ void SingleDuel::WaitforResponse(int playerid) {
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
void SingleDuel::RequestField(DuelPlayer* dp) {
|
||||
if(dp->type > 1)
|
||||
const bool watcher = dp->type == NETPLAYER_TYPE_OBSERVER; // [YGOL] late watcher
|
||||
if(dp->type > 1 && !watcher)
|
||||
return;
|
||||
uint8_t player = dp->type;
|
||||
uint8_t player = watcher ? 0 : dp->type;
|
||||
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
|
||||
|
||||
uint8_t buf[1024];
|
||||
@@ -1989,7 +2004,7 @@ void SingleDuel::RequestField(DuelPlayer* dp) {
|
||||
|
||||
WriteMsg([&](uint8_t*& pbuf) {
|
||||
BufferIO::Write<uint8_t>(pbuf, MSG_START);
|
||||
BufferIO::Write<uint8_t>(pbuf, player);
|
||||
BufferIO::Write<uint8_t>(pbuf, watcher ? ((players[0] == pplayer[0]) ? 0x10 : 0x11) : player); // [YGOL] late watcher: the observer byte lobby watchers get
|
||||
BufferIO::Write<uint8_t>(pbuf, host_info.duel_rule);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
@@ -2141,6 +2156,10 @@ if(!dp || dp == players[player])
|
||||
#endif
|
||||
for(const auto& segment : hidden_segments)
|
||||
std::memset(segment.first, 0, segment.second - 4);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(!dp || dp == players[1 - player])
|
||||
#endif
|
||||
@@ -2188,6 +2207,10 @@ if(!dp || dp == players[player])
|
||||
#endif
|
||||
for(const auto& segment : hidden_segments)
|
||||
std::memset(segment.first, 0, segment.second - 4);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(!dp || dp == players[1 - player])
|
||||
#endif
|
||||
@@ -2230,6 +2253,10 @@ if(!dp || dp == players[player])
|
||||
std::memset(qbuf, 0, slen - 4);
|
||||
qbuf += slen - 4;
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(!dp || dp == players[1 - player])
|
||||
#endif
|
||||
@@ -2253,6 +2280,10 @@ void SingleDuel::RefreshGrave(int player, int flag, int use_cache)
|
||||
std::array<unsigned char, SIZE_QUERY_BUFFER> query_buffer;
|
||||
auto qbuf = query_buffer.data();
|
||||
auto len = WriteUpdateData(player, LOCATION_GRAVE, flag, qbuf, use_cache);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(!dp || dp == players[0])
|
||||
#endif
|
||||
@@ -2298,6 +2329,10 @@ if(!dp || dp == players[player])
|
||||
memset(qbuf, 0, clen - 4);
|
||||
qbuf += clen - 4;
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
if(!dp || dp == players[1 - player])
|
||||
NetServer::SendBufferToPlayer(players[1 - player], STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
if(!dp)
|
||||
@@ -2327,6 +2362,10 @@ void SingleDuel::RefreshRemoved(int player, int flag, int use_cache, DuelPlayer*
|
||||
memset(qbuf, 0, clen - 4);
|
||||
qbuf += clen - 4;
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
if(!dp || dp == players[1 - player])
|
||||
NetServer::SendBufferToPlayer(players[1 - player], STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
if(!dp)
|
||||
|
||||
@@ -157,6 +157,18 @@ void TagDuel::JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) {
|
||||
scwc.watch_count = (unsigned short)observers.size();
|
||||
NetServer::SendPacketToPlayer(dp, STOC_HS_WATCH_CHANGE, scwc);
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
// [YGOL] late watcher: a joiner after StartDuel is an observer with no board.
|
||||
if(dp->type == NETPLAYER_TYPE_OBSERVER && duel_stage != DUEL_STAGE_BEGIN) {
|
||||
dp->state = CTOS_LEAVE_GAME;
|
||||
if(duel_stage == DUEL_STAGE_DUELING && pduel)
|
||||
RequestField(dp);
|
||||
else if(duel_stage == DUEL_STAGE_SIDING)
|
||||
NetServer::SendPacketToPlayer(dp, STOC_WAITING_SIDE);
|
||||
else if(duel_stage != DUEL_STAGE_END)
|
||||
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void TagDuel::LeaveGame(DuelPlayer* dp) {
|
||||
if(dp == host_player) {
|
||||
@@ -406,7 +418,9 @@ void TagDuel::StartDuel(DuelPlayer* dp) {
|
||||
return;
|
||||
if(!ready[0] || !ready[1] || !ready[2] || !ready[3])
|
||||
return;
|
||||
NetServer::StopListen();
|
||||
#ifndef YGOPRO_SERVER_MODE
|
||||
NetServer::StopListen(); // [YGOL] late watcher: the server keeps accepting so a watcher can join mid-duel
|
||||
#endif
|
||||
//NetServer::StopBroadcast();
|
||||
for(int i = 0; i < 4; ++i)
|
||||
NetServer::SendPacketToPlayer(players[i], STOC_DUEL_START);
|
||||
@@ -2090,9 +2104,10 @@ void TagDuel::WaitforResponse(int playerid) {
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
void TagDuel::RequestField(DuelPlayer* dp) {
|
||||
if(dp->type > 3)
|
||||
const bool watcher = dp->type == NETPLAYER_TYPE_OBSERVER; // [YGOL] late watcher
|
||||
if(dp->type > 3 && !watcher)
|
||||
return;
|
||||
uint8_t player = (dp->type > 1) ? 1 : 0;
|
||||
uint8_t player = watcher ? 0 : ((dp->type > 1) ? 1 : 0);
|
||||
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
|
||||
|
||||
uint8_t buf[1024];
|
||||
@@ -2105,7 +2120,7 @@ void TagDuel::RequestField(DuelPlayer* dp) {
|
||||
|
||||
WriteMsg([&](uint8_t*& pbuf) {
|
||||
BufferIO::Write<uint8_t>(pbuf, MSG_START);
|
||||
BufferIO::Write<uint8_t>(pbuf, player);
|
||||
BufferIO::Write<uint8_t>(pbuf, watcher ? ((players[0] == pplayer[0]) ? 0x10 : 0x11) : player); // [YGOL] late watcher: the observer byte lobby watchers get
|
||||
BufferIO::Write<uint8_t>(pbuf, host_info.duel_rule);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
BufferIO::Write<int32_t>(pbuf, host_info.start_lp);
|
||||
@@ -2259,6 +2274,10 @@ if(!dp || dp == players[pid])
|
||||
#endif
|
||||
for(const auto& segment : hidden_segments)
|
||||
std::memset(segment.first, 0, segment.second - 4);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
pid = 2 - pid;
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(!dp || dp == players[pid])
|
||||
@@ -2316,6 +2335,10 @@ if(!dp || dp == players[pid])
|
||||
#endif
|
||||
for(const auto& segment : hidden_segments)
|
||||
std::memset(segment.first, 0, segment.second - 4);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
pid = 2 - pid;
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(!dp || dp == players[pid])
|
||||
@@ -2370,6 +2393,10 @@ if(!dp || dp == players[tp + 1])
|
||||
std::memset(qbuf, 0, slen - 4);
|
||||
qbuf += slen - 4;
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
// [YGOL] the masked copy goes to the OTHER team only.
|
||||
tp = 2 - tp;
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
@@ -2399,6 +2426,10 @@ void TagDuel::RefreshGrave(int player, int flag, int use_cache)
|
||||
std::array<unsigned char, SIZE_QUERY_BUFFER> query_buffer;
|
||||
auto qbuf = query_buffer.data();
|
||||
auto len = WriteUpdateData(player, LOCATION_GRAVE, flag, qbuf, use_cache);
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
for(int i = 0; i < 4; ++i)
|
||||
if(!dp || dp == players[i])
|
||||
@@ -2450,6 +2481,10 @@ if(!dp || dp == players[tp + 1])
|
||||
memset(qbuf, 0, clen - 4);
|
||||
qbuf += clen - 4;
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
// [YGOL] the masked copy goes to the OTHER team only.
|
||||
tp = 2 - tp;
|
||||
if(!dp || dp == players[tp])
|
||||
@@ -2486,6 +2521,10 @@ void TagDuel::RefreshRemoved(int player, int flag, int use_cache, DuelPlayer* dp
|
||||
memset(qbuf, 0, clen - 4);
|
||||
qbuf += clen - 4;
|
||||
}
|
||||
#ifdef YGOPRO_SERVER_MODE
|
||||
if(dp && dp->type == NETPLAYER_TYPE_OBSERVER) // [YGOL] late watcher: the masked copy observers always get
|
||||
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
#endif
|
||||
pid = 2 - pid;
|
||||
if(!dp || dp == players[pid])
|
||||
NetServer::SendBufferToPlayer(players[pid], STOC_GAME_MSG, query_buffer.data(), len + 3);
|
||||
|
||||
Reference in new issue
Block a user