The room's "Life Points - Side B" field had nowhere to go: the host string
carries ONE start LP and the server gave it to both duel players. Now the
setup pair ygol.side.b.lp=<n> gives seat side B (seat 1; Tag seats 2 and 3)
its own start LP while side A keeps slot 8; absent, both sides start at
slot 8 exactly as before.
- SideBStartLp(fallback) reads the pair (positive integer, else fallback).
- single_duel / tag_duel keep player_lp[2] in DUEL PLAYER order, so the
side that goes first keeps its own LP through the first-turn swap, in
every duel of a Match: set_player_info per player, MSG_START at the
start and in the late-watcher snapshot carry lp[0], lp[1].
- Replay flag REPLAY_YGOL_SIDE_LP 0x20000000: set only when the two
differ; i32 lp[0], i32 lp[1] follow opt, before the decks. The binding
gets ReplayFlags { SetupPairs, SideLp } for the readers.
- Probe: two more setup-pair rooms (Single and Tag) check MSG_START on
every seat in duel player order and the replay's flag + values; every
other room's replay must have no such flag.
- Contract: slot 8 row, the behaviour table, the Replay section, the
server-read pairs table (three now), the binding row; CHANGELOG v1.4.0.
No new export or capability bit: exports 335 / 856 / 850, protocol 9,
capabilities 0x27FF.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
187 lines
7.2 KiB
C++
187 lines
7.2 KiB
C++
#ifndef SINGLE_DUEL_H
|
|
#define SINGLE_DUEL_H
|
|
|
|
#include <set>
|
|
#include "network.h"
|
|
#include "deck.h"
|
|
#include "replay.h"
|
|
|
|
namespace ygo {
|
|
|
|
class SingleDuel: public DuelMode {
|
|
public:
|
|
SingleDuel(bool is_match);
|
|
~SingleDuel() override;
|
|
void Chat(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
// YGOL feature messages
|
|
void Capability(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void Appearance(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void Dialogue(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
// YGOL host seats
|
|
void SeatPlan(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void SeatSwap(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void SeatMove(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
// YGOL rules restart
|
|
void RestartPrepare(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void RestartAck(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void RestartControl(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void SeatResume(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
void RestartOpen(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
// YGOL seat state
|
|
void SeatState(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
// YGOL profile
|
|
void Profile(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
// YGOL attack preview
|
|
void AttackPreview(DuelPlayer* dp, unsigned char* pdata, int len) override;
|
|
// YGOL coin toss
|
|
void ChooseTimeout() override;
|
|
void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) override;
|
|
void LeaveGame(DuelPlayer* dp) override;
|
|
void ToDuelist(DuelPlayer* dp) override;
|
|
void ToObserver(DuelPlayer* dp) override;
|
|
void PlayerReady(DuelPlayer* dp, bool is_ready) override;
|
|
void PlayerKick(DuelPlayer* dp, unsigned char pos) override;
|
|
void UpdateDeck(DuelPlayer* dp, unsigned char* pdata, unsigned int len) override;
|
|
void StartDuel(DuelPlayer* dp) override;
|
|
void HandResult(DuelPlayer* dp, unsigned char res) override;
|
|
void TPResult(DuelPlayer* dp, unsigned char tp) override;
|
|
void Process() override;
|
|
void Surrender(DuelPlayer* dp) override;
|
|
int Analyze(unsigned char* msgbuffer, unsigned int len) override;
|
|
void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) override;
|
|
void TimeConfirm(DuelPlayer* dp) override;
|
|
#ifdef YGOPRO_SERVER_MODE
|
|
void RequestField(DuelPlayer* dp) override;
|
|
#endif
|
|
void TimerTick() override;
|
|
void EndDuel() override;
|
|
void OnPlayerDisconnected(DuelPlayer* dp) override;
|
|
#ifdef YGOPRO_SERVER_MODE
|
|
void TestCard(int code) override;
|
|
#endif
|
|
|
|
void DuelEndProc();
|
|
// YGOL lobby after match
|
|
void SendDuelEnd();
|
|
void ReturnToLobby();
|
|
void SendMatchOver();
|
|
void SeatLeft(DuelPlayer* dp);
|
|
void WaitforResponse(int playerid);
|
|
#ifdef YGOPRO_SERVER_MODE
|
|
void RefreshMzone(int player, int flag = 0x881fff, int use_cache = 1, DuelPlayer* dp = 0);
|
|
void RefreshSzone(int player, int flag = 0xe81fff, int use_cache = 1, DuelPlayer* dp = 0);
|
|
void RefreshHand(int player, int flag = 0x681fff, int use_cache = 1, DuelPlayer* dp = 0);
|
|
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1, DuelPlayer* dp = 0);
|
|
void RefreshExtra(int player, int flag = 0xe81fff, int use_cache = 1, DuelPlayer* dp = 0);
|
|
void RefreshRemoved(int player, int flag = 0x81fff, int use_cache = 1, DuelPlayer* dp = 0);
|
|
#else
|
|
void RefreshMzone(int player, int flag = 0x881fff, int use_cache = 1);
|
|
void RefreshSzone(int player, int flag = 0xe81fff, int use_cache = 1);
|
|
void RefreshHand(int player, int flag = 0x681fff, int use_cache = 1);
|
|
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1);
|
|
void RefreshExtra(int player, int flag = 0xe81fff, int use_cache = 1);
|
|
#endif
|
|
void RefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
|
|
|
|
static uint32_t MessageHandler(intptr_t fduel, uint32_t type);
|
|
private:
|
|
int WriteUpdateData(int player, int location, unsigned int flag, unsigned char*& qbuf, int use_cache);
|
|
|
|
protected:
|
|
// YGOL feature messages
|
|
void BroadcastFeature(unsigned char proto, unsigned char* pdata, int len, uint16_t sender);
|
|
void SendServerCapability(DuelPlayer* dp);
|
|
void SendSeatFeatures(DuelPlayer* dp, int seat);
|
|
bool has_appearance[2]{};
|
|
CTOS_Appearance appearance[2]{};
|
|
CTOS_SeatState seat_state[2]{}; // YGOL seat state
|
|
// YGOL profile
|
|
bool has_profile[2]{};
|
|
CTOS_Profile profile[2]{};
|
|
std::vector<uint16_t> preview_attackers; // YGOL attack preview: location << 8 | sequence of every attacker the open battle prompt lists
|
|
void BeginChoose(int chooser, uint8_t face); // YGOL coin toss
|
|
// YGOL deck lists
|
|
void MarkDeckLists();
|
|
void ResetDeckLists();
|
|
void FlushDeckLists();
|
|
bool BuildDeckList(int side, uint8_t kind, std::vector<uint32_t>& codes);
|
|
void SendDeckList(DuelPlayer* dp, int side, uint8_t kind, const std::vector<uint32_t>& codes);
|
|
std::vector<uint32_t> deck_list_sent[2][DECK_LIST_KINDS];
|
|
bool deck_list_known[2][DECK_LIST_KINDS]{};
|
|
bool deck_list_dirty{};
|
|
// YGOL host seats
|
|
void SendToLobby(unsigned char proto, void* buffer, size_t len);
|
|
size_t SeatPlanPacket(unsigned char* buf, uint16_t revision);
|
|
void SendSeatPlan(DuelPlayer* dp, uint16_t revision);
|
|
void BroadcastSeatPlan();
|
|
void BroadcastSeatFeatures(int seat);
|
|
int FreeOpenSeat();
|
|
int ClaimedSeat(DuelPlayer* dp);
|
|
void ClearSeatPlan();
|
|
void SeatObserver(DuelPlayer* dp, int seat);
|
|
void SwapSeats(int first, int second);
|
|
uint8_t seat_kind[2]{};
|
|
uint8_t seat_token[2][16]{};
|
|
uint16_t seat_revision{};
|
|
bool has_seat_plan{};
|
|
// YGOL rules restart
|
|
template<typename F> void ForEachParticipant(F f);
|
|
bool RestartCompatible();
|
|
void SendRestarting(DuelPlayer* dp, uint8_t phase, const uint8_t* token);
|
|
void SendRestartStatus(DuelPlayer* dp, uint8_t phase, const uint8_t* id, uint8_t complete, uint8_t reason);
|
|
void SendResumeResult(DuelPlayer* dp, const uint8_t* id, bool accepted, uint8_t reason);
|
|
void ClearRestart();
|
|
void LobbyTick();
|
|
void ExpireReservations();
|
|
uint8_t restart_id[16]{};
|
|
bool has_restart_id{};
|
|
uint8_t restart_phase{};
|
|
uint32_t restart_ticks{};
|
|
uint32_t restart_timeout_ms{};
|
|
uint8_t restart_seat_token[2][16]{};
|
|
uint8_t restart_observer_token[16]{};
|
|
uint8_t observer_token[16]{};
|
|
bool has_observer_token{};
|
|
bool has_restart_plan{};
|
|
uint32_t reserve_ticks{};
|
|
bool ygol_started{};
|
|
DuelPlayer* players[2]{};
|
|
DuelPlayer* pplayer[2]{};
|
|
int32_t player_lp[2]{}; // YGOL life points per side: start LP in duel player order, set at every duel start
|
|
bool ready[2]{};
|
|
Deck pdeck[2];
|
|
int deck_error[2]{};
|
|
unsigned char hand_result[2]{};
|
|
unsigned char last_response{ 0 };
|
|
std::set<DuelPlayer*> observers;
|
|
#ifdef YGOPRO_SERVER_MODE
|
|
DuelPlayer* cache_recorder{};
|
|
DuelPlayer* replay_recorder{};
|
|
unsigned char turn_player{ 0 };
|
|
unsigned short phase{ 0 };
|
|
bool deck_reversed{ false };
|
|
#endif
|
|
Replay last_replay;
|
|
size_t last_replay_response_size{ 0 };
|
|
bool match_mode{ false };
|
|
int match_kill{ 0 };
|
|
unsigned char duel_count{ 0 };
|
|
unsigned char tp_player{ 0 };
|
|
#ifdef YGOPRO_SERVER_MODE
|
|
unsigned char match_result[5]{};
|
|
#else
|
|
unsigned char match_result[3]{};
|
|
#endif
|
|
uint16_t time_limit[2]{};
|
|
uint16_t time_elapsed{ 0 };
|
|
#ifdef YGOPRO_SERVER_MODE
|
|
uint32_t time_compensator[2]{};
|
|
uint16_t time_backed[2]{};
|
|
unsigned char last_game_msg{ 0 };
|
|
#endif
|
|
};
|
|
|
|
}
|
|
|
|
#endif //SINGLE_DUEL_H
|