Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Improve anticheat: Reach is working now!
Browse files Browse the repository at this point in the history
  • Loading branch information
xqwtxon committed Sep 12, 2023
1 parent c1dc81f commit da9f208
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/PrideCore/Anticheat/Anticheat.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
use PrideCore\Anticheat\Modules\Flight;
use PrideCore\Anticheat\Modules\Glitch;
use PrideCore\Anticheat\Modules\Instabreak;
use PrideCore\Anticheat\Modules\Killaura;
use PrideCore\Anticheat\Modules\NoClip;
use PrideCore\Anticheat\Modules\Killaura;
use PrideCore\Anticheat\Modules\NoPacket;
use PrideCore\Anticheat\Modules\Reach;
use PrideCore\Anticheat\Modules\Timer;
Expand Down Expand Up @@ -263,8 +263,8 @@ public static function getCurrentFrictionFactor(Player $player){
public static function load() : void{
// load all available check class
(new Reach());
(new Killaura());
(new Flight());
//(new Flight()); TODO
(new Killaura());
(new NoClip());
(new Glitch());
(new Instabreak());
Expand Down
1 change: 1 addition & 0 deletions src/PrideCore/Anticheat/Modules/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

use pocketmine\entity\effect\VanillaEffects;
use pocketmine\event\Listener;
use PrideCore\Utils\Rank;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\math\Vector3;
use pocketmine\world\Position;
Expand Down
34 changes: 3 additions & 31 deletions src/PrideCore/Anticheat/Modules/Killaura.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

namespace PrideCore\Anticheat\Modules;

use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
Expand All @@ -55,35 +54,8 @@ public function __construct()
Core::getInstance()->getServer()->getPluginManager()->registerEvents($this, Core::getInstance());
}

private array $lastEntity = [];
private array $entities = [];
private array $timer = [];

public function handleEvent(EntityDamageByEntityEvent $event) : void{ // bruh worst anticheat
if(($player = $event->getEntity()) instanceof Player && ($damager = $event->getDamager()) instanceof Player){
if($damager->getRankId() === Rank::OWNER) return;
if($damager->getGamemode()->equals(GameMode::CREATIVE())) return;
if($damager->getGamemode()->equals(GameMode::SPECTATOR())) return;
if(!isset($this->lastEntity[$damager->getUniqueId()->__toString()])) $this->lastEntity[$damager->getUniqueId()->__toString()] = spl_object_hash($player);
if(!isset($this->entities[$damager->getUniqueId()->__toString()])) $this->lastEntity[$damager->getUniqueId()->__toString()] = 0;
if(!isset($this->timer[$damager->getUniqueId()->__toString()])) $this->timer[$damager->getUniqueId()->__toString()] = microtime(true);

if($this->lastEntity[$damager->getUniqueId()->__toString()] !== spl_object_hash($player)){
if($this->lastEntity[$damager->getUniqueId()->__toString()]->distance($damager) > 2){
if($this->timer[$damager->getUniqueId()->__toString()] - microtime(true) > 0.5){
$event->cancel();
$this->fail($damager);
}
}
$this->entities[$damager->getUniqueId()->__toString()]++;
$this->lastEntity[$damager->getUniqueId()->__toString()] = spl_object_hash($player);
$this->timer[$damager->getUniqueId()->__toString()] = microtime(true);
}
}
}

// Commonly in Toolbox
public function toolboxAura(Packet $packet, Player $player) : void{
public function handlePackets(Packet $packet, Player $player) : void{
if($player->getRankId() === Rank::OWNER) return;
if($player->getGamemode()->equals(GameMode::CREATIVE())) return;
if($player->getGamemode()->equals(GameMode::SPECTATOR())) return;
Expand All @@ -106,7 +78,7 @@ public function toolboxAura(Packet $packet, Player $player) : void{

public function processEvent(DataPacketReceiveEvent $event) : void{
if($event->getPacket() instanceof AnimatePacket || $event->getPacket() instanceof InventoryTransactionPacket){
$this->toolboxAura($event->getPacket(), $event->getOrigin()->getPlayer());
$this->handlePackets($event->getPacket(), $event->getOrigin()->getPlayer());
}
}

Expand All @@ -116,4 +88,4 @@ public function destroyQuit(PlayerQuitEvent $event) : void{
if(isset($this->entities[$player->getUniqueId()->__toString()])) unset($this->entities[$player->getUniqueId()->__toString()]);
if(isset($this->timer[$player->getUniqueId()->__toString()])) unset($this->timer[$player->getUniqueId()->__toString()]);
}
}
}
2 changes: 1 addition & 1 deletion src/PrideCore/Anticheat/Modules/NoClip.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct()

public function onMove(PlayerMoveEvent $event) {
$id = $event->getPlayer()->getWorld()->getBlock($event->getPlayer()->getLocation())->getTypeId();
if ($event->getPlayer()->getWorld()->getBlock($event->getPlayer()->getLocation()->add(0, 1, 0))->isSolid() && $id !== BlockTypeIds::SAND && $id !== BlockTypeIds::GRAVEL && $event->getPlayer()->getGamemode() !== GameMode::SPECTATOR()) {
if ($event->getPlayer()->getWorld()->getBlock($event->getPlayer()->getLocation()->add(0, 1, 0))->isSolid() && $id !== BlockTypeIds::SAND && $id !== BlockTypeIds::GRAVEL && $id !== BlockTypeIds::ACACIA_FENCE && $id !== BlockTypeIds::OAK_FENCE && $id !== BlockTypeIds::BIRCH_FENCE && $id !== BlockTypeIds::DARK_OAK_FENCE && $id !== BlockTypeIds::JUNGLE_FENCE && $id !== BlockTypeIds::NETHER_BRICK_FENCE && $id !== BlockTypeIds::SPRUCE_FENCE && $id !== BlockTypeIds::WARPED_FENCE && $id !== BlockTypeIds::MANGROVE_FENCE && $id !== BlockTypeIds::CRIMSON_FENCE && $id !== BlockTypeIds::CHERRY_FENCE && $id !== BlockTypeIds::ACACIA_FENCE_GATE && $id !== BlockTypeIds::OAK_FENCE_GATE && $id !== BlockTypeIds::BIRCH_FENCE_GATE && $id !== BlockTypeIds::DARK_OAK_FENCE_GATE && $id !== BlockTypeIds::JUNGLE_FENCE_GATE && $id !== BlockTypeIds::SPRUCE_FENCE_GATE && $id !== BlockTypeIds::WARPED_FENCE_GATE && $id !== BlockTypeIds::MANGROVE_FENCE_GATE && $id !== BlockTypeIds::CRIMSON_FENCE_GATE && $id !== BlockTypeIds::CHERRY_FENCE_GATE && $event->getPlayer()->getGamemode() !== GameMode::SPECTATOR()) {
$event->cancel();
$this->fail($event->getPlayer());
return;
Expand Down
2 changes: 1 addition & 1 deletion src/PrideCore/Anticheat/Modules/Reach.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function reachV3(EntityDamageEvent $event){
if(!$event->getDamager()->canInteract($event->getEntity()->getLocation()->add(0.5, 0.5, 0.5), $event->getEntity()->isCreative() ? self::MAX_REACH_DISTANCE_CREATIVE_V3 : self::MAX_REACH_DISTANCE_SURVIVAL_V3)){
$this->fail($event->getDamager());
}
if(!$event->getDamager()->canInteract($event->getEntity()->getLocation(), self::MAX_REACH_DISTANCE_ENTITY_INTERACTION)){
if(!$event->getDamager()->canInteract($event->getEntity()->getLocation(), self::MAX_REACH_DISTANCE_ENTITY_INTERACTION_V3)){
$this->fail($event->getDamager());
$event->cancel();
}
Expand Down
14 changes: 7 additions & 7 deletions src/PrideCore/Discord/PrideBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class Bot implements Listener{

private DiscordBot $bot;

public function getDiscordBot() : DiscordBot{
return $this->bot;
}

public function ready() : void{

}
public function __construct(){
}
public function onMessage(MessageEvent $event){
}
}
10 changes: 10 additions & 0 deletions src/PrideCore/Utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,14 @@ public function killPlayer(Player $player, bool $nodrops = false) : void{

$player->kill();
}

public static function generateCode(int $length, string $chars = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789"): string{
mt_srand(intval(microtime(true)*1000000));
$pass = '' ;
for($i = 0; $i < $length; $i += 1){
$num = mt_rand() % strlen($chars);
$pass .= $chars[$num];
}
return $pass;
}
}

0 comments on commit da9f208

Please sign in to comment.