Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added native operator permission management #348

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

KairuDeibisu
Copy link

@KairuDeibisu KairuDeibisu commented Nov 28, 2024

This commit adds the ops.json configuration found in vanilla servers, and updates the basic configuration to handle the default permission level.

Server now uses ops file and defaults players to op level 0

The /op command has been added.

Testing

Before starting the server:

  1. If you had a previously existing ops.json file in the data folder (e.g., from testing this pull request), delete it.

Note: ops.json is not present by default. It is automatically generated when the server is started for the first time, and it stores the list of server operators.

Start server:

  1. Attempted to change the game mode to creative; this should fail.
  2. Attempted to use /op JustATempest ; this should fail.
  3. Used /op JustATempest in the console; this should work.
  4. In-game, attempted to change the game mode to creative; this should work.

Testing Results

image
image
image
image

Design challenges

Operator Level Management

To maintain parity with Minecraft, the operator level must be configurable within the basic configuration. Initially, the idea of introducing a new operator level type and conversions was explored. However, this approach led to duplicated code and complexity. Instead, it was suggested to centralize permission levels within the core, as the configuration system already depends on the core module.

Operator List (ops.json)

For parity with Minecraft, an ops.json file is required to store the list of operators on the server. This file is loaded at startup, and its data is referenced whenever a player is constructed. If a player’s UUID is not found in the list, they are assigned the default permission level of 0, which matches Minecraft’s behavior and cannot be changed.

/op Command

The /op command is also necessary for parity. This command accepts a single argument: the target player's name. A player must have a permission level of 3 or higher to use this command. Executing /op adds the target player to the operator list with the default permission level specified in the basic configuration.

Edge Case: Overlapping Permission Levels

An edge case exists where a player with permission level 3 could use /op to grant another player a higher permission level (e.g., 4). To resolve this, the command checks the sender’s permission level against the default operator level in the basic configuration and applies the lower value.

Session Update

After a player is added to the operator list, their current session must reflect the updated permission level. This required adding a mutex to synchronize access to the permission level within the player structure.

Command Builder Limitation

This change introduced a side effect: the require function in the command builder does not support async functions. To address this, we opted to use the parking_lot crate instead of tokio, avoiding the need for async and await in the builder.

Fixes

Checklist

Things need to be done before this Pull Request can be merged.

  • Code is well-formatted and adheres to project style guidelines: cargo fmt
  • Code does not produce any clippy warnings: cargo clippy
  • All unit tests pass: cargo test

This commit adds the ops.json configuration found in vanilla
servers, and updates the basic configuration to handle the default
permission level.

Server now uses ops file and defaults players to op level 0

The /op command has been added but needs players to rejoin for now.
I found the source of the DeadLock. Updated set permission function.

Fix cargo formatting issues and clippy issues.
@Snowiiii
Copy link
Owner

You added a bunch of deps and put OP into pumpkin-config. This is not a Config. It is used as Runtime data which can be changed. Im not sure if we should handle OPs per Server or per World base.

@KairuDeibisu
Copy link
Author

KairuDeibisu commented Nov 29, 2024

You added a bunch of deps and put OP into pumpkin-config. This is not a Config. It is used as Runtime data which can be changed. Im not sure if we should handle OPs per Server or per World base.

Per server sounds more accurate but I'm not sure what you're getting at. I initially added it to config because, from my perspective, it is a config. But I can see what you're saying.

But I'm not seeing the immediate solution. What am I changing? Is there anything specific I should change?

As Snowiii pointed out, OperatorConfig is runtime data.

Revert most changes in pumpkin-config.

op_permission_level must say in the basic configuration for
parity with Minecraft.
pumpkin-config/src/op.rs Outdated Show resolved Hide resolved
@KairuDeibisu KairuDeibisu changed the title Feature permissions Added native operator permission management Dec 3, 2024
Copy link
Author

@KairuDeibisu KairuDeibisu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've double checked my code and can't see issues. The things that are important are pointed out in the design section of my pull request.

pumpkin-config/src/op.rs Outdated Show resolved Hide resolved
pumpkin/src/command/commands/cmd_op.rs Outdated Show resolved Hide resolved
pumpkin/src/command/commands/cmd_op.rs Outdated Show resolved Hide resolved
pumpkin/src/command/commands/cmd_op.rs Outdated Show resolved Hide resolved
pumpkin/src/command/commands/cmd_op.rs Outdated Show resolved Hide resolved
pumpkin/src/command/commands/cmd_op.rs Outdated Show resolved Hide resolved
pumpkin/src/entity/player.rs Show resolved Hide resolved
pumpkin/src/server/json_config.rs Outdated Show resolved Hide resolved
- Move PermissionLvl to core and removed OpLevel
- Move ops.json to /data/ops.json
- Fix permissions issue with /op command
- Shorten /op command description
@OfficialKris
Copy link
Contributor

OfficialKris commented Dec 9, 2024

Is there a way to change default op? for instance, on the test server, if we want to go to creative mode it would no longer be possible without an admin to give op permission. Maybe the setting could configure the default permission to be op level three two rather than zero?

Copy link
Collaborator

@lukas0008 lukas0008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont have many complaints, maybe @Bryntet check if somethings amiss

PS: i started doing something else and forgot about this, so it took a while

uuid: Uuid,
name: String,
level: PermissionLvl,
bypasses_player_limit: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer to use enums instead of bools, the function call is hard to read:

Op::new(..., false)

is hard to read

Path::new("data/ops.json")
}
fn validate(&self) {
// TODO: Validate the operator configuration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotta do the todo

2 => Ok(PermissionLvl::Two),
3 => Ok(PermissionLvl::Three),
4 => Ok(PermissionLvl::Four),
_ => Err(serde::de::Error::custom(format!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use serde::de::Error::invalid_value instead here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants