Skip to content

Commit

Permalink
Add new API to allow filtering players (ynoproject#47)
Browse files Browse the repository at this point in the history
* Add new API to allow filtering players

* Fix cache key to compile again
  • Loading branch information
Desdaemon authored Oct 10, 2024
1 parent 38897e4 commit a56c397
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const void*>(src_bitmap.get()));
const effect_key_type key {
id,
src_bitmap->GetTransparent(),
Expand Down
2 changes: 1 addition & 1 deletion src/multiplayer/game_multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void Game_Multiplayer::InitConnection() {
});
connection.RegisterHandler<ConnectPacket>("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;
Expand Down
6 changes: 6 additions & 0 deletions src/web_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/web_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a56c397

Please sign in to comment.