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

feat: add whitelist command #446

Closed

Conversation

smuu
Copy link
Contributor

@smuu smuu commented Jan 2, 2025

Description

  • This PR adds the whitelist command and the corresponding whitelist.json file to keep track of the whitelisted users.

Testing

Please follow our Coding Guidelines

Comment on lines 106 to 109
/// Whether to enable the whitelist
pub white_list: bool,
/// Whether to enforce the whitelist
pub enforce_whitelist: bool,
Copy link
Member

Choose a reason for hiding this comment

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

One boolean would be enough, If the white list is enabled it will be automatically enforced

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both variables are used in the vanilla server.properties file. You can enable the whitelist but not enforce it. If you enforce it, players will be kicked when you reload the whitelist if they are not whitelisted.
From the Minecraft wiki:

white-list

Whether the whitelist is enabled.

With a whitelist enabled, users not on the whitelist cannot connect. Intended for private servers, such as those for real-life friends or strangers carefully selected via an application process, for example.

false - No white list is used.
true - The file whitelist.json is used to generate the white list.

Note: Ops are automatically whitelisted, and there is no need to add them to the whitelist.

enforce-whitelist

Whether to enforce changes to the whitelist.

When this option as well as the whitelist is enabled, players not present on the whitelist get kicked from the server after the server reloads the whitelist file.

false - Online players that are not on the whitelist are not kicked.
true - Online players that are not on the whitelist are kicked.

use uuid::Uuid;

#[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct PlayerProfile {
Copy link
Member

Choose a reason for hiding this comment

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

Why this is here in pumpkin-config?

Copy link
Contributor Author

@smuu smuu Jan 4, 2025

Choose a reason for hiding this comment

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

I placed it where the op files were and moved both to the data folder.

Comment on lines 238 to 252

// If the whitelist is enabled, check if the player is whitelisted
if *server.white_list.read().await {
let whitelist_config = WHITELIST_CONFIG.read().await;
let is_whitelisted = whitelist_config
.whitelist
.iter()
.any(|p| p.uuid == player.gameprofile.id);
let is_op = player.permission_lvl.load() >= PermissionLvl::Three;
if !is_whitelisted && !is_op {
player
.kick(TextComponent::text("You are not whitelisted!"))
.await;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Lets not clutter our main (even more), A new method in the Server which gets called in Server::add_player would be probably ideal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hat makes sense. Moved it

@smuu smuu closed this Jan 4, 2025
@smuu smuu force-pushed the smuu/20250101-add-whitelist-feature branch from fb2b213 to 0fbc730 Compare January 4, 2025 10:57
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.

2 participants