From 295bb9c4a45eef2611b599655ccc63ec23bc8a62 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 1 Oct 2022 18:38:09 -0700 Subject: [PATCH] don't send Ep3 card defs unnecessarily --- src/Client.hh | 3 +++ src/ProxyCommands.cc | 4 ++++ src/SendCommands.cc | 15 ++++++++++----- tests/GC-Episode3GameSmokeTest.test.txt | 8 ++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Client.hh b/src/Client.hh index 00c4cb46..226dd80b 100644 --- a/src/Client.hh +++ b/src/Client.hh @@ -64,6 +64,9 @@ struct Client { // Client has already received a 97 (enable saves) command, so don't show // the programs menu anymore SAVE_ENABLED = 0x0400, + // Client has received newserv's Episode 3 card definitions, so don't send + // them again + HAS_EP3_CARD_DEFS = 0x4000, }; uint64_t id; diff --git a/src/ProxyCommands.cc b/src/ProxyCommands.cc index a9acb7ae..48f08c98 100644 --- a/src/ProxyCommands.cc +++ b/src/ProxyCommands.cc @@ -963,6 +963,10 @@ static HandlerResult S_G_B8(shared_ptr, session.log.info("Wrote %zu bytes to %s", size, output_filename.c_str()); } + // Unset the flag specifying that the client has newserv's card definitions, + // so the file sill be sent again if the client returns to newserv. + session.newserv_client_config.cfg.flags &= ~Client::Flag::HAS_EP3_CARD_DEFS; + return !(session.newserv_client_config.cfg.flags & Client::Flag::IS_EPISODE_3) ? HandlerResult::Type::FORWARD : HandlerResult::Type::SUPPRESS; diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 69a9e807..06ed7d2c 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -1568,13 +1568,18 @@ void send_give_experience(shared_ptr l, shared_ptr c, // ep3 only commands void send_ep3_card_list_update(shared_ptr s, shared_ptr c) { - const auto& data = s->ep3_data_index->get_compressed_card_definitions(); + if (!(c->flags & Client::Flag::HAS_EP3_CARD_DEFS)) { + const auto& data = s->ep3_data_index->get_compressed_card_definitions(); - StringWriter w; - w.put_u32l(data.size()); - w.write(data); + StringWriter w; + w.put_u32l(data.size()); + w.write(data); - send_command(c, 0xB8, 0x00, w.str()); + send_command(c, 0xB8, 0x00, w.str()); + + c->flags |= Client::Flag::HAS_EP3_CARD_DEFS; + send_update_client_config(c); + } } // sends the client a generic rank diff --git a/tests/GC-Episode3GameSmokeTest.test.txt b/tests/GC-Episode3GameSmokeTest.test.txt index db77d7c9..9e5524d6 100644 --- a/tests/GC-Episode3GameSmokeTest.test.txt +++ b/tests/GC-Episode3GameSmokeTest.test.txt @@ -1902,6 +1902,10 @@ I 94711 2022-07-26 00:24:56 - [Commands] Sending to C-7 (version=GC command=B8 f 71B0 | 30 36 20 F5 3A D0 F3 3A E8 3A 2E FF 5D 00 F8 FF | 06 : : :. ] 71C0 | E3 02 BD C0 FF 0D 77 FC FF CA A3 F8 F4 1F 2A A0 | w * 71D0 | 85 45 F0 24 F0 F0 8C 0A 08 FF 0B 00 00 00 00 00 | E $ +I 8584 2022-10-01 18:38:45 - [Commands] Sending to C-7 (version=GC command=04 flag=00) +0000 | 04 00 2C 00 00 00 01 00 78 62 F8 10 39 98 AC 82 | , xb 9 +0010 | 0E 89 2A 49 0A 43 00 00 00 00 00 00 FF FF FF FF | *I C +0020 | FF FF FF FF FF FF FF FF FF FF FF FF | I 94711 2022-07-26 00:24:56 - [Commands] Sending to C-7 (version=GC command=B7 flag=00) 0000 | B7 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 | 0010 | 00 00 00 00 FF FF FF 00 FF FF FF 00 FF FF FF FF | @@ -1938,7 +1942,7 @@ I 94711 2022-07-26 00:24:59 - [Commands] Sending to C-7 (version=GC command=07 f 00C0 | 6E 73 65 00 00 00 00 00 | nse I 94711 2022-07-26 00:24:59 - [Commands] Sending to C-7 (version=GC command=04 flag=00) 0000 | 04 00 2C 00 00 00 01 00 78 62 F8 10 39 98 AC 82 | , xb 9 -0010 | 0E 89 2A 49 0A 02 00 00 00 00 00 00 FF FF FF FF | *I +0010 | 0E 89 2A 49 0A 42 00 00 00 00 00 00 FF FF FF FF | *I 0020 | FF FF FF FF FF FF FF FF FF FF FF FF | I 94711 2022-07-26 00:25:06 - [Commands] Received from C-7 (version=GC command=10 flag=00) 0000 | 10 00 0C 00 11 00 00 11 11 33 33 11 | 33 @@ -2050,7 +2054,7 @@ I 94711 2022-07-26 00:25:12 - [Commands] Sending to C-7 (version=GC command=97 f 0000 | 97 01 04 00 | I 94711 2022-07-26 00:25:12 - [Commands] Sending to C-7 (version=GC command=04 flag=00) 0000 | 04 00 2C 00 00 00 01 00 78 62 F8 10 39 98 AC 82 | , xb 9 -0010 | 0E 89 2A 49 0A 06 00 00 00 00 00 00 FF FF FF FF | *I +0010 | 0E 89 2A 49 0A 46 00 00 00 00 00 00 FF FF FF FF | *I 0020 | FF FF FF FF FF FF FF FF FF FF FF FF | I 94711 2022-07-26 00:25:12 - [Commands] Received from C-7 (version=GC command=B1 flag=00) 0000 | B1 00 04 00 |