From a56c39760ae33c6a5ae6e3f197b458550938493e Mon Sep 17 00:00:00 2001 From: Viet Dinh <36768030+Desdaemon@users.noreply.github.com> Date: Wed, 9 Oct 2024 21:12:04 -0400 Subject: [PATCH] Add new API to allow filtering players (#47) * Add new API to allow filtering players * Fix cache key to compile again --- src/cache.cpp | 2 +- src/multiplayer/game_multiplayer.cpp | 2 +- src/web_api.cpp | 6 ++++++ src/web_api.h | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cache.cpp b/src/cache.cpp index e4ae6925e..63131ba09 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -451,7 +451,7 @@ BitmapRef Cache::SpriteEffect(const BitmapRef& src_bitmap, const Rect& rect, boo auto id = src_bitmap->GetId(); // HACK: This might not be unique enough. if (id.empty()) - id = fmt::format("{}", src_bitmap.get()); + id = fmt::format("{}", static_cast(src_bitmap.get())); const effect_key_type key { id, src_bitmap->GetTransparent(), diff --git a/src/multiplayer/game_multiplayer.cpp b/src/multiplayer/game_multiplayer.cpp index a738b0b86..2e163caad 100644 --- a/src/multiplayer/game_multiplayer.cpp +++ b/src/multiplayer/game_multiplayer.cpp @@ -229,7 +229,7 @@ void Game_Multiplayer::InitConnection() { }); connection.RegisterHandler("c", [this] (ConnectPacket& p) { // I am entering a new room and don't care about players in the old room - if (switching_room) + if (switching_room || !Web_API::ShouldConnectPlayer(p.uuid)) return; if (players.find(p.id) == players.end()) SpawnOtherPlayer(p.id); players[p.id].account = p.account_bin == 1; diff --git a/src/web_api.cpp b/src/web_api.cpp index e12e78fc3..9b1c4d5d8 100644 --- a/src/web_api.cpp +++ b/src/web_api.cpp @@ -98,3 +98,9 @@ void Web_API::ShowToastMessage(std::string_view msg, std::string_view icon) { }, msg.data(), msg.size(), icon.data(), icon.size()); } +bool Web_API::ShouldConnectPlayer(std::string_view uuid) { + int result = EM_ASM_INT({ + return shouldConnectPlayer(UTF8ToString($0, $1)) ? 1 : 0; + }, uuid.data(), uuid.size()); + return result == 1; +} diff --git a/src/web_api.h b/src/web_api.h index 63da4b353..cc126dc68 100644 --- a/src/web_api.h +++ b/src/web_api.h @@ -23,6 +23,8 @@ namespace Web_API { // msg: localizedMessages.toast.client.* // icon: icon.js void ShowToastMessage(std::string_view msg, std::string_view icon); + + bool ShouldConnectPlayer(std::string_view uuid); } #endif