diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index 5b0fa36e..7b6108b2 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -199,7 +199,7 @@ void Server::send(const void* data, size_t size) const { send_command(l, 0xC9, 0x00, data, size); for (auto watcher_l : l->watcher_lobbies) { - send_command(watcher_l, 0xC9, 0x00, data, size); + send_command_if_not_loading(watcher_l, 0xC9, 0x00, data, size); } if (l->battle_record && l->battle_record->writable()) { l->battle_record->add_command( @@ -2120,7 +2120,7 @@ void Server::handle_6xB3x40_map_list_request(const string& data) { w.write(list_data); send_command(l, 0x6C, 0x00, w.str()); for (auto watcher_l : l->watcher_lobbies) { - send_command(watcher_l, 0x6C, 0x00, w.str()); + send_command_if_not_loading(watcher_l, 0x6C, 0x00, w.str()); } if (l->battle_record && l->battle_record->writable()) { @@ -2144,7 +2144,7 @@ void Server::handle_6xB3x41_map_request(const string& data) { auto out_cmd = this->prepare_6xB6x41_map_definition(base->last_chosen_map); send_command(l, 0x6C, 0x00, out_cmd); for (auto watcher_l : l->watcher_lobbies) { - send_command(watcher_l, 0x6C, 0x00, out_cmd); + send_command_if_not_loading(watcher_l, 0x6C, 0x00, out_cmd); } if (l->battle_record && l->battle_record->writable()) { diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 8e40f97a..b38f1b9a 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -76,6 +76,16 @@ void send_command_excluding_client(shared_ptr l, shared_ptr c, } } +void send_command_if_not_loading(shared_ptr l, + uint16_t command, uint32_t flag, const void* data, size_t size) { + for (auto& client : l->clients) { + if (!client || (client->flags & Client::Flag::LOADING)) { + continue; + } + send_command(client, command, flag, data, size); + } +} + void send_command(shared_ptr l, uint16_t command, uint32_t flag, const void* data, size_t size) { send_command_excluding_client(l, nullptr, command, flag, data, size); diff --git a/src/SendCommands.hh b/src/SendCommands.hh index 54865eaa..8f8c0fcf 100644 --- a/src/SendCommands.hh +++ b/src/SendCommands.hh @@ -51,6 +51,18 @@ inline void send_command_excluding_client(std::shared_ptr l, send_command_excluding_client(l, c, command, flag, nullptr, 0); } +void send_command_if_not_loading(std::shared_ptr l, + uint16_t command, uint32_t flag, const void* data, size_t size); +inline void send_command_if_not_loading(std::shared_ptr l, + uint16_t command, uint32_t flag, const string& data) { + send_command_if_not_loading(l, command, flag, data.data(), data.size()); +} +template +inline void send_command_if_not_loading(std::shared_ptr l, + uint16_t command, uint32_t flag, const StructT& data) { + send_command_if_not_loading(l, command, flag, &data, sizeof(data)); +} + void send_command(std::shared_ptr l, uint16_t command, uint32_t flag, const void* data, size_t size);