PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
UserToRakLibThreadMessageSender.php
1<?php
2
3/*
4 * RakLib network library
5 *
6 *
7 * This project is not affiliated with Jenkins Software LLC nor RakNet.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 */
15
16declare(strict_types=1);
17
18namespace raklib\server\ipc;
19
25use function chr;
26use function strlen;
27
29 public function __construct(
30 private InterThreadChannelWriter $channel
31 ){}
32
33 public function sendEncapsulated(int $sessionId, EncapsulatedPacket $packet, bool $immediate = false) : void{
34 $flags =
35 ($immediate ? ITCProtocol::ENCAPSULATED_FLAG_IMMEDIATE : 0) |
36 ($packet->identifierACK !== null ? ITCProtocol::ENCAPSULATED_FLAG_NEED_ACK : 0);
37
38 $buffer = chr(ITCProtocol::PACKET_ENCAPSULATED) .
39 Binary::writeInt($sessionId) .
40 chr($flags) .
41 chr($packet->reliability) .
42 ($packet->identifierACK !== null ? Binary::writeInt($packet->identifierACK) : "") .
43 (PacketReliability::isSequencedOrOrdered($packet->reliability) ? chr($packet->orderChannel) : "") .
44 $packet->buffer;
45 $this->channel->write($buffer);
46 }
47
48 public function sendRaw(string $address, int $port, string $payload) : void{
49 $buffer = chr(ITCProtocol::PACKET_RAW) . chr(strlen($address)) . $address . Binary::writeShort($port) . $payload;
50 $this->channel->write($buffer);
51 }
52
53 public function closeSession(int $sessionId) : void{
54 $buffer = chr(ITCProtocol::PACKET_CLOSE_SESSION) . Binary::writeInt($sessionId);
55 $this->channel->write($buffer);
56 }
57
58 public function setName(string $name) : void{
59 $this->channel->write(chr(ITCProtocol::PACKET_SET_NAME) . $name);
60 }
61
62 public function setPortCheck(bool $value) : void{
63 $this->channel->write(chr($value ? ITCProtocol::PACKET_ENABLE_PORT_CHECK : ITCProtocol::PACKET_DISABLE_PORT_CHECK));
64 }
65
66 public function setPacketsPerTickLimit(int $limit) : void{
67 $this->channel->write(chr(ITCProtocol::PACKET_SET_PACKETS_PER_TICK_LIMIT) . Binary::writeLong($limit));
68 }
69
70 public function blockAddress(string $address, int $timeout) : void{
71 $buffer = chr(ITCProtocol::PACKET_BLOCK_ADDRESS) . chr(strlen($address)) . $address . Binary::writeInt($timeout);
72 $this->channel->write($buffer);
73 }
74
75 public function unblockAddress(string $address) : void{
76 $buffer = chr(ITCProtocol::PACKET_UNBLOCK_ADDRESS) . chr(strlen($address)) . $address;
77 $this->channel->write($buffer);
78 }
79
80 public function addRawPacketFilter(string $regex) : void{
81 $this->channel->write(chr(ITCProtocol::PACKET_RAW_FILTER) . $regex);
82 }
83}