Skip to content

Commit

Permalink
fix(command): commands will no longer be sent to a player who doesn't…
Browse files Browse the repository at this point in the history
… have the appropriate permissions
  • Loading branch information
wu-vincent committed Jul 31, 2024
1 parent 73fa791 commit 46325a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/endstone_core/permissions/permissible_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ void PermissibleBase::calculateChildPermissions(const std::unordered_map<std::st

for (const auto &entry : children) {
auto name = entry.first;

auto *perm = plugin_manager.getPermission(name);
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) { return std::tolower(c); });
bool value = entry.second ^ invert;

permissions_[name] = std::make_unique<PermissionAttachmentInfo>(parent_, name, attachment, value);
plugin_manager.subscribeToPermission(name, parent_);

auto *perm = plugin_manager.getPermission(name);
if (perm != nullptr) {
calculateChildPermissions(perm->getChildren(), !value, attachment);
}
Expand Down
11 changes: 6 additions & 5 deletions src/endstone_core/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,15 @@ void EndstonePlayer::updateCommands() const
AvailableCommandsPacket packet = registry.serializeAvailableCommands();

auto &command_map = server_.getCommandMap();
for (auto &data : packet.commands) {
auto name = data.name;
for (auto it = packet.commands.begin(); it != packet.commands.end();) {
auto &name = it->name;
auto *command = command_map.getCommand(name);
if (command && command->isRegistered() && command->testPermissionSilently(*static_cast<const Player *>(this))) {
if (command && command->isRegistered() && command->testPermissionSilently(*static_cast<const Player *>(this)) &&
it->permission_level <= CommandPermissionLevel::GameDirectors) {
++it;
continue;
}
data.command_flag |= (CommandFlag::HiddenFromPlayer | CommandFlag::HiddenFromBlock);
data.permission_level = CommandPermissionLevel::Internal;
it = packet.commands.erase(it);
}

getHandle().sendNetworkPacket(packet);
Expand Down

0 comments on commit 46325a3

Please sign in to comment.