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

Add permissions check for SSetCreativeSlot #51

Merged
merged 3 commits into from
Aug 21, 2024
Merged

Conversation

Bryntet
Copy link
Contributor

@Bryntet Bryntet commented Aug 21, 2024

make sure the players gamemode is creative when client sends SSetCreativeSlot

@Snowiiii
Copy link
Owner

You have a good commit message, Why you don't use that for the PR description. There are many people using "self explanatory commit" or something like this in PR and i really hate it. So would be cool if you could use good commit messages and good PR descriptions in the future 👍

@Bryntet
Copy link
Contributor Author

Bryntet commented Aug 21, 2024

updated my PR message :)

@Bryntet Bryntet changed the title Permissions check for creative Add permissions check for SSetCreativeSlot Aug 21, 2024
Comment on lines 403 to 407
let gamemode = self.player.as_ref().unwrap().gamemode;
if gamemode != GameMode::Creative {
self.kick("CHEATER")
}
let inventory = &mut self.player.as_mut().unwrap().inventory;
Copy link
Owner

Choose a reason for hiding this comment

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

Why we should &mut self.player.as_mut() twice when we also could just do it once ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the borrow checker yells at me if i try to have a mut ref to player (that gets used later, so it can't be dropped) when doing self.kick (which requires &mut)

pumpkin/src/client/player_packet.rs Outdated Show resolved Hide resolved
Copy link
Owner

@Snowiiii Snowiiii left a comment

Choose a reason for hiding this comment

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

  let player = self.player.as_mut().unwrap();

        if player.gamemode != GameMode::Creative {
            self.kick("Invalid action, you can only do that if you are in creative");
            return;
        }

        player
            .inventory
            .set_slot(packet.slot as usize, packet.clicked_item.to_item(), false);

@Bryntet
Copy link
Contributor Author

Bryntet commented Aug 21, 2024

that should be fixed now

@Snowiiii
Copy link
Owner

Looks good, Thanks

@Snowiiii Snowiiii merged commit ee4bde9 into Snowiiii:master Aug 21, 2024
1 check passed
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