server: 0023-attack-preview-server
TICKET-378: the attack preview over the wire. CTOS/STOC 0x5E: the seat whose battle prompt is open asks for pairs, the host answers from its embedded core (ygol_preview_attack). Capability bit 0x400, protocol 8. Replayed from Tools/YGOLegacy/patches/0023-attack-preview-server.patch in the Unity repo. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
b7c5cb2467
commit
3993b8c5e5
7 files changed
+89
-4
No files matched your search
@@ -500,6 +500,15 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, size_t len
|
||||
duel_mode->Profile(dp, pdata, len - 1);
|
||||
break;
|
||||
}
|
||||
// YGOL attack preview: header + exactly count pairs, or dropped
|
||||
case CTOS_ATTACK_PREVIEW: {
|
||||
if(!dp->game || !duel_mode->pduel)
|
||||
return;
|
||||
if (len < 1 + 2 || len != 1 + 2 + pdata[1] * sizeof(CTOS_AttackPreviewPair))
|
||||
return;
|
||||
duel_mode->AttackPreview(dp, pdata, len - 1);
|
||||
break;
|
||||
}
|
||||
case CTOS_UPDATE_DECK: {
|
||||
if(!dp->game)
|
||||
return;
|
||||
@@ -690,6 +699,35 @@ size_t NetServer::CreateStampedPacket(unsigned char* src, int src_size, unsigned
|
||||
std::memcpy(pdst, src, src_size);
|
||||
return sizeof(dst_player_type) + src_size;
|
||||
}
|
||||
// YGOL attack preview: one answer per pair the open battle prompt could offer and the engine agrees to preview; the
|
||||
// rest are left out, so the count is the number of answers. A header the client got wrong is dropped whole.
|
||||
void NetServer::AnswerAttackPreview(DuelPlayer* dp, intptr_t pduel, uint8_t playerid, const std::vector<uint16_t>& attackers, unsigned char* pdata, int len) {
|
||||
if(len < 2 || pdata[0] != ATTACK_PREVIEW_VERSION)
|
||||
return;
|
||||
const int count = pdata[1];
|
||||
if(count == 0 || count > ATTACK_PREVIEW_MAX_PAIRS || len != 2 + count * (int)sizeof(CTOS_AttackPreviewPair))
|
||||
return;
|
||||
std::vector<unsigned char> buf;
|
||||
buf.reserve(2 + count * (sizeof(CTOS_AttackPreviewPair) + ATTACK_PREVIEW_ANSWER_SIZE));
|
||||
buf.push_back(ATTACK_PREVIEW_VERSION);
|
||||
buf.push_back(0);
|
||||
uint8_t answered = 0;
|
||||
for(int i = 0; i < count; ++i) {
|
||||
CTOS_AttackPreviewPair pair;
|
||||
std::memcpy(&pair, pdata + 2 + i * sizeof pair, sizeof pair);
|
||||
const uint16_t attacker = (uint16_t)(pair.attacker_location << 8 | pair.attacker_sequence);
|
||||
if(std::find(attackers.begin(), attackers.end(), attacker) == attackers.end())
|
||||
continue;
|
||||
unsigned char answer[ATTACK_PREVIEW_ANSWER_SIZE];
|
||||
if(ygol_preview_attack(pduel, playerid, pair.attacker_location, pair.attacker_sequence, pair.target_location, pair.target_sequence, answer) != 1)
|
||||
continue;
|
||||
buf.insert(buf.end(), (unsigned char*)&pair, (unsigned char*)&pair + sizeof pair);
|
||||
buf.insert(buf.end(), answer, answer + sizeof answer);
|
||||
++answered;
|
||||
}
|
||||
buf[1] = answered;
|
||||
SendBufferToPlayer(dp, STOC_ATTACK_PREVIEW, buf.data(), buf.size());
|
||||
}
|
||||
// YGOL setup pairs
|
||||
std::vector<std::string> setup_pairs;
|
||||
bool IsSetupPairToken(const char* token) {
|
||||
|
||||
Reference in new issue
Block a user