PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
UserToRakLibThreadMessageReceiver.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
26use function ord;
27use function substr;
28
30 public function __construct(
31 private InterThreadChannelReader $channel
32 ){}
33
34 public function process(ServerInterface $server) : bool{
35 if(($packet = $this->channel->read()) !== null){
36 $id = ord($packet[0]);
37 $offset = 1;
38 if($id === ITCProtocol::PACKET_ENCAPSULATED){
39 $sessionId = Binary::readInt(substr($packet, $offset, 4));
40 $offset += 4;
41 $flags = ord($packet[$offset++]);
42 $immediate = ($flags & ITCProtocol::ENCAPSULATED_FLAG_IMMEDIATE) !== 0;
43 $needACK = ($flags & ITCProtocol::ENCAPSULATED_FLAG_NEED_ACK) !== 0;
44
45 $encapsulated = new EncapsulatedPacket();
46 $encapsulated->reliability = ord($packet[$offset++]);
47
48 if($needACK){
49 $encapsulated->identifierACK = Binary::readInt(substr($packet, $offset, 4));
50 $offset += 4;
51 }
52
53 if(PacketReliability::isSequencedOrOrdered($encapsulated->reliability)){
54 $encapsulated->orderChannel = ord($packet[$offset++]);
55 }
56
57 $encapsulated->buffer = substr($packet, $offset);
58 $server->sendEncapsulated($sessionId, $encapsulated, $immediate);
59 }elseif($id === ITCProtocol::PACKET_RAW){
60 $len = ord($packet[$offset++]);
61 $address = substr($packet, $offset, $len);
62 $offset += $len;
63 $port = Binary::readShort(substr($packet, $offset, 2));
64 $offset += 2;
65 $payload = substr($packet, $offset);
66 $server->sendRaw($address, $port, $payload);
67 }elseif($id === ITCProtocol::PACKET_CLOSE_SESSION){
68 $sessionId = Binary::readInt(substr($packet, $offset, 4));
69 $server->closeSession($sessionId);
70 }elseif($id === ITCProtocol::PACKET_SET_NAME){
71 $server->setName(substr($packet, $offset));
72 }elseif($id === ITCProtocol::PACKET_ENABLE_PORT_CHECK){
73 $server->setPortCheck(true);
74 }elseif($id === ITCProtocol::PACKET_DISABLE_PORT_CHECK){
75 $server->setPortCheck(false);
76 }elseif($id === ITCProtocol::PACKET_SET_PACKETS_PER_TICK_LIMIT){
77 $limit = Binary::readLong(substr($packet, $offset, 8));
78 $server->setPacketsPerTickLimit($limit);
79 }elseif($id === ITCProtocol::PACKET_BLOCK_ADDRESS){
80 $len = ord($packet[$offset++]);
81 $address = substr($packet, $offset, $len);
82 $offset += $len;
83 $timeout = Binary::readInt(substr($packet, $offset, 4));
84 $server->blockAddress($address, $timeout);
85 }elseif($id === ITCProtocol::PACKET_UNBLOCK_ADDRESS){
86 $len = ord($packet[$offset++]);
87 $address = substr($packet, $offset, $len);
88 $server->unblockAddress($address);
89 }elseif($id === ITCProtocol::PACKET_RAW_FILTER){
90 $pattern = substr($packet, $offset);
91 $server->addRawPacketFilter($pattern);
92 }
93
94 return true;
95 }
96
97 return false;
98 }
99}