-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProxyPacketSender.php
54 lines (41 loc) · 1.33 KB
/
ProxyPacketSender.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 libproxy\protocol\ForwardPacket;
use libproxy\protocol\ForwardReceiptPacket;
use pocketmine\network\mcpe\PacketSender;
class ProxyPacketSender implements PacketSender
{
/** @var int */
private int $socketId;
/** @var ProxyNetworkInterface */
private ProxyNetworkInterface $handler;
/** @var bool */
private bool $closed = false;
public function __construct(int $socketId, ProxyNetworkInterface $handler)
{
$this->socketId = $socketId;
$this->handler = $handler;
}
public function send(string $payload, bool $immediate, ?int $receiptId): void
{
if (!$this->closed) {
if ($receiptId === null) {
$pk = new ForwardPacket();
} else {
$pk = new ForwardReceiptPacket();
$pk->receiptId = $receiptId;
}
$pk->payload = $payload;
$this->handler->putPacket($this->socketId, $pk);
}
}
public function close(string $reason = "unknown reason"): void
{
if (!$this->closed) {
$this->closed = true;
// We don't need to call onClientDisconnect() when player is already being kicked by the server.
$this->handler->close($this->socketId, $reason, false, true);
}
}
}