mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
support php8019 and some cleanup (by @D-aHTuCT)
This commit is contained in:
parent
cf0f9df267
commit
b60f0877e1
376 changed files with 6528 additions and 13472 deletions
|
|
@ -1,32 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class RakNetCodec{
|
||||
|
||||
public $packet;
|
||||
|
||||
public function __construct(RakNetPacket $packet){
|
||||
$this->packet = $packet;
|
||||
$this->buffer =& $this->packet->buffer;
|
||||
$this->encode();
|
||||
}
|
||||
|
||||
|
||||
private function encode(){
|
||||
if(strlen($this->packet->buffer) > 0){
|
||||
return;
|
||||
|
|
@ -87,7 +70,7 @@ class RakNetCodec{
|
|||
$pointer = 0;
|
||||
sort($this->packet->packets, SORT_NUMERIC);
|
||||
$max = count($this->packet->packets);
|
||||
|
||||
|
||||
while($pointer < $max){
|
||||
$type = true;
|
||||
$curr = $start = $this->packet->packets[$pointer];
|
||||
|
|
@ -116,69 +99,69 @@ class RakNetCodec{
|
|||
$this->buffer .= $payload;
|
||||
break;
|
||||
default:
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function encodeDataPacket(RakNetDataPacket $pk){
|
||||
$this->putByte(($pk->reliability << 5) | ($pk->hasSplit > 0 ? 0b00010000:0));
|
||||
$this->putShort(strlen($pk->buffer) << 3);
|
||||
if($pk->reliability === 2
|
||||
or $pk->reliability === 3
|
||||
or $pk->reliability === 4
|
||||
or $pk->reliability === 6
|
||||
or $pk->reliability === 7){
|
||||
$this->putLTriad($pk->messageIndex);
|
||||
}
|
||||
|
||||
if($pk->reliability === 1
|
||||
or $pk->reliability === 3
|
||||
or $pk->reliability === 4
|
||||
or $pk->reliability === 7){
|
||||
$this->putLTriad($pk->orderIndex);
|
||||
$this->putByte($pk->orderChannel);
|
||||
}
|
||||
|
||||
if($pk->hasSplit === true){
|
||||
$this->putInt($pk->splitCount);
|
||||
$this->putShort($pk->splitID);
|
||||
$this->putInt($pk->splitIndex);
|
||||
}
|
||||
|
||||
$this->buffer .= $pk->buffer;
|
||||
|
||||
protected function putLong($v){
|
||||
$this->buffer .= Utils::writeLong($v);
|
||||
}
|
||||
|
||||
protected function putByte($v){
|
||||
$this->buffer .= chr($v);
|
||||
}
|
||||
|
||||
protected function putShort($v){
|
||||
$this->buffer .= Utils::writeShort($v);
|
||||
}
|
||||
|
||||
protected function putString($v){
|
||||
$this->putShort(strlen($v));
|
||||
$this->put($v);
|
||||
}
|
||||
|
||||
protected function put($str){
|
||||
$this->buffer .= $str;
|
||||
}
|
||||
|
||||
protected function putLong($v){
|
||||
$this->buffer .= Utils::writeLong($v);
|
||||
protected function putLTriad($v){
|
||||
$this->buffer .= strrev(Utils::writeTriad($v));
|
||||
}
|
||||
|
||||
|
||||
private function encodeDataPacket(RakNetDataPacket $pk){
|
||||
$this->putByte(($pk->reliability << 5) | ($pk->hasSplit > 0 ? 0b00010000 : 0));
|
||||
$this->putShort(strlen($pk->buffer) << 3);
|
||||
if($pk->reliability === 2
|
||||
or $pk->reliability === 3
|
||||
or $pk->reliability === 4
|
||||
or $pk->reliability === 6
|
||||
or $pk->reliability === 7){
|
||||
$this->putLTriad($pk->messageIndex);
|
||||
}
|
||||
|
||||
if($pk->reliability === 1
|
||||
or $pk->reliability === 3
|
||||
or $pk->reliability === 4
|
||||
or $pk->reliability === 7){
|
||||
$this->putLTriad($pk->orderIndex);
|
||||
$this->putByte($pk->orderChannel);
|
||||
}
|
||||
|
||||
if($pk->hasSplit === true){
|
||||
$this->putInt($pk->splitCount);
|
||||
$this->putShort($pk->splitID);
|
||||
$this->putInt($pk->splitIndex);
|
||||
}
|
||||
|
||||
$this->buffer .= $pk->buffer;
|
||||
}
|
||||
|
||||
protected function putInt($v){
|
||||
$this->buffer .= Utils::writeInt($v);
|
||||
}
|
||||
|
||||
protected function putShort($v){
|
||||
$this->buffer .= Utils::writeShort($v);
|
||||
}
|
||||
|
||||
protected function putTriad($v){
|
||||
$this->buffer .= Utils::writeTriad($v);
|
||||
}
|
||||
|
||||
protected function putLTriad($v){
|
||||
$this->buffer .= strrev(Utils::writeTriad($v));
|
||||
}
|
||||
|
||||
protected function putByte($v){
|
||||
$this->buffer .= chr($v);
|
||||
}
|
||||
|
||||
protected function putString($v){
|
||||
$this->putShort(strlen($v));
|
||||
$this->put($v);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class RakNetDataPacket extends stdClass{
|
||||
private $offset = 0;
|
||||
|
||||
public $buffer = b"";
|
||||
|
||||
public $reliability = 0;
|
||||
public $hasSplit = false;
|
||||
public $messageIndex;
|
||||
|
|
@ -31,27 +11,31 @@ abstract class RakNetDataPacket extends stdClass{
|
|||
public $splitCount;
|
||||
public $splitID;
|
||||
public $splitIndex;
|
||||
private $offset = 0;
|
||||
|
||||
|
||||
abstract public function pid();
|
||||
|
||||
abstract public function encode();
|
||||
|
||||
|
||||
abstract public function decode();
|
||||
|
||||
protected function reset(){
|
||||
$this->setBuffer(chr($this->pid()));
|
||||
public function getBuffer(){
|
||||
return $this->buffer;
|
||||
}
|
||||
|
||||
|
||||
public function setBuffer($buffer = ""){
|
||||
$this->buffer = $buffer;
|
||||
$this->offset = 0;
|
||||
}
|
||||
|
||||
public function getBuffer(){
|
||||
return $this->buffer;
|
||||
|
||||
protected function reset(){
|
||||
$this->setBuffer(chr($this->pid()));
|
||||
}
|
||||
|
||||
|
||||
abstract public function pid();
|
||||
|
||||
protected function getLong($unsigned = false){
|
||||
return Utils::readLong($this->get(8), $unsigned);
|
||||
}
|
||||
|
||||
protected function get($len){
|
||||
if($len <= 0){
|
||||
$this->offset = strlen($this->buffer) - 1;
|
||||
|
|
@ -62,35 +46,19 @@ abstract class RakNetDataPacket extends stdClass{
|
|||
$this->offset += $len;
|
||||
return substr($this->buffer, $this->offset - $len, $len);
|
||||
}
|
||||
|
||||
protected function put($str){
|
||||
$this->buffer .= $str;
|
||||
}
|
||||
|
||||
protected function getLong($unsigned = false){
|
||||
return Utils::readLong($this->get(8), $unsigned);
|
||||
}
|
||||
|
||||
protected function putLong($v){
|
||||
$this->buffer .= Utils::writeLong($v);
|
||||
}
|
||||
|
||||
|
||||
protected function getInt($unsigned = false){
|
||||
return Utils::readInt($this->get(4), $unsigned);
|
||||
}
|
||||
|
||||
|
||||
protected function putInt($v){
|
||||
$this->buffer .= Utils::writeInt($v);
|
||||
}
|
||||
|
||||
protected function getShort($unsigned = false){
|
||||
return Utils::readShort($this->get(2), $unsigned);
|
||||
}
|
||||
|
||||
protected function putShort($v){
|
||||
$this->buffer .= Utils::writeShort($v);
|
||||
}
|
||||
|
||||
|
||||
protected function getFloat(){
|
||||
return Utils::readFloat($this->get(4));
|
||||
}
|
||||
|
|
@ -99,46 +67,45 @@ abstract class RakNetDataPacket extends stdClass{
|
|||
$this->buffer .= Utils::writeFloat($v);
|
||||
}
|
||||
|
||||
protected function getTriad(){
|
||||
return Utils::readTriad($this->get(3));
|
||||
}
|
||||
|
||||
protected function putTriad($v){
|
||||
$this->buffer .= Utils::writeTriad($v);
|
||||
}
|
||||
|
||||
|
||||
protected function getLTriad(){
|
||||
return Utils::readTriad(strrev($this->get(3)));
|
||||
}
|
||||
|
||||
|
||||
protected function putLTriad($v){
|
||||
$this->buffer .= strrev(Utils::writeTriad($v));
|
||||
}
|
||||
|
||||
protected function getByte(){
|
||||
return ord($this->get(1));
|
||||
}
|
||||
|
||||
protected function putByte($v){
|
||||
$this->buffer .= chr($v);
|
||||
}
|
||||
|
||||
protected function getDataArray($len = 10){
|
||||
$data = array();
|
||||
$data = [];
|
||||
for($i = 1; $i <= $len and !$this->feof(); ++$i){
|
||||
$data[] = $this->get($this->getTriad());
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function putDataArray(array $data = array()){
|
||||
protected function feof(){
|
||||
return !isset($this->buffer[$this->offset]);
|
||||
}
|
||||
|
||||
protected function getTriad(){
|
||||
return Utils::readTriad($this->get(3));
|
||||
}
|
||||
|
||||
protected function putDataArray(array $data = []){
|
||||
foreach($data as $v){
|
||||
$this->putTriad(strlen($v));
|
||||
$this->put($v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function putTriad($v){
|
||||
$this->buffer .= Utils::writeTriad($v);
|
||||
}
|
||||
|
||||
protected function put($str){
|
||||
$this->buffer .= $str;
|
||||
}
|
||||
|
||||
protected function getSlot(){
|
||||
$id = $this->getShort();
|
||||
$cnt = $this->getByte();
|
||||
|
|
@ -148,23 +115,35 @@ abstract class RakNetDataPacket extends stdClass{
|
|||
$cnt
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function getShort($unsigned = false){
|
||||
return Utils::readShort($this->get(2), $unsigned);
|
||||
}
|
||||
|
||||
protected function getByte(){
|
||||
return ord($this->get(1));
|
||||
}
|
||||
|
||||
protected function putSlot(Item $item){
|
||||
$this->putShort($item->getID());
|
||||
$this->putByte($item->count);
|
||||
$this->putShort($item->getMetadata());
|
||||
}
|
||||
|
||||
|
||||
protected function putShort($v){
|
||||
$this->buffer .= Utils::writeShort($v);
|
||||
}
|
||||
|
||||
protected function putByte($v){
|
||||
$this->buffer .= chr($v);
|
||||
}
|
||||
|
||||
protected function getString(){
|
||||
return $this->get($this->getShort(true));
|
||||
}
|
||||
|
||||
|
||||
protected function putString($v){
|
||||
$this->putShort(strlen($v));
|
||||
$this->put($v);
|
||||
}
|
||||
|
||||
protected function feof(){
|
||||
return !isset($this->buffer[$this->offset]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class RakNetInfo{
|
||||
|
||||
const STRUCTURE = 5;
|
||||
const MAGIC = "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78";
|
||||
const UNCONNECTED_PING = 0x01;
|
||||
|
|
@ -55,8 +37,6 @@ abstract class RakNetInfo{
|
|||
const NACK = 0xa0;
|
||||
const ACK = 0xc0;
|
||||
|
||||
|
||||
|
||||
public static function isValid($pid){
|
||||
switch((int) $pid){
|
||||
case RakNetInfo::UNCONNECTED_PING:
|
||||
|
|
|
|||
|
|
@ -1,34 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class RakNetPacket extends Packet{
|
||||
|
||||
private $packetID;
|
||||
|
||||
|
||||
public function __construct($packetID){
|
||||
$this->packetID = (int) $packetID;
|
||||
}
|
||||
|
||||
|
||||
public function pid(){
|
||||
return $this->packetID;
|
||||
}
|
||||
|
||||
public function __destruct(){}
|
||||
|
||||
public function __destruct(){
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class RakNetParser{
|
||||
|
||||
public $packet;
|
||||
private $buffer;
|
||||
private $offset;
|
||||
public $packet;
|
||||
|
||||
|
||||
public function __construct(&$buffer){
|
||||
$this->buffer =& $buffer;
|
||||
$this->offset = 0;
|
||||
|
|
@ -33,44 +15,7 @@ class RakNetParser{
|
|||
$this->packet = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function get($len){
|
||||
if($len <= 0){
|
||||
$this->offset = strlen($this->buffer) - 1;
|
||||
return "";
|
||||
}
|
||||
if($len === true){
|
||||
return substr($this->buffer, $this->offset);
|
||||
}
|
||||
$this->offset += $len;
|
||||
return substr($this->buffer, $this->offset - $len, $len);
|
||||
}
|
||||
|
||||
private function getLong($unsigned = false){
|
||||
return Utils::readLong($this->get(8), $unsigned);
|
||||
}
|
||||
|
||||
private function getInt($unsigned = false){
|
||||
return Utils::readInt($this->get(4), $unsigned);
|
||||
}
|
||||
|
||||
private function getShort($unsigned = false){
|
||||
return Utils::readShort($this->get(2), $unsigned);
|
||||
}
|
||||
|
||||
private function getLTriad(){
|
||||
return Utils::readTriad(strrev($this->get(3)));
|
||||
}
|
||||
|
||||
private function getByte(){
|
||||
return ord($this->get(1));
|
||||
}
|
||||
|
||||
|
||||
private function feof(){
|
||||
return !isset($this->buffer[$this->offset]);
|
||||
}
|
||||
|
||||
|
||||
private function parse(){
|
||||
$this->packet = new RakNetPacket(ord($this->get(1)));
|
||||
$this->packet->buffer =& $this->buffer;
|
||||
|
|
@ -110,15 +55,15 @@ class RakNetParser{
|
|||
case RakNetInfo::DATA_PACKET_E:
|
||||
case RakNetInfo::DATA_PACKET_F:
|
||||
$this->packet->seqNumber = $this->getLTriad();
|
||||
$this->packet->data = array();
|
||||
$this->packet->data = [];
|
||||
while(!$this->feof() and ($pk = $this->parseDataPacket()) instanceof RakNetDataPacket){
|
||||
$this->packet->data[] = $pk;
|
||||
$this->packet->data[] = $pk;
|
||||
}
|
||||
break;
|
||||
case RakNetInfo::NACK:
|
||||
case RakNetInfo::ACK:
|
||||
$count = $this->getShort();
|
||||
$this->packet->packets = array();
|
||||
$this->packet->packets = [];
|
||||
for($i = 0; $i < $count and !$this->feof(); ++$i){
|
||||
if($this->getByte() === 0){
|
||||
$start = $this->getLTriad();
|
||||
|
|
@ -139,33 +84,65 @@ class RakNetParser{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function get($len){
|
||||
if($len <= 0){
|
||||
$this->offset = strlen($this->buffer) - 1;
|
||||
return "";
|
||||
}
|
||||
if($len === true){
|
||||
return substr($this->buffer, $this->offset);
|
||||
}
|
||||
$this->offset += $len;
|
||||
return substr($this->buffer, $this->offset - $len, $len);
|
||||
}
|
||||
|
||||
private function getLong($unsigned = false){
|
||||
return Utils::readLong($this->get(8), $unsigned);
|
||||
}
|
||||
|
||||
private function getByte(){
|
||||
return ord($this->get(1));
|
||||
}
|
||||
|
||||
private function getShort($unsigned = false){
|
||||
return Utils::readShort($this->get(2), $unsigned);
|
||||
}
|
||||
|
||||
private function getLTriad(){
|
||||
return Utils::readTriad(strrev($this->get(3)));
|
||||
}
|
||||
|
||||
private function feof(){
|
||||
return !isset($this->buffer[$this->offset]);
|
||||
}
|
||||
|
||||
private function parseDataPacket(){
|
||||
$packetFlags = $this->getByte();
|
||||
$reliability = ($packetFlags & 0b11100000) >> 5;
|
||||
$hasSplit = ($packetFlags & 0b00010000) > 0;
|
||||
$length = (int) ceil($this->getShort() / 8);
|
||||
if($reliability === 2
|
||||
or $reliability === 3
|
||||
or $reliability === 4
|
||||
or $reliability === 6
|
||||
or $reliability === 7){
|
||||
or $reliability === 3
|
||||
or $reliability === 4
|
||||
or $reliability === 6
|
||||
or $reliability === 7){
|
||||
$messageIndex = $this->getLTriad();
|
||||
}else{
|
||||
$messageIndex = false;
|
||||
}
|
||||
|
||||
|
||||
if($reliability === 1
|
||||
or $reliability === 3
|
||||
or $reliability === 4
|
||||
or $reliability === 7){
|
||||
or $reliability === 3
|
||||
or $reliability === 4
|
||||
or $reliability === 7){
|
||||
$orderIndex = $this->getLTriad();
|
||||
$orderChannel = $this->getByte();
|
||||
}else{
|
||||
$orderIndex = false;
|
||||
$orderChannel = false;
|
||||
}
|
||||
|
||||
|
||||
if($hasSplit == true){
|
||||
$splitCount = $this->getInt();
|
||||
$splitID = $this->getShort();
|
||||
|
|
@ -175,10 +152,10 @@ class RakNetParser{
|
|||
$splitID = false;
|
||||
$splitIndex = false;
|
||||
}
|
||||
|
||||
|
||||
if($length <= 0
|
||||
or $orderChannel >= 32
|
||||
or ($hasSplit === true and $splitIndex >= $splitCount)){
|
||||
or $orderChannel >= 32
|
||||
or ($hasSplit === true and $splitIndex >= $splitCount)){
|
||||
return false;
|
||||
}else{
|
||||
$pid = $this->getByte();
|
||||
|
|
@ -366,4 +343,8 @@ class RakNetParser{
|
|||
return $data;
|
||||
}
|
||||
|
||||
private function getInt($unsigned = false){
|
||||
return Utils::readInt($this->get(4), $unsigned);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue