forked from NetherGamesMC/libproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxyListener.php
54 lines (45 loc) · 1.8 KB
/
ProxyListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace libproxy;
use pocketmine\event\Listener;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\NetworkSettingsPacket;
use pocketmine\network\mcpe\protocol\NetworkStackLatencyPacket;
use pocketmine\network\mcpe\protocol\RequestNetworkSettingsPacket;
use pocketmine\network\mcpe\protocol\types\CompressionAlgorithm;
class ProxyListener implements Listener
{
/**
* @param DataPacketReceiveEvent $event
*
* @priority LOWEST
*/
public function onDataPacketReceive(DataPacketReceiveEvent $event): void
{
$origin = $event->getOrigin();
$packet = $event->getPacket();
switch ($packet->pid()){
case NetworkStackLatencyPacket::NETWORK_ID:
/** @var NetworkStackLatencyPacket $packet USED FOR PING CALCULATIONS */
if ($packet->timestamp === 0 && $packet->needResponse) {
if (($player = $origin->getPlayer()) !== null && $player->isConnected()) {
$origin->sendDataPacket(NetworkStackLatencyPacket::response(0));
}
$event->cancel();
}
break;
case RequestNetworkSettingsPacket::NETWORK_ID:
/** @var RequestNetworkSettingsPacket $packet USED TO SIMULATE VANILLA BEHAVIOUR, SINCE IT'S NOT USED BY US */
// $origin->setProtocolId($packet->getProtocolVersion());
$origin->sendDataPacket(NetworkSettingsPacket::create(
NetworkSettingsPacket::COMPRESS_EVERYTHING,
CompressionAlgorithm::ZLIB,
false,
0,
0
), true);
$event->cancel();
break;
}
}
}