implement bb blocked senders

This commit is contained in:
Martin Michelsen
2022-07-30 12:56:05 -07:00
parent 7c28ee05cc
commit f4517ab92e
4 changed files with 61 additions and 31 deletions
+9 -5
View File
@@ -1781,13 +1781,17 @@ struct S_ChoiceSearchResultEntry_V3_C4 {
// client_id field in each entry before sending.
// C6 (C->S): Set blocked senders list (V3/BB)
// The command always contains the same number of entries, even if the entries
// at the end are blank (zero).
struct C_SetBlockedSenders_V3_BB_C6 {
// The command always contains 30 entries, even if the entries at the end are
// blank (zero).
parray<le_uint32_t, 30> blocked_senders;
template <size_t Count>
struct C_SetBlockedSenders_C6 {
parray<le_uint32_t, Count> blocked_senders;
};
struct C_SetBlockedSenders_V3_C6 : C_SetBlockedSenders_C6<30> { };
struct C_SetBlockedSenders_BB_C6 : C_SetBlockedSenders_C6<28> { };
// C7 (C->S): Enable simple mail auto-reply (V3/BB)
// Same format as 1A/D5 command (plain text).
// Server does not respond
@@ -2299,7 +2303,7 @@ struct C_DeleteGuildCard_BB_05E8_08E8 {
le_uint32_t guild_card_number;
};
// 06E8 (C->S): Set guild card text
// 06E8 (C->S): Update (overwrite) guild card
// Format is GuildCardBB (see Player.hh)
// 07E8 (C->S): Add blocked user
+3 -3
View File
@@ -271,14 +271,14 @@ GuildCardV3::GuildCardV3() noexcept
: player_tag(0),
guild_card_number(0),
present(0),
present2(0),
language(0),
section_id(0),
char_class(0) { }
GuildCardBB::GuildCardBB() noexcept
: guild_card_number(0),
present(0),
present2(0),
language(0),
section_id(0),
char_class(0) { }
@@ -288,7 +288,7 @@ void GuildCardBB::clear() {
this->team_name.clear();
this->description.clear();
this->present = 0;
this->present2 = 0;
this->language = 0;
this->section_id = 0;
this->char_class = 0;
}
+6 -4
View File
@@ -215,7 +215,7 @@ struct GuildCardV3 {
ptext<char, 0x18> name;
ptext<char, 0x6C> description;
uint8_t present; // should be 1
uint8_t present2; // should be 1
uint8_t language;
uint8_t section_id;
uint8_t char_class;
@@ -229,7 +229,7 @@ struct GuildCardBB {
ptext<char16_t, 0x10> team_name;
ptext<char16_t, 0x58> description;
uint8_t present; // should be 1 if guild card entry exists
uint8_t present2; // should be 1 if guild card entry exists
uint8_t language;
uint8_t section_id;
uint8_t char_class;
@@ -248,8 +248,10 @@ struct GuildCardEntryBB {
// the format of the BB guild card file
struct GuildCardFileBB {
parray<uint8_t, 0x1F74> unknown_a3;
GuildCardEntryBB entries[0x0069]; // that's 105 of them in decimal
parray<uint8_t, 0x114> unknown_a1;
GuildCardBB blocked[0x1C];
parray<uint8_t, 0x180> unknown_a2;
GuildCardEntryBB entries[0x69];
} __attribute__((packed));
struct KeyAndTeamConfigBB {
+43 -19
View File
@@ -1583,7 +1583,8 @@ void process_player_preview_request_bb(shared_ptr<ServerState>, shared_ptr<Clien
void process_client_checksum_bb(shared_ptr<ServerState>, shared_ptr<Client> c,
uint16_t command, uint32_t, const string& data) {
constexpr size_t max_count = sizeof(GuildCardFileBB) / sizeof(GuildCardEntryBB);
constexpr size_t max_count = sizeof(GuildCardFileBB::entries) / sizeof(GuildCardEntryBB);
constexpr size_t max_blocked = sizeof(GuildCardFileBB::blocked) / sizeof(GuildCardBB);
switch (command) {
case 0x01E8: { // Check guild card file checksum
check_size_v(data.size(), sizeof(C_GuildCardChecksum_01E8));
@@ -1615,20 +1616,17 @@ void process_client_checksum_bb(shared_ptr<ServerState>, shared_ptr<Client> c,
case 0x05E8: { // Delete guild card
auto& cmd = check_size_t<C_DeleteGuildCard_BB_05E8_08E8>(data);
auto& gcf = c->game_data.account()->guild_cards;
size_t z;
for (z = 0; z < max_count; z++) {
for (size_t z = 0; z < max_count; z++) {
if (gcf.entries[z].data.guild_card_number == cmd.guild_card_number) {
c->log.info("Deleted guild card %" PRIu32 " at position %zu",
cmd.guild_card_number.load(), z);
for (z = 0; z < max_count - 1; z++) {
gcf.entries[z] = gcf.entries[z + 1];
}
gcf.entries[max_count - 1].clear();
break;
}
}
if (z < max_count) {
c->log.info("Deleted guild card %" PRIu32 " at position %zu",
cmd.guild_card_number.load(), z);
for (z = 0; z < max_count - 1; z++) {
gcf.entries[z] = gcf.entries[z + 1];
}
gcf.entries[max_count - 1].clear();
}
break;
}
case 0x06E8: { // Update guild card
@@ -1644,15 +1642,36 @@ void process_client_checksum_bb(shared_ptr<ServerState>, shared_ptr<Client> c,
break;
}
case 0x07E8: { // Add blocked user
// TODO: Where do these go in GuildCardFileBB?
// auto& cmd = check_size_t<C_DeleteGuildCard_BB_05E8_08E8>(data);
throw runtime_error("blocked users are not yet implemented on BB");
auto& new_gc = check_size_t<GuildCardBB>(data);
auto& gcf = c->game_data.account()->guild_cards;
for (size_t z = 0; z < max_blocked; z++) {
if (!gcf.blocked[z].present) {
gcf.blocked[z] = new_gc;
c->log.info("Added blocked guild card %" PRIu32 " at position %zu",
new_gc.guild_card_number.load(), z);
// Note: The client also sends a C6 command, so we don't have to
// manually sync the actual blocked senders list here
break;
}
}
break;
}
case 0x08E8: { // Delete blocked user
// TODO: Where do these go in GuildCardFileBB?
// auto& cmd = check_size_t<C_DeleteGuildCard_BB_05E8_08E8>(data);
throw runtime_error("blocked users are not yet implemented on BB");
auto& cmd = check_size_t<C_DeleteGuildCard_BB_05E8_08E8>(data);
auto& gcf = c->game_data.account()->guild_cards;
for (size_t z = 0; z < max_blocked; z++) {
if (gcf.blocked[z].guild_card_number == cmd.guild_card_number) {
c->log.info("Deleted blocked guild card %" PRIu32 " at position %zu",
cmd.guild_card_number.load(), z);
for (z = 0; z < max_blocked - 1; z++) {
gcf.blocked[z] = gcf.blocked[z + 1];
}
gcf.blocked[max_blocked - 1].clear();
// Note: The client also sends a C6 command, so we don't have to
// manually sync the actual blocked senders list here
break;
}
}
break;
}
case 0x09E8: { // Write comment
@@ -1932,8 +1951,13 @@ void process_disable_auto_reply(shared_ptr<ServerState>, shared_ptr<Client> c,
void process_set_blocked_senders_list(shared_ptr<ServerState>, shared_ptr<Client> c,
uint16_t, uint32_t, const string& data) { // C6
const auto& cmd = check_size_t<C_SetBlockedSenders_V3_BB_C6>(data);
c->game_data.account()->blocked_senders = cmd.blocked_senders;
if (c->version == GameVersion::BB) {
const auto& cmd = check_size_t<C_SetBlockedSenders_BB_C6>(data);
c->game_data.account()->blocked_senders = cmd.blocked_senders;
} else {
const auto& cmd = check_size_t<C_SetBlockedSenders_V3_C6>(data);
c->game_data.account()->blocked_senders = cmd.blocked_senders;
}
}