From 3bbe19f4d4392b60d1c8910609191c1088a1b07a Mon Sep 17 00:00:00 2001 From: Edvin Bryntesson Date: Wed, 21 Aug 2024 20:05:50 +0200 Subject: [PATCH 1/3] make sure the players gamemode is creative when client sends SSetCreativeSlot --- pumpkin/src/client/player_packet.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index b8a7853d7..097e22f9c 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -400,6 +400,10 @@ impl Client { } pub fn handle_set_creative_slot(&mut self, _server: &mut Server, packet: SSetCreativeSlot) { + let gamemode = self.player.as_ref().unwrap().gamemode; + if gamemode != GameMode::Creative { + self.kick("CHEATER") + } let inventory = &mut self.player.as_mut().unwrap().inventory; inventory.set_slot(packet.slot as usize, packet.clicked_item.to_item(), false); From dda2958e2af15911d49bc77aff047a0e6b0f555a Mon Sep 17 00:00:00 2001 From: Edvin Bryntesson Date: Wed, 21 Aug 2024 20:19:18 +0200 Subject: [PATCH 2/3] fix kick message --- pumpkin/src/client/player_packet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 097e22f9c..d2f855b0c 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -402,7 +402,7 @@ impl Client { pub fn handle_set_creative_slot(&mut self, _server: &mut Server, packet: SSetCreativeSlot) { let gamemode = self.player.as_ref().unwrap().gamemode; if gamemode != GameMode::Creative { - self.kick("CHEATER") + self.kick("Invalid action, you can only do that if you are in creative") } let inventory = &mut self.player.as_mut().unwrap().inventory; From e34fc4733208e80dae0b3f6bd38d9a95350444fb Mon Sep 17 00:00:00 2001 From: Edvin Bryntesson Date: Wed, 21 Aug 2024 20:43:09 +0200 Subject: [PATCH 3/3] refactor out double call to self.player --- pumpkin/src/client/player_packet.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index d2f855b0c..2457f1a62 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -400,11 +400,12 @@ impl Client { } pub fn handle_set_creative_slot(&mut self, _server: &mut Server, packet: SSetCreativeSlot) { - let gamemode = self.player.as_ref().unwrap().gamemode; - if gamemode != GameMode::Creative { - self.kick("Invalid action, you can only do that if you are in creative") + 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; } - let inventory = &mut self.player.as_mut().unwrap().inventory; + let inventory = &mut player.inventory; inventory.set_slot(packet.slot as usize, packet.clicked_item.to_item(), false); }