diff --git a/server/gframe/netserver.cpp b/server/gframe/netserver.cpp index 539a8c4..89ccb88 100644 --- a/server/gframe/netserver.cpp +++ b/server/gframe/netserver.cpp @@ -491,6 +491,15 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, size_t len duel_mode->SeatState(dp, pdata, len - 1); break; } + // YGOL profile: exact size or dropped + case CTOS_PROFILE: { + if(!dp->game) + return; + if (len != 1 + sizeof(CTOS_Profile)) + return; + duel_mode->Profile(dp, pdata, len - 1); + break; + } case CTOS_UPDATE_DECK: { if(!dp->game) return; diff --git a/server/gframe/network.h b/server/gframe/network.h index a01672c..bfde1fe 100644 --- a/server/gframe/network.h +++ b/server/gframe/network.h @@ -224,7 +224,7 @@ static_assert(sizeof(CTOS_Appearance) == 352, "size mismatch: CTOS_Appearance"); check_trivially_copyable(CTOS_Dialogue); static_assert(sizeof(CTOS_Dialogue) == 204, "size mismatch: CTOS_Dialogue"); constexpr int SIZE_STOC_FEATURE = sizeof(uint16_t) + sizeof(CTOS_Appearance); -constexpr uint16_t FEATURE_PROTOCOL = 6; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6 +constexpr uint16_t FEATURE_PROTOCOL = 7; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6; YGOL profile: 6 -> 7 constexpr uint32_t FEATURE_APPEARANCE = 0x1; constexpr uint32_t FEATURE_DIALOGUE = 0x2; constexpr uint16_t FEATURE_SENDER_SERVER = 0xff; @@ -433,6 +433,19 @@ constexpr uint8_t DECK_LIST_SORTED = 0; constexpr uint8_t DECK_LIST_ORDERED = 1; constexpr uint8_t DECK_LIST_SUBMITTED = 2; constexpr int DECK_LIST_KINDS = 3; +// YGOL profile: a seated duelist's avatar id and frame id; stored per seat and replayed to joiners like appearance +#pragma pack(push, 1) +struct CTOS_Profile { + uint8_t version{}; + uint8_t reserved{}; + uint16_t avatar_id[32]{}; + uint16_t frame_id[16]{}; +}; +#pragma pack(pop) +check_trivially_copyable(CTOS_Profile); +static_assert(sizeof(CTOS_Profile) == 98, "size mismatch: CTOS_Profile"); +constexpr uint32_t FEATURE_PROFILE = 0x200; +constexpr uint8_t PROFILE_VERSION = 1; // the one-use bootstrap secret of a replacement server: a host-string token parsed apart from the ygol.* pairs, never stored anywhere else extern uint8_t bootstrap_secret[16]; extern bool bootstrap_closed; @@ -492,6 +505,8 @@ public: virtual void RestartOpen(DuelPlayer* dp, unsigned char* pdata, int len) = 0; // YGOL seat state virtual void SeatState(DuelPlayer* dp, unsigned char* pdata, int len) = 0; + // YGOL profile + virtual void Profile(DuelPlayer* dp, unsigned char* pdata, int len) = 0; // YGOL coin toss virtual void ChooseTimeout() = 0; virtual void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) = 0; @@ -578,12 +593,15 @@ public: #define CTOS_RESTART_OPEN 0x58 // CTOS_RestartOpen, bootstrap host only // YGOL seat state #define CTOS_SEAT_STATE 0x59 // CTOS_SeatState, own seat only +// YGOL profile +#define CTOS_PROFILE 0x5D // CTOS_Profile, own seat only inline bool IsFeatureMessage(unsigned char pktType) { return pktType == CTOS_CAPABILITY || pktType == CTOS_APPEARANCE || pktType == CTOS_DIALOGUE || pktType == CTOS_SEAT_PLAN || pktType == CTOS_SEAT_REQUEST || pktType == CTOS_SEAT_SWAP || pktType == CTOS_SEAT_MOVE // YGOL host seats || pktType == CTOS_RESTART_PREPARE || pktType == CTOS_RESTART_ACK || pktType == CTOS_RESTART_CONTROL || pktType == CTOS_SEAT_RESUME || pktType == CTOS_RESTART_OPEN // YGOL rules restart - || pktType == CTOS_SEAT_STATE; // YGOL seat state + || pktType == CTOS_SEAT_STATE // YGOL seat state + || pktType == CTOS_PROFILE; // YGOL profile } #define STOC_GAME_MSG 0x1 // byte array @@ -625,6 +643,7 @@ inline bool IsFeatureMessage(unsigned char pktType) { #define STOC_MATCH_OVER 0x5A // uint16_t 0xFF + STOC_MatchOver (YGOL lobby after match) #define STOC_COIN_TOSS 0x5B // STOC_CoinToss, no sender stamp (YGOL coin toss) #define STOC_DECK_LIST 0x5C // STOC_DeckList + uint32_t codes[count], no sender stamp (YGOL deck lists) +#define STOC_PROFILE 0x5D // uint16_t + CTOS_Profile (YGOL profile) // STOC_GAME_MSG header #define MSG_WAITING 3 diff --git a/server/gframe/single_duel.cpp b/server/gframe/single_duel.cpp index ef0043a..fc2bbd0 100644 --- a/server/gframe/single_duel.cpp +++ b/server/gframe/single_duel.cpp @@ -77,10 +77,22 @@ void SingleDuel::SeatState(DuelPlayer* dp, unsigned char* pdata, int len) { seat_state[dp->type] = state; BroadcastFeature(STOC_SEAT_STATE, pdata, len, dp->type); } +// YGOL profile: a seated human says which avatar and frame it shows; kept per seat, cleared with the seat, kept across matches +void SingleDuel::Profile(DuelPlayer* dp, unsigned char* pdata, int len) { + if(dp->type > 1 || dp->ygol_cpu) + return; + CTOS_Profile sent; + std::memcpy(&sent, pdata, sizeof sent); + if(sent.version != PROFILE_VERSION) + return; + profile[dp->type] = sent; + has_profile[dp->type] = true; + BroadcastFeature(STOC_PROFILE, pdata, len, dp->type); +} void SingleDuel::SendServerCapability(DuelPlayer* dp) { CTOS_Capability cap; cap.protocol = FEATURE_PROTOCOL; - cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile 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); @@ -99,6 +111,10 @@ void SingleDuel::SendSeatFeatures(DuelPlayer* dp, int seat) { const auto size = NetServer::CreateStampedPacket((unsigned char*)&seat_state[seat], sizeof seat_state[seat], buf, (uint16_t)seat); NetServer::SendBufferToPlayer(dp, STOC_SEAT_STATE, buf, size); } + if(has_profile[seat]) { // YGOL profile + const auto size = NetServer::CreateStampedPacket((unsigned char*)&profile[seat], sizeof profile[seat], buf, (uint16_t)seat); + NetServer::SendBufferToPlayer(dp, STOC_PROFILE, buf, size); + } } // YGOL host seats void SingleDuel::SendToLobby(unsigned char proto, void* buffer, size_t len) { @@ -141,6 +157,10 @@ void SingleDuel::BroadcastSeatFeatures(int seat) { const auto size = NetServer::CreateStampedPacket((unsigned char*)&seat_state[seat], sizeof seat_state[seat], buf, (uint16_t)seat); SendToLobby(STOC_SEAT_STATE, buf, size); } + if(has_profile[seat]) { // YGOL profile + const auto size = NetServer::CreateStampedPacket((unsigned char*)&profile[seat], sizeof profile[seat], buf, (uint16_t)seat); + SendToLobby(STOC_PROFILE, buf, size); + } } int SingleDuel::FreeOpenSeat() { for(int i = 0; i < 2; ++i) @@ -272,6 +292,8 @@ void SingleDuel::SwapSeats(int first, int second) { std::swap(appearance[first], appearance[second]); std::swap(has_appearance[first], has_appearance[second]); std::swap(seat_state[first], seat_state[second]); // YGOL seat state + std::swap(profile[first], profile[second]); // YGOL profile + std::swap(has_profile[first], has_profile[second]); std::swap(seat_kind[first], seat_kind[second]); uint8_t token[SEAT_TOKEN_LEN]; std::memcpy(token, seat_token[first], SEAT_TOKEN_LEN); @@ -894,6 +916,7 @@ void SingleDuel::SeatLeft(DuelPlayer* dp) { ready[dp->type] = false; has_appearance[dp->type] = false; // YGOL feature messages seat_state[dp->type] = CTOS_SeatState{}; // YGOL seat state + has_profile[dp->type] = false; // YGOL profile scpc.status = (dp->type << 4) | PLAYERCHANGE_LEAVE; if(players[0] && dp->type != 0) NetServer::SendPacketToPlayer(players[0], STOC_HS_PLAYER_CHANGE, scpc); @@ -972,6 +995,7 @@ void SingleDuel::ToObserver(DuelPlayer* dp) { ready[dp->type] = false; has_appearance[dp->type] = false; // YGOL feature messages seat_state[dp->type] = CTOS_SeatState{}; // YGOL seat state + has_profile[dp->type] = false; // YGOL profile dp->type = NETPLAYER_TYPE_OBSERVER; observers.insert(dp); STOC_TypeChange sctc; diff --git a/server/gframe/single_duel.h b/server/gframe/single_duel.h index 51eb661..73a3e49 100644 --- a/server/gframe/single_duel.h +++ b/server/gframe/single_duel.h @@ -29,6 +29,8 @@ public: 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 coin toss void ChooseTimeout() override; void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) override; @@ -91,6 +93,9 @@ protected: 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]{}; void BeginChoose(int chooser, uint8_t face); // YGOL coin toss // YGOL deck lists void MarkDeckLists(); diff --git a/server/gframe/tag_duel.cpp b/server/gframe/tag_duel.cpp index ad5c7af..daf67a6 100644 --- a/server/gframe/tag_duel.cpp +++ b/server/gframe/tag_duel.cpp @@ -75,10 +75,22 @@ void TagDuel::SeatState(DuelPlayer* dp, unsigned char* pdata, int len) { seat_state[dp->type] = state; BroadcastFeature(STOC_SEAT_STATE, pdata, len, dp->type); } +// YGOL profile: a seated human says which avatar and frame it shows; kept per seat, cleared with the seat, kept across matches +void TagDuel::Profile(DuelPlayer* dp, unsigned char* pdata, int len) { + if(dp->type > 3 || dp->ygol_cpu) + return; + CTOS_Profile sent; + std::memcpy(&sent, pdata, sizeof sent); + if(sent.version != PROFILE_VERSION) + return; + profile[dp->type] = sent; + has_profile[dp->type] = true; + BroadcastFeature(STOC_PROFILE, pdata, len, dp->type); +} void TagDuel::SendServerCapability(DuelPlayer* dp) { CTOS_Capability cap; cap.protocol = FEATURE_PROTOCOL; - cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile 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); @@ -97,6 +109,10 @@ void TagDuel::SendSeatFeatures(DuelPlayer* dp, int seat) { const auto size = NetServer::CreateStampedPacket((unsigned char*)&seat_state[seat], sizeof seat_state[seat], buf, (uint16_t)seat); NetServer::SendBufferToPlayer(dp, STOC_SEAT_STATE, buf, size); } + if(has_profile[seat]) { // YGOL profile + const auto size = NetServer::CreateStampedPacket((unsigned char*)&profile[seat], sizeof profile[seat], buf, (uint16_t)seat); + NetServer::SendBufferToPlayer(dp, STOC_PROFILE, buf, size); + } } // YGOL host seats void TagDuel::SendToLobby(unsigned char proto, void* buffer, size_t len) { @@ -139,6 +155,10 @@ void TagDuel::BroadcastSeatFeatures(int seat) { const auto size = NetServer::CreateStampedPacket((unsigned char*)&seat_state[seat], sizeof seat_state[seat], buf, (uint16_t)seat); SendToLobby(STOC_SEAT_STATE, buf, size); } + if(has_profile[seat]) { // YGOL profile + const auto size = NetServer::CreateStampedPacket((unsigned char*)&profile[seat], sizeof profile[seat], buf, (uint16_t)seat); + SendToLobby(STOC_PROFILE, buf, size); + } } int TagDuel::FreeOpenSeat() { for(int i = 0; i < 4; ++i) @@ -270,6 +290,8 @@ void TagDuel::SwapSeats(int first, int second) { std::swap(appearance[first], appearance[second]); std::swap(has_appearance[first], has_appearance[second]); std::swap(seat_state[first], seat_state[second]); // YGOL seat state + std::swap(profile[first], profile[second]); // YGOL profile + std::swap(has_profile[first], has_profile[second]); std::swap(seat_kind[first], seat_kind[second]); uint8_t token[SEAT_TOKEN_LEN]; std::memcpy(token, seat_token[first], SEAT_TOKEN_LEN); @@ -862,6 +884,7 @@ void TagDuel::SeatLeft(DuelPlayer* dp) { ready[dp->type] = false; has_appearance[dp->type] = false; // YGOL feature messages seat_state[dp->type] = CTOS_SeatState{}; // YGOL seat state + has_profile[dp->type] = false; // YGOL profile scpc.status = (dp->type << 4) | PLAYERCHANGE_LEAVE; for(int i = 0; i < 4; ++i) if(players[i]) @@ -914,6 +937,7 @@ void TagDuel::ToDuelist(DuelPlayer* dp) { players[dp->type] = 0; has_appearance[dp->type] = false; // YGOL feature messages: a moved seat re-sends its own seat_state[dp->type] = CTOS_SeatState{}; // YGOL seat state + has_profile[dp->type] = false; // YGOL profile: a moved seat re-sends its own dp->type = (uint8_t)dptype; } } @@ -971,6 +995,7 @@ void TagDuel::ToObserver(DuelPlayer* dp) { ready[dp->type] = false; has_appearance[dp->type] = false; // YGOL feature messages seat_state[dp->type] = CTOS_SeatState{}; // YGOL seat state + has_profile[dp->type] = false; // YGOL profile dp->type = NETPLAYER_TYPE_OBSERVER; observers.insert(dp); STOC_TypeChange sctc; diff --git a/server/gframe/tag_duel.h b/server/gframe/tag_duel.h index 83789be..b5a9cac 100644 --- a/server/gframe/tag_duel.h +++ b/server/gframe/tag_duel.h @@ -29,6 +29,8 @@ public: 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 coin toss void ChooseTimeout() override; void JoinGame(DuelPlayer* dp, unsigned char* pdata, bool is_creater) override; @@ -91,6 +93,9 @@ protected: bool has_appearance[4]{}; CTOS_Appearance appearance[4]{}; CTOS_SeatState seat_state[4]{}; // YGOL seat state + // YGOL profile + bool has_profile[4]{}; + CTOS_Profile profile[4]{}; // YGOL coin toss void BeginChoose(int chooser, uint8_t face); int choose_seat{};