30 public function __construct(
35 if(($packet = $this->channel->read()) !==
null){
36 $id = ord($packet[0]);
38 if($id === ITCProtocol::PACKET_ENCAPSULATED){
39 $sessionId = Binary::readInt(substr($packet, $offset, 4));
41 $flags = ord($packet[$offset++]);
42 $immediate = ($flags & ITCProtocol::ENCAPSULATED_FLAG_IMMEDIATE) !== 0;
43 $needACK = ($flags & ITCProtocol::ENCAPSULATED_FLAG_NEED_ACK) !== 0;
46 $encapsulated->reliability = ord($packet[$offset++]);
49 $encapsulated->identifierACK = Binary::readInt(substr($packet, $offset, 4));
53 if(PacketReliability::isSequencedOrOrdered($encapsulated->reliability)){
54 $encapsulated->orderChannel = ord($packet[$offset++]);
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);
63 $port = Binary::readShort(substr($packet, $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);
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);