Last active
May 6, 2020 11:39
-
-
Save Alemiz112/c82e8e65526d1207989d00faa052be10 to your computer and use it in GitHub Desktop.
Simple way to check if player is using Waterdog proxy to connect to PMMP server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use pocketmine\event\Listener; | |
use pocketmine\event\server\DataPacketReceiveEvent; | |
use pocketmine\network\mcpe\protocol\LoginPacket; | |
class ProxyCheck implements Listener { | |
/** | |
* List of addresses that may bypass this restriction | |
* Include address of Waterdog too (usually 0.0.0.0 if running on same node) | |
* @var array | |
*/ | |
public $acceptedIPs = ["0.0.0.0", "127.0.0.1"]; | |
/** | |
* @param DataPacketReceiveEvent $event | |
*/ | |
public function onPacketReceive(DataPacketReceiveEvent $event): void { | |
if(!($event->getPacket() instanceof LoginPacket)) return; | |
/** @var LoginPacket $packet */ | |
$packet = $event->getPacket(); | |
$player = $event->getPlayer(); | |
$remoteAddress = $packet->clientData["WaterDog_RemoteIP"] ?? null; | |
if ($remoteAddress === null || !in_array($player->getAddress(), $this->acceptedIPs, true)){ | |
//Player is not joined over Waterdog Proxy or his address is not accepted | |
return; | |
} | |
try { | |
//Set right address to player class | |
$class = new ReflectionClass($player); | |
$prop = $class->getProperty("ip"); | |
$prop->setAccessible(true); | |
$prop->setValue($player, $remoteAddress); | |
}catch (Exception $e){ | |
//ignore | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment