mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
Update to API 12
This commit is contained in:
parent
731ada7b38
commit
c59b4776ae
149 changed files with 6850 additions and 1918 deletions
|
|
@ -20,241 +20,80 @@
|
|||
*/
|
||||
|
||||
class MinecraftInterface{
|
||||
public $client;
|
||||
public $bandwidth;
|
||||
private $socket;
|
||||
private $data;
|
||||
private $chunked;
|
||||
private $toChunk;
|
||||
private $needCheck;
|
||||
function __construct($object, $server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){
|
||||
$this->socket = new UDPSocket($server, $port, (bool) $listen, $serverip);
|
||||
private $packets;
|
||||
function __construct($server, $port = 25565, $serverip = "0.0.0.0"){
|
||||
$this->socket = new UDPSocket($server, $port, true, $serverip);
|
||||
if($this->socket->connected === false){
|
||||
console("[ERROR] Couldn't bind to $serverip:".$port, true, true, 0);
|
||||
console("[SEVERE] Couldn't bind to $serverip:".$port, true, true, 0);
|
||||
exit(1);
|
||||
}
|
||||
$this->bandwidth = array(0, 0, microtime(true));
|
||||
$this->client = (bool) $client;
|
||||
$this->start = microtime(true);
|
||||
$this->chunked = array();
|
||||
$this->toChunk = array();
|
||||
$this->needCheck = array();
|
||||
$object->schedule(1, array($this, "checkChunked"), array(), true);
|
||||
$this->packets = array();
|
||||
}
|
||||
|
||||
public function close(){
|
||||
return $this->socket->close(false);
|
||||
}
|
||||
|
||||
protected function getStruct($pid){
|
||||
if(isset(Protocol::$raknet[$pid])){
|
||||
return Protocol::$raknet[$pid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function readPacket(){
|
||||
$pk = $this->popPacket();
|
||||
if($this->socket->connected === false){
|
||||
return $pk;
|
||||
return false;
|
||||
}
|
||||
$buf = "";
|
||||
$source = false;
|
||||
$port = 1;
|
||||
$len = $this->socket->read($buf, $source, $port);
|
||||
if($len === false or $len === 0){
|
||||
return $pk;
|
||||
return false;
|
||||
}
|
||||
$this->bandwidth[0] += $len;
|
||||
$this->parsePacket($buf, $source, $port);
|
||||
return ($pk !== false ? $pk : $this->popPacket());
|
||||
return $this->parsePacket($buf, $source, $port);
|
||||
}
|
||||
|
||||
private function parsePacket($buf, $source, $port){
|
||||
$pid = ord($buf{0});
|
||||
$struct = $this->getStruct($pid);
|
||||
if($struct === false){
|
||||
if(ServerAPI::request()->api->dhandle("server.unknownpacket", array(
|
||||
"pid" => $pid,
|
||||
"data" => array(),
|
||||
"raw" => $buf,
|
||||
"ip" => $source,
|
||||
"port" => $port
|
||||
)) !== true){
|
||||
console("[ERROR] Unknown Packet ID 0x".Utils::strToHex(chr($pid)), true, true, 2);
|
||||
private function parsePacket($buffer, $source, $port){
|
||||
$pid = ord($buffer{0});
|
||||
|
||||
if(RakNetInfo::isValid($pid)){
|
||||
$parser = new RakNetParser($buffer);
|
||||
if($parser->packet !== false){
|
||||
$parser->packet->ip = $source;
|
||||
$parser->packet->port = $port;
|
||||
if(EventHandler::callEvent(new PacketReceiveEvent($parser->packet)) === BaseEvent::DENY){
|
||||
return false;
|
||||
}
|
||||
return $parser->packet;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$packet = new Packet($pid, $struct, $buf);
|
||||
@$packet->parse();
|
||||
if($pid === 0x99){
|
||||
$CID = PocketMinecraftServer::clientID($source, $port);
|
||||
if(!isset($this->chunked[$CID]) and $packet->data[0] !== 0){ //Drop packet
|
||||
}elseif($pid === 0xfe and $buffer{1} === "\xfd" and ServerAPI::request()->api->query instanceof QueryHandler){
|
||||
$packet = new QueryPacket;
|
||||
$packet->ip = $source;
|
||||
$packet->port = $port;
|
||||
$packet->buffer = $buffer;
|
||||
if(EventHandler::callEvent(new PacketReceiveEvent($packet)) === BaseEvent::DENY){
|
||||
return false;
|
||||
}
|
||||
switch($packet->data[0]){
|
||||
case 0:
|
||||
$this->initChunked($CID, $source, $port);
|
||||
return false;
|
||||
case 1:
|
||||
$this->stopChunked($CID);
|
||||
return false;
|
||||
case 3:
|
||||
$this->ackChunked($CID, $data[1]["id"], $data[1]["index"]);
|
||||
return false;
|
||||
case 4:
|
||||
$this->receiveChunked($CID, $data[1]["id"], $data[1]["index"], $data[1]["count"], $data[1]["data"]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$this->data[] = array($pid, $packet->data, $buf, $source, $port);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkChunked($CID){
|
||||
$time = microtime(true);
|
||||
foreach($this->needCheck as $CID => $packets){
|
||||
if($packets[-1] < $time){
|
||||
$d = $this->chunked[$CID];
|
||||
unset($packets[-1]);
|
||||
foreach($packets as $packet){
|
||||
$this->writePacket(0x99, $packet, true, $d[1], $d[2], true);
|
||||
}
|
||||
$this->needCheck[$CID][-1] = $time + 5;
|
||||
}
|
||||
}
|
||||
foreach($this->toChunk as $CID => $packets){
|
||||
$d = $this->chunked[$CID];
|
||||
$raw = "";
|
||||
$MTU = 512;
|
||||
foreach($packets as $packet){
|
||||
$raw .= $packet;
|
||||
if(($len = strlen($packet)) > $MTU){
|
||||
$MTU = $len;
|
||||
}
|
||||
}
|
||||
if($MTU > $d[0][2]){
|
||||
$this->chunked[$CID][0][2] = $MTU;
|
||||
}else{
|
||||
$MTU = $d[0][2];
|
||||
}
|
||||
$raw = str_split(gzdeflate($raw, DEFLATEPACKET_LEVEL), $MTU - 9); // - 1 - 2 - 2 - 2 - 2
|
||||
$count = count($raw);
|
||||
$messageID = $this->chunked[$CID][0][0]++;
|
||||
$this->chunked[$CID][0][0] &= 0xFFFF;
|
||||
if(!isset($this->needCheck[$CID])){
|
||||
$this->needCheck[$CID] = array();
|
||||
}
|
||||
$this->needCheck[$CID][$messageID] = array(-1 => $time + 1);
|
||||
foreach($raw as $index => $r){
|
||||
$p = "\x99\x02".Utils::writeShort($messageID).Utils::writeShort($index).Utils::writeShort($count).Utils::writeShort(strlen($r)).$r;
|
||||
$this->needCheck[$CID][$messageID][$index] = $p;
|
||||
$this->writePacket(0x99, $p, true, $d[1], $d[2], true);
|
||||
}
|
||||
unset($this->toChunk[$CID]);
|
||||
}
|
||||
}
|
||||
|
||||
public function isChunked($CID){
|
||||
return isset($this->chunked[$CID]);
|
||||
}
|
||||
|
||||
private function initChunked($CID, $source, $port){
|
||||
console("[DEBUG] Starting DEFLATEPacket for $source:$port", true, true, 2);
|
||||
$this->chunked[$CID] = array(
|
||||
0 => array(0, 0, 0), //index, sent/received; MTU
|
||||
1 => $source,
|
||||
2 => $port,
|
||||
3 => array(), //Received packets
|
||||
);
|
||||
$this->writePacket(0x99, array(
|
||||
0 => 0, //start
|
||||
), false, $source, $port, true);
|
||||
}
|
||||
|
||||
public function stopChunked($CID){
|
||||
if(!isset($this->chunked[$CID])){
|
||||
ServerAPI::request()->api->query->handle($packet);
|
||||
}else{
|
||||
$packet = new Packet();
|
||||
$packet->ip = $source;
|
||||
$packet->port = $port;
|
||||
$packet->buffer = $buffer;
|
||||
EventHandler::callEvent(new PacketReceiveEvent($packet));
|
||||
return false;
|
||||
}
|
||||
$this->writePacket(0x99, array(
|
||||
0 => 1, //stop
|
||||
), false, $this->chunked[$CID][1], $this->chunked[$CID][2], true);
|
||||
console("[DEBUG] Stopping DEFLATEPacket for ".$this->chunked[$CID][1].":".$this->chunked[$CID][2], true, true, 2);
|
||||
$this->chunked[$CID][3] = null;
|
||||
$this->chunked[$CID][4] = null;
|
||||
unset($this->chunked[$CID]);
|
||||
unset($this->toChunk[$CID]);
|
||||
unset($this->needCheck[$CID]);
|
||||
}
|
||||
|
||||
private function ackChunked($CID, $ID, $index){
|
||||
unset($this->needCheck[$CID][$ID][$index]);
|
||||
if(count($this->needCheck[$CID][$ID]) <= 1){
|
||||
unset($this->needCheck[$CID][$ID]);
|
||||
}
|
||||
}
|
||||
|
||||
private function receiveChunked($CID, $ID, $index, $count, $data){
|
||||
if(!isset($this->chunked[$CID][3][$ID])){
|
||||
$this->chunked[$CID][3][$ID] = array();
|
||||
}
|
||||
$this->chunked[$CID][3][$ID][$index] = $data;
|
||||
|
||||
if(count($this->chunked[$CID][3][$ID]) === $count){
|
||||
ksort($this->chunked[$CID][3][$ID]);
|
||||
$data = gzinflate(implode($this->chunked[$CID][3][$ID]), 524280);
|
||||
unset($this->chunked[$CID][3][$ID]);
|
||||
if($data === false or strlen($data) === 0){
|
||||
console("[ERROR] Invalid DEFLATEPacket for ".$this->chunked[$CID][1].":".$this->chunked[$CID][2], true, true, 2);
|
||||
}
|
||||
$offset = 0;
|
||||
while(($plen = Utils::readShort(substr($data, $offset, 2), false)) !== 0xFFFF or $offset >= $len){
|
||||
$offset += 2;
|
||||
$packet = substr($data, $offset, $plen);
|
||||
$this->parsePacket($packet, $this->chunked[$CID][1], $this->chunked[$CID][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function popPacket(){
|
||||
if(count($this->data) > 0){
|
||||
$p = each($this->data);
|
||||
unset($this->data[$p[0]]);
|
||||
$p = $p[1];
|
||||
return array("pid" => $p[0], "data" => $p[1], "raw" => $p[2], "ip" => $p[3], "port" => $p[4]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false, $force = false){
|
||||
$CID = PocketMinecraftServer::clientID($dest, $port);
|
||||
if($raw === false){
|
||||
$packet = new Packet($pid, $this->getStruct($pid));
|
||||
$packet->data = $data;
|
||||
@$packet->create();
|
||||
if($force === false and $this->isChunked($CID)){
|
||||
if(!isset($this->toChunk[$CID])){
|
||||
$this->toChunk[$CID] = array();
|
||||
}
|
||||
$this->toChunk[$CID][] = $packet->raw;
|
||||
$write = strlen($packet->raw);
|
||||
}else{
|
||||
$write = $this->socket->write($packet->raw, $dest, $port);
|
||||
$this->bandwidth[1] += $write;
|
||||
}
|
||||
}else{
|
||||
if($force === false and $this->isChunked($CID)){
|
||||
if(!isset($this->toChunk[$CID])){
|
||||
$this->toChunk[$CID] = array();
|
||||
}
|
||||
$this->toChunk[$CID][] = $data;
|
||||
$write = strlen($data);
|
||||
}else{
|
||||
$write = $this->socket->write($data, $dest, $port);
|
||||
$this->bandwidth[1] += $write;
|
||||
}
|
||||
public function writePacket(Packet $packet){
|
||||
if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){
|
||||
return 0;
|
||||
}elseif($packet instanceof RakNetPacket){
|
||||
$codec = new RakNetCodec($packet);
|
||||
}
|
||||
$write = $this->socket->write($packet->buffer, $packet->ip, $packet->port);
|
||||
$this->bandwidth[1] += $write;
|
||||
return $write;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,325 +19,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
class Packet{
|
||||
private $struct;
|
||||
protected $pid, $packet;
|
||||
public $data, $raw;
|
||||
|
||||
function __construct($pid, $struct, $data = ""){
|
||||
$this->pid = $pid;
|
||||
$this->offset = 1;
|
||||
$this->raw = $data;
|
||||
$this->data = array();
|
||||
if($data === ""){
|
||||
$this->addRaw(chr($pid));
|
||||
}
|
||||
$this->struct = $struct;
|
||||
}
|
||||
|
||||
public function create($raw = false){
|
||||
foreach($this->struct as $field => $type){
|
||||
if(!isset($this->data[$field])){
|
||||
$this->data[$field] = "";
|
||||
}
|
||||
if($raw === true){
|
||||
$this->addRaw($this->data[$field]);
|
||||
continue;
|
||||
}
|
||||
switch($type){
|
||||
case "special1":
|
||||
switch($this->pid){
|
||||
case 0x99:
|
||||
if($this->data[0] >= 2){
|
||||
$this->addRaw(Utils::writeShort($this->data[1]["id"]));
|
||||
$this->addRaw(Utils::writeShort($this->data[1]["index"]));
|
||||
if($this->data[0] === 2){
|
||||
$this->addRaw(Utils::writeShort($this->data[1]["count"]));
|
||||
$this->addRaw(Utils::writeShort(strlen($this->data[1]["data"])).$this->data[1]["data"]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xc0:
|
||||
case 0xa0:
|
||||
$payload = "";
|
||||
$records = 0;
|
||||
$pointer = 0;
|
||||
sort($this->data[$field], SORT_NUMERIC);
|
||||
$max = count($this->data[$field]);
|
||||
while($pointer < $max){
|
||||
$type = true;
|
||||
$curr = $start = $this->data[$field][$pointer];
|
||||
for($i = $start + 1; $i < $max; ++$i){
|
||||
$n = $this->data[$field][$i];
|
||||
if(($n - $curr) === 1){
|
||||
$curr = $end = $n;
|
||||
$type = false;
|
||||
$pointer = $i + 1;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
++$pointer;
|
||||
if($type === false){
|
||||
$payload .= Utils::writeBool(false);
|
||||
$payload .= strrev(Utils::writeTriad($start));
|
||||
$payload .= strrev(Utils::writeTriad($end));
|
||||
}else{
|
||||
$payload .= Utils::writeBool(true);
|
||||
$payload .= strrev(Utils::writeTriad($start));
|
||||
}
|
||||
++$records;
|
||||
}
|
||||
$this->addRaw(Utils::writeShort($records) . $payload);
|
||||
break;
|
||||
case 0x05:
|
||||
$this->addRaw($this->data[$field]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "customData":
|
||||
$this->addRaw(chr($this->data[1]));
|
||||
if($this->data[2]["id"] === false){
|
||||
$this->addRaw($this->data[2]["raw"]);
|
||||
}else{
|
||||
switch($this->data[1]){
|
||||
case 0x40:
|
||||
$reply = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true);
|
||||
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
|
||||
$this->addRaw(strrev(Utils::writeTriad($this->data[2]["count"])));
|
||||
$this->addRaw(chr($this->data[2]["id"]));
|
||||
$this->addRaw($reply->raw);
|
||||
break;
|
||||
case 0x00:
|
||||
$raw = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true);
|
||||
$raw = $raw->raw;
|
||||
$this->addRaw(Utils::writeShort((strlen($raw) + 1) << 3));
|
||||
$this->addRaw(chr($this->data[2]["id"]));
|
||||
$this->addRaw($raw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case "magic":
|
||||
$this->addRaw(RAKNET_MAGIC);
|
||||
break;
|
||||
case "float":
|
||||
$this->addRaw(Utils::writeFloat($this->data[$field]));
|
||||
break;
|
||||
case "triad":
|
||||
$this->addRaw(Utils::writeTriad($this->data[$field]));
|
||||
break;
|
||||
case "itriad":
|
||||
$this->addRaw(strrev(Utils::writeTriad($this->data[$field])));
|
||||
break;
|
||||
case "int":
|
||||
$this->addRaw(Utils::writeInt($this->data[$field]));
|
||||
break;
|
||||
case "double":
|
||||
$this->addRaw(Utils::writeDouble($this->data[$field]));
|
||||
break;
|
||||
case "long":
|
||||
$this->addRaw(Utils::writeLong($this->data[$field]));
|
||||
break;
|
||||
case "bool":
|
||||
case "boolean":
|
||||
$this->addRaw(Utils::writeBool($this->data[$field]));
|
||||
break;
|
||||
case "ubyte":
|
||||
case "byte":
|
||||
$this->addRaw(Utils::writeByte($this->data[$field]));
|
||||
break;
|
||||
case "short":
|
||||
$this->addRaw(Utils::writeShort($this->data[$field]));
|
||||
break;
|
||||
case "string":
|
||||
$this->addRaw(Utils::writeShort(strlen($this->data[$field])));
|
||||
$this->addRaw($this->data[$field]);
|
||||
break;
|
||||
default:
|
||||
$this->addRaw(Utils::writeByte($this->data[$field]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function get($len = true){
|
||||
if($len === true){
|
||||
$data = substr($this->raw, $this->offset);
|
||||
$this->offset = strlen($this->raw);
|
||||
return $data;
|
||||
}
|
||||
$data = substr($this->raw, $this->offset, $len);
|
||||
$this->offset += $len;
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function feof(){
|
||||
return !isset($this->raw{$this->offset});
|
||||
}
|
||||
|
||||
protected function addRaw($str){
|
||||
$this->raw .= $str;
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function parse(){
|
||||
foreach($this->struct as $field => $type){
|
||||
switch($type){
|
||||
case "special1":
|
||||
switch($this->pid){
|
||||
case 0x07:
|
||||
$this->data[] = $this->get(5);
|
||||
break;
|
||||
case 0x99:
|
||||
if($this->data[0] >= 2){ //
|
||||
$messageID = Utils::readShort($this->get(2), false);
|
||||
$messageIndex = Utils::readShort($this->get(2), false);
|
||||
$this->data[1] = array("id" => $messageID, "index" => $messageIndex);
|
||||
if($this->data[0] === 2){
|
||||
$this->data[1]["count"] = Utils::readShort($this->get(2), false);
|
||||
$dataLength = Utils::readShort($this->get(2), false);
|
||||
$this->data[1]["data"] = $this->get($dataLength);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xc0:
|
||||
case 0xa0:
|
||||
$cnt = Utils::readShort($this->get(2), false);
|
||||
$this->data[$field] = array();
|
||||
for($i = 0; $i < $cnt and !$this->feof(); ++$i){
|
||||
if(Utils::readBool($this->get(1)) === false){
|
||||
$start = Utils::readTriad(strrev($this->get(3)));
|
||||
$end = min(Utils::readTriad(strrev($this->get(3))), $start + 4096);
|
||||
for($c = $start; $c <= $end; ++$c){
|
||||
$this->data[$field][] = $c;
|
||||
}
|
||||
}else{
|
||||
$this->data[$field][] = Utils::readTriad(strrev($this->get(3)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x05:
|
||||
$this->data[] = $this->get(true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "customData":
|
||||
$raw = $this->get(true);
|
||||
$len = strlen($raw);
|
||||
$offset = 0;
|
||||
$this->data["packets"] = array();
|
||||
while($len > $offset){
|
||||
$pid = ord($raw{$offset});
|
||||
++$offset;
|
||||
$reliability = ($pid & 0b11100000) >> 5;
|
||||
$hasSplit = ($pid & 0b00010000) >> 4;
|
||||
$length = Utils::readShort(substr($raw, $offset, 2), false);
|
||||
$offset += 2;
|
||||
if($reliability === 2
|
||||
or $reliability === 3
|
||||
or $reliability === 4
|
||||
or $reliability === 6
|
||||
or $reliability === 7){
|
||||
$messageIndex = Utils::readTriad(strrev(substr($raw, $offset, 3)));
|
||||
$offset += 3;
|
||||
}else{
|
||||
$messageIndex = 0;
|
||||
}
|
||||
|
||||
if($reliability === 1
|
||||
or $reliability === 3
|
||||
or $reliability === 4
|
||||
or $reliability === 7){
|
||||
$orderIndex = Utils::readTriad(strrev(substr($raw, $offset, 3)));
|
||||
$offset += 3;
|
||||
$orderChannel = ord($raw{$offset}); //5 bits, 32 values
|
||||
++$offset;
|
||||
}else{
|
||||
$orderIndex = 0;
|
||||
$orderChannel = 0;
|
||||
}
|
||||
|
||||
if($hasSplit === 1){
|
||||
$splitCount = Utils::readInt(substr($raw, $offset, 4));
|
||||
$offset += 4;
|
||||
$splitID = Utils::readShort(substr($raw, $offset, 2));
|
||||
$offset += 2;
|
||||
$splitIndex = Utils::readInt(substr($raw, $offset, 4));
|
||||
$offset += 4;
|
||||
//error! no split packets allowed!
|
||||
break;
|
||||
}else{
|
||||
$splitCount = 0;
|
||||
$splitID = 0;
|
||||
$splitIndex = 0;
|
||||
}
|
||||
|
||||
if($length == 0
|
||||
or $orderChannel >= 32
|
||||
or ($hasSplit === 1 and $splitIndex >= $splitCount)){
|
||||
continue;
|
||||
}
|
||||
$ln = ceil($length / 8);
|
||||
$id = ord($raw{$offset});
|
||||
++$offset;
|
||||
$pak = substr($raw, $offset, $ln - 1);
|
||||
$offset += $ln - 1;
|
||||
$pk = new CustomPacketHandler($id, $pak);
|
||||
$pk->data["length"] = $ln;
|
||||
$pk->data["id"] = $id;
|
||||
$pk->data["counter"] = $messageIndex;
|
||||
$pk->data["packetName"] = $pk->name;
|
||||
$this->data["packets"][] = array($pid, $pk->data, $pak);
|
||||
}
|
||||
break;
|
||||
case "magic":
|
||||
$this->data[] = $this->get(16);
|
||||
break;
|
||||
case "triad":
|
||||
$this->data[] = Utils::readTriad($this->get(3));
|
||||
break;
|
||||
case "itriad":
|
||||
$this->data[] = Utils::readTriad(strrev($this->get(3)));
|
||||
break;
|
||||
case "int":
|
||||
$this->data[] = Utils::readInt($this->get(4));
|
||||
break;
|
||||
case "string":
|
||||
$this->data[] = $this->get(Utils::readShort($this->get(2)));
|
||||
break;
|
||||
case "long":
|
||||
$this->data[] = Utils::readLong($this->get(8));
|
||||
break;
|
||||
case "byte":
|
||||
$this->data[] = Utils::readByte($this->get(1));
|
||||
break;
|
||||
case "ubyte":
|
||||
$this->data[] = ord($this->get(1));
|
||||
break;
|
||||
case "float":
|
||||
$this->data[] = Utils::readFloat($this->get(4));
|
||||
break;
|
||||
case "double":
|
||||
$this->data[] = Utils::readDouble($this->get(8));
|
||||
break;
|
||||
case "ushort":
|
||||
$this->data[] = Utils::readShort($this->get(2), false);
|
||||
break;
|
||||
case "short":
|
||||
$this->data[] = Utils::readShort($this->get(2));
|
||||
break;
|
||||
case "bool":
|
||||
case "boolean":
|
||||
$this->data[] = Utils::readBool($this->get(1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Packet extends stdClass{
|
||||
public $ip;
|
||||
public $port;
|
||||
public $buffer;
|
||||
|
||||
}
|
||||
|
|
@ -55,6 +55,8 @@ class RCON{
|
|||
for($n = 0; $n < $this->threads; ++$n){
|
||||
$this->workers[$n]->close();
|
||||
$this->workers[$n]->join();
|
||||
usleep(50000);
|
||||
$this->workers[$n]->kill();
|
||||
}
|
||||
@socket_close($this->socket);
|
||||
$this->threads = 0;
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ class UDPSocket{
|
|||
return @socket_recvfrom($this->sock, $buf, 65535, 0, $source, $port);
|
||||
}
|
||||
|
||||
public function write($data, $dest = false, $port = false){
|
||||
public function write($data, $dest, $port){
|
||||
if($this->connected === false){
|
||||
return false;
|
||||
}
|
||||
return @socket_sendto($this->sock, $data, strlen($data), 0, ($dest === false ? $this->server:$dest), ($port === false ? $this->port:$port));
|
||||
return @socket_sendto($this->sock, $data, strlen($data), 0, $dest, $port);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
160
src/network/protocol/ProtocolInfo.php
Normal file
160
src/network/protocol/ProtocolInfo.php
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<?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 ProtocolInfo{
|
||||
|
||||
const CURRENT_PROTOCOL = 14;
|
||||
|
||||
|
||||
|
||||
const PING_PACKET = 0x00;
|
||||
|
||||
const PONG_PACKET = 0x03;
|
||||
|
||||
const CLIENT_CONNECT_PACKET = 0x09;
|
||||
const SERVER_HANDSHAKE_PACKET = 0x10;
|
||||
|
||||
const CLIENT_HANDSHAKE_PACKET = 0x13;
|
||||
//const SERVER_FULL_PACKET = 0x14;
|
||||
const DISCONNECT_PACKET = 0x15;
|
||||
|
||||
//const BANNED_PACKET = 0x17;
|
||||
|
||||
|
||||
const LOGIN_PACKET = 0x82;
|
||||
const LOGIN_STATUS_PACKET = 0x83;
|
||||
const READY_PACKET = 0x84;
|
||||
const MESSAGE_PACKET = 0x85;
|
||||
const SET_TIME_PACKET = 0x86;
|
||||
const START_GAME_PACKET = 0x87;
|
||||
const ADD_MOB_PACKET = 0x88;
|
||||
const ADD_PLAYER_PACKET = 0x89;
|
||||
const REMOVE_PLAYER_PACKET = 0x8a;
|
||||
|
||||
const ADD_ENTITY_PACKET = 0x8c;
|
||||
const REMOVE_ENTITY_PACKET = 0x8d;
|
||||
const ADD_ITEM_ENTITY_PACKET = 0x8e;
|
||||
const TAKE_ITEM_ENTITY_PACKET = 0x8f;
|
||||
const MOVE_ENTITY_PACKET = 0x90;
|
||||
|
||||
const MOVE_ENTITY_PACKET_POSROT = 0x93;
|
||||
const ROTATE_HEAD_PACKET = 0x94;
|
||||
const MOVE_PLAYER_PACKET = 0x95;
|
||||
//const PLACE_BLOCK_PACKET = 0x96;
|
||||
const REMOVE_BLOCK_PACKET = 0x97;
|
||||
const UPDATE_BLOCK_PACKET = 0x98;
|
||||
const ADD_PAINTING_PACKET = 0x99;
|
||||
const EXPLODE_PACKET = 0x9a;
|
||||
const LEVEL_EVENT_PACKET = 0x9b;
|
||||
const TILE_EVENT_PACKET = 0x9c;
|
||||
const ENTITY_EVENT_PACKET = 0x9d;
|
||||
const REQUEST_CHUNK_PACKET = 0x9e;
|
||||
const CHUNK_DATA_PACKET = 0x9f;
|
||||
const PLAYER_EQUIPMENT_PACKET = 0xa0;
|
||||
const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa1;
|
||||
const INTERACT_PACKET = 0xa2;
|
||||
const USE_ITEM_PACKET = 0xa3;
|
||||
const PLAYER_ACTION_PACKET = 0xa4;
|
||||
|
||||
const HURT_ARMOR_PACKET = 0xa6;
|
||||
const SET_ENTITY_DATA_PACKET = 0xa7;
|
||||
const SET_ENTITY_MOTION_PACKET = 0xa8;
|
||||
//const SET_ENTITY_LINK_PACKET = 0xa9;
|
||||
const SET_HEALTH_PACKET = 0xaa;
|
||||
const SET_SPAWN_POSITION_PACKET = 0xab;
|
||||
const ANIMATE_PACKET = 0xac;
|
||||
const RESPAWN_PACKET = 0xad;
|
||||
const SEND_INVENTORY_PACKET = 0xae;
|
||||
const DROP_ITEM_PACKET = 0xaf;
|
||||
const CONTAINER_OPEN_PACKET = 0xb0;
|
||||
const CONTAINER_CLOSE_PACKET = 0xb1;
|
||||
const CONTAINER_SET_SLOT_PACKET = 0xb2;
|
||||
const CONTAINER_SET_DATA_PACKET = 0xb3;
|
||||
const CONTAINER_SET_CONTENT_PACKET = 0xb4;
|
||||
//const CONTAINER_ACK_PACKET = 0xb5;
|
||||
const CHAT_PACKET = 0xb6;
|
||||
const ADVENTURE_SETTINGS_PACKET = 0xb7;
|
||||
const ENTITY_DATA_PACKET = 0xb8;
|
||||
//const PLAYER_INPUT_PACKET = 0xb9;
|
||||
|
||||
public static $packets = array(
|
||||
-1 => "UnknownPacket",
|
||||
ProtocolInfo::PING_PACKET => "PingPacket",
|
||||
ProtocolInfo::PONG_PACKET => "PongPacket",
|
||||
ProtocolInfo::CLIENT_CONNECT_PACKET => "ClientConnectPacket",
|
||||
ProtocolInfo::SERVER_HANDSHAKE_PACKET => "ServerHandshakePacket",
|
||||
ProtocolInfo::DISCONNECT_PACKET => "DisconnectPacket",
|
||||
ProtocolInfo::LOGIN_PACKET => "LoginPacket",
|
||||
ProtocolInfo::LOGIN_STATUS_PACKET => "LoginStatusPacket",
|
||||
ProtocolInfo::READY_PACKET => "ReadyPacket",
|
||||
ProtocolInfo::MESSAGE_PACKET => "MessagePacket",
|
||||
ProtocolInfo::SET_TIME_PACKET => "SetTimePacket",
|
||||
ProtocolInfo::START_GAME_PACKET => "StartGamePacket",
|
||||
ProtocolInfo::ADD_MOB_PACKET => "AddMobPacket",
|
||||
ProtocolInfo::ADD_PLAYER_PACKET => "AddPlayerPacket",
|
||||
ProtocolInfo::REMOVE_PLAYER_PACKET => "RemovePlayerPacket",
|
||||
ProtocolInfo::ADD_ENTITY_PACKET => "AddEntityPacket",
|
||||
ProtocolInfo::REMOVE_ENTITY_PACKET => "RemoveEntityPacket",
|
||||
ProtocolInfo::ADD_ITEM_ENTITY_PACKET => "AddItemEntityPacket",
|
||||
ProtocolInfo::TAKE_ITEM_ENTITY_PACKET => "TakeItemEntityPacket",
|
||||
ProtocolInfo::MOVE_ENTITY_PACKET => "MoveEntityPacket",
|
||||
ProtocolInfo::MOVE_ENTITY_PACKET_POSROT => "MoveEntityPacket_PosRot",
|
||||
ProtocolInfo::ROTATE_HEAD_PACKET => "RotateHeadPacket",
|
||||
ProtocolInfo::MOVE_PLAYER_PACKET => "MovePlayerPacket",
|
||||
ProtocolInfo::REMOVE_BLOCK_PACKET => "RemoveBlockPacket",
|
||||
ProtocolInfo::UPDATE_BLOCK_PACKET => "UpdateBlockPacket",
|
||||
ProtocolInfo::ADD_PAINTING_PACKET => "AddPaintingPacket",
|
||||
ProtocolInfo::EXPLODE_PACKET => "ExplodePacket",
|
||||
ProtocolInfo::LEVEL_EVENT_PACKET => "LevelEventPacket",
|
||||
ProtocolInfo::TILE_EVENT_PACKET => "TileEventPacket",
|
||||
ProtocolInfo::ENTITY_EVENT_PACKET => "EntityEventPacket",
|
||||
ProtocolInfo::REQUEST_CHUNK_PACKET => "RequestChunkPacket",
|
||||
ProtocolInfo::CHUNK_DATA_PACKET => "ChunkDataPacket",
|
||||
ProtocolInfo::PLAYER_EQUIPMENT_PACKET => "PlayerEquipmentPacket",
|
||||
ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET => "PlayerArmorEquipmentPacket",
|
||||
ProtocolInfo::INTERACT_PACKET => "InteractPacket",
|
||||
ProtocolInfo::USE_ITEM_PACKET => "UseItemPacket",
|
||||
ProtocolInfo::PLAYER_ACTION_PACKET => "PlayerActionPacket",
|
||||
ProtocolInfo::HURT_ARMOR_PACKET => "HurtArmorPacket",
|
||||
ProtocolInfo::SET_ENTITY_DATA_PACKET => "SetEntityDataPacket",
|
||||
ProtocolInfo::SET_ENTITY_MOTION_PACKET => "SetEntityMotionPacket",
|
||||
ProtocolInfo::SET_HEALTH_PACKET => "SetHealthPacket",
|
||||
ProtocolInfo::SET_SPAWN_POSITION_PACKET => "SetSpawnPositionPacket",
|
||||
ProtocolInfo::ANIMATE_PACKET => "AnimatePacket",
|
||||
ProtocolInfo::RESPAWN_PACKET => "RespawnPacket",
|
||||
ProtocolInfo::SEND_INVENTORY_PACKET => "SendInventoryPacket",
|
||||
ProtocolInfo::DROP_ITEM_PACKET => "DropItemPacket",
|
||||
ProtocolInfo::CONTAINER_OPEN_PACKET => "ContainerOpenPacket",
|
||||
ProtocolInfo::CONTAINER_CLOSE_PACKET => "ContainerClosePacket",
|
||||
ProtocolInfo::CONTAINER_SET_SLOT_PACKET => "ContainerSetSlotPacket",
|
||||
ProtocolInfo::CONTAINER_SET_DATA_PACKET => "ContainerSetDataPacket",
|
||||
ProtocolInfo::CONTAINER_SET_CONTENT_PACKET => "ContainerSetContentPacket",
|
||||
ProtocolInfo::CHAT_PACKET => "ChatPacket",
|
||||
ProtocolInfo::ADVENTURE_SETTINGS_PACKET => "AdventureSettingsPacket",
|
||||
ProtocolInfo::ENTITY_DATA_PACKET => "EntityDataPacket",
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/***REM_START***/
|
||||
require_once(FILE_PATH . "src/network/raknet/RakNetDataPacket.php");
|
||||
/***REM_END***/
|
||||
56
src/network/protocol/packet/AddEntityPacket.php
Normal file
56
src/network/protocol/packet/AddEntityPacket.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?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 AddEntityPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $type;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $did;
|
||||
public $speedX;
|
||||
public $speedY;
|
||||
public $speedZ;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ADD_ENTITY_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putByte($this->type);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putInt($this->did);
|
||||
if($this->did > 0){
|
||||
$this->putShort($this->speedX);
|
||||
$this->putShort($this->speedY);
|
||||
$this->putShort($this->speedZ);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
52
src/network/protocol/packet/AddItemEntityPacket.php
Normal file
52
src/network/protocol/packet/AddItemEntityPacket.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?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 AddItemEntityPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $item;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $yaw;
|
||||
public $pitch;
|
||||
public $roll;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ADD_ITEM_ENTITY_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putSlot($this->item);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putByte($this->yaw);
|
||||
$this->putByte($this->pitch);
|
||||
$this->putByte($this->roll);
|
||||
}
|
||||
|
||||
}
|
||||
52
src/network/protocol/packet/AddMobPacket.php
Normal file
52
src/network/protocol/packet/AddMobPacket.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?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 AddMobPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $type;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $pitch;
|
||||
public $yaw;
|
||||
public $metadata;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ADD_MOB_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putInt($this->type);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putByte($this->yaw);
|
||||
$this->putByte($this->pitch);
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
|
||||
}
|
||||
48
src/network/protocol/packet/AddPaintingPacket.php
Normal file
48
src/network/protocol/packet/AddPaintingPacket.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?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 AddPaintingPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $direction;
|
||||
public $title;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ADD_PAINTING_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putInt($this->x);
|
||||
$this->putInt($this->y);
|
||||
$this->putInt($this->z);
|
||||
$this->putInt($this->direction);
|
||||
$this->putString($this->title);
|
||||
}
|
||||
|
||||
}
|
||||
58
src/network/protocol/packet/AddPlayerPacket.php
Normal file
58
src/network/protocol/packet/AddPlayerPacket.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?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 AddPlayerPacket extends RakNetDataPacket{
|
||||
public $clientID;
|
||||
public $username;
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $pitch;
|
||||
public $yaw;
|
||||
public $unknown1;
|
||||
public $unknown2;
|
||||
public $metadata;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ADD_PLAYER_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putLong($this->clientID);
|
||||
$this->putString($this->username);
|
||||
$this->putInt($this->eid);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putByte($this->yaw);
|
||||
$this->putByte($this->pitch);
|
||||
$this->putShort($this->unknown1);
|
||||
$this->putShort($this->unknown2);
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/AdventureSettingsPacket.php
Normal file
38
src/network/protocol/packet/AdventureSettingsPacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 AdventureSettingsPacket extends RakNetDataPacket{
|
||||
public $flags;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ADVENTURE_SETTINGS_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->flags);
|
||||
}
|
||||
|
||||
}
|
||||
41
src/network/protocol/packet/AnimatePacket.php
Normal file
41
src/network/protocol/packet/AnimatePacket.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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 AnimatePacket extends RakNetDataPacket{
|
||||
public $action;
|
||||
public $eid;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ANIMATE_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->action = $this->getByte();
|
||||
$this->eid = $this->getInt();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->action);
|
||||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/ChatPacket.php
Normal file
38
src/network/protocol/packet/ChatPacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 ChatPacket extends RakNetDataPacket{
|
||||
public $message;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CHAT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putString($this->message);
|
||||
}
|
||||
|
||||
}
|
||||
42
src/network/protocol/packet/ChunkDataPacket.php
Normal file
42
src/network/protocol/packet/ChunkDataPacket.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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 ChunkDataPacket extends RakNetDataPacket{
|
||||
public $chunkX;
|
||||
public $chunkZ;
|
||||
public $data;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CHUNK_DATA_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->chunkX);
|
||||
$this->putInt($this->chunkZ);
|
||||
$this->put($this->data);
|
||||
}
|
||||
|
||||
}
|
||||
41
src/network/protocol/packet/ClientConnectPacket.php
Normal file
41
src/network/protocol/packet/ClientConnectPacket.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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 ClientConnectPacket extends RakNetDataPacket{
|
||||
public $clientID;
|
||||
public $session;
|
||||
public $unknown1;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CLIENT_CONNECT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->clientID = $this->getLong();
|
||||
$this->session = $this->getLong();
|
||||
$this->unknown1 = $this->get(1);
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
51
src/network/protocol/packet/ClientHandshakePacket.php
Normal file
51
src/network/protocol/packet/ClientHandshakePacket.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?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 ClientHandshakePacket extends RakNetDataPacket{
|
||||
public $cookie;
|
||||
public $security;
|
||||
public $port;
|
||||
public $dataArray0;
|
||||
public $dataArray;
|
||||
public $timestamp;
|
||||
public $session2;
|
||||
public $session;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CLIENT_HANDSHAKE_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->cookie = $this->get(4);
|
||||
$this->security = $this->get(1);
|
||||
$this->port = $this->getShort(true);
|
||||
$this->dataArray0 = $this->get($this->getByte());
|
||||
$this->dataArray = $this->getDataArray(9);
|
||||
$this->timestamp = $this->get(2);
|
||||
$this->session2 = $this->getLong();
|
||||
$this->session = $this->getLong();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/ContainerClosePacket.php
Normal file
38
src/network/protocol/packet/ContainerClosePacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 ContainerClosePacket extends RakNetDataPacket{
|
||||
public $windowid;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CONTAINER_CLOSE_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->windowid = $this->getByte();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->windowid);
|
||||
}
|
||||
|
||||
}
|
||||
48
src/network/protocol/packet/ContainerOpenPacket.php
Normal file
48
src/network/protocol/packet/ContainerOpenPacket.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?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 ContainerOpenPacket extends RakNetDataPacket{
|
||||
public $windowid;
|
||||
public $type;
|
||||
public $slots;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CONTAINER_OPEN_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->windowid);
|
||||
$this->putByte($this->type);
|
||||
$this->putByte($this->slots);
|
||||
$this->putInt($this->x);
|
||||
$this->putInt($this->y);
|
||||
$this->putInt($this->z);
|
||||
}
|
||||
|
||||
}
|
||||
60
src/network/protocol/packet/ContainerSetContentPacket.php
Normal file
60
src/network/protocol/packet/ContainerSetContentPacket.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?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 ContainerSetContentPacket extends RakNetDataPacket{
|
||||
public $windowid;
|
||||
public $slots = array();
|
||||
public $hotbar = array();
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CONTAINER_SET_CONTENT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->windowid = $this->getByte();
|
||||
$count = $this->getShort();
|
||||
for($s = 0; $s < $count and !$this->feof(); ++$s){
|
||||
$this->slots[$s] = $this->getSlot();
|
||||
}
|
||||
if($this->windowid === 0){
|
||||
$count = $this->getShort();
|
||||
for($s = 0; $s < $count and !$this->feof(); ++$s){
|
||||
$this->hotbar[$s] = $this->getInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->windowid);
|
||||
$this->putShort(count($this->slots));
|
||||
foreach($this->slots as $slot){
|
||||
$this->putSlot($slot);
|
||||
}
|
||||
if($this->windowid === 0 and count($this->hotbar) > 0){
|
||||
$this->putShort(count($this->hotbar));
|
||||
foreach($this->hotbar as $slot){
|
||||
$this->putInt($slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
42
src/network/protocol/packet/ContainerSetDataPacket.php
Normal file
42
src/network/protocol/packet/ContainerSetDataPacket.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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 ContainerSetDataPacket extends RakNetDataPacket{
|
||||
public $windowid;
|
||||
public $property;
|
||||
public $value;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CONTAINER_SET_DATA_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->windowid);
|
||||
$this->putShort($this->property);
|
||||
$this->putShort($this->value);
|
||||
}
|
||||
|
||||
}
|
||||
44
src/network/protocol/packet/ContainerSetSlotPacket.php
Normal file
44
src/network/protocol/packet/ContainerSetSlotPacket.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?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 ContainerSetSlotPacket extends RakNetDataPacket{
|
||||
public $windowid;
|
||||
public $slot;
|
||||
public $item;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::CONTAINER_SET_SLOT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->windowid = $this->getByte();
|
||||
$this->slot = $this->getShort();
|
||||
$this->item = $this->getSlot();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->windowid);
|
||||
$this->putShort($this->slot);
|
||||
$this->putSlot($this->item);
|
||||
}
|
||||
|
||||
}
|
||||
35
src/network/protocol/packet/DisconnectPacket.php
Normal file
35
src/network/protocol/packet/DisconnectPacket.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?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 DisconnectPacket extends RakNetDataPacket{
|
||||
public function pid(){
|
||||
return ProtocolInfo::DISCONNECT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
}
|
||||
41
src/network/protocol/packet/DropItemPacket.php
Normal file
41
src/network/protocol/packet/DropItemPacket.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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 DropItemPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $unknown;
|
||||
public $item;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::DROP_ITEM_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->unknown = $this->getByte();
|
||||
$this->item = $this->getSlot();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
src/network/protocol/packet/EntityDataPacket.php
Normal file
47
src/network/protocol/packet/EntityDataPacket.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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 EntityDataPacket extends RakNetDataPacket{
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $namedtag;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ENTITY_DATA_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->x = $this->getShort();
|
||||
$this->y = $this->getByte();
|
||||
$this->z = $this->getShort();
|
||||
$this->namedtag = $this->get(true);
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putShort($this->x);
|
||||
$this->putByte($this->y);
|
||||
$this->putShort($this->z);
|
||||
$this->put($this->namedtag);
|
||||
}
|
||||
|
||||
}
|
||||
41
src/network/protocol/packet/EntityEventPacket.php
Normal file
41
src/network/protocol/packet/EntityEventPacket.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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 EntityEventPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $event;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ENTITY_EVENT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->event = $this->getByte();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putByte($this->event);
|
||||
}
|
||||
|
||||
}
|
||||
53
src/network/protocol/packet/ExplodePacket.php
Normal file
53
src/network/protocol/packet/ExplodePacket.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?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 ExplodePacket extends RakNetDataPacket{
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $radius;
|
||||
public $records;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::EXPLODE_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putFloat($this->radius);
|
||||
$this->putInt(@count($this->records));
|
||||
if(@count($this->records) > 0){
|
||||
foreach($this->records as $record){
|
||||
$this->putByte($record->x);
|
||||
$this->putByte($record->y);
|
||||
$this->putByte($record->z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/HurtArmorPacket.php
Normal file
38
src/network/protocol/packet/HurtArmorPacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 HurtArmorPacket extends RakNetDataPacket{
|
||||
public $health;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::HURT_ARMOR_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->health);
|
||||
}
|
||||
|
||||
}
|
||||
44
src/network/protocol/packet/InteractPacket.php
Normal file
44
src/network/protocol/packet/InteractPacket.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?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 InteractPacket extends RakNetDataPacket{
|
||||
public $action;
|
||||
public $eid;
|
||||
public $target;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::INTERACT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->action = $this->getByte();
|
||||
$this->eid = $this->getInt();
|
||||
$this->target = $this->getInt();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->action);
|
||||
$this->putInt($this->eid);
|
||||
$this->putInt($this->target);
|
||||
}
|
||||
|
||||
}
|
||||
46
src/network/protocol/packet/LevelEventPacket.php
Normal file
46
src/network/protocol/packet/LevelEventPacket.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?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 LevelEventPacket extends RakNetDataPacket{
|
||||
public $evid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $data;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::LEVEL_EVENT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putShort($this->evid);
|
||||
$this->putShort($this->x);
|
||||
$this->putShort($this->y);
|
||||
$this->putShort($this->z);
|
||||
$this->putInt($this->data);
|
||||
}
|
||||
|
||||
}
|
||||
45
src/network/protocol/packet/LoginPacket.php
Normal file
45
src/network/protocol/packet/LoginPacket.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?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 LoginPacket extends RakNetDataPacket{
|
||||
public $username;
|
||||
public $protocol1;
|
||||
public $protocol2;
|
||||
public $clientId;
|
||||
public $loginData;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::LOGIN_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->username = $this->getString();
|
||||
$this->protocol1 = $this->getInt();
|
||||
$this->protocol2 = $this->getInt();
|
||||
$this->clientId = $this->getInt();
|
||||
$this->loginData = $this->getString();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/LoginStatusPacket.php
Normal file
38
src/network/protocol/packet/LoginStatusPacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 LoginStatusPacket extends RakNetDataPacket{
|
||||
public $status;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::LOGIN_STATUS_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->status);
|
||||
}
|
||||
|
||||
}
|
||||
41
src/network/protocol/packet/MessagePacket.php
Normal file
41
src/network/protocol/packet/MessagePacket.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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 MessagePacket extends RakNetDataPacket{
|
||||
public $source;
|
||||
public $message;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::MESSAGE_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->source = $this->getString();
|
||||
$this->message = $this->getString();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putString($this->source);
|
||||
$this->putString($this->message);
|
||||
}
|
||||
|
||||
}
|
||||
36
src/network/protocol/packet/MoveEntityPacket.php
Normal file
36
src/network/protocol/packet/MoveEntityPacket.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?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 MoveEntityPacket extends RakNetDataPacket{
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::MOVE_ENTITY_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
}
|
||||
48
src/network/protocol/packet/MoveEntityPacket_PosRot.php
Normal file
48
src/network/protocol/packet/MoveEntityPacket_PosRot.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?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 MoveEntityPacket_PosRot extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $yaw;
|
||||
public $pitch;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::MOVE_ENTITY_PACKET_POSROT;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putFloat($this->yaw);
|
||||
$this->putFloat($this->pitch);
|
||||
}
|
||||
|
||||
}
|
||||
56
src/network/protocol/packet/MovePlayerPacket.php
Normal file
56
src/network/protocol/packet/MovePlayerPacket.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?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 MovePlayerPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $yaw;
|
||||
public $pitch;
|
||||
public $bodyYaw;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::MOVE_PLAYER_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->x = $this->getFloat();
|
||||
$this->y = $this->getFloat();
|
||||
$this->z = $this->getFloat();
|
||||
$this->yaw = $this->getFloat();
|
||||
$this->pitch = $this->getFloat();
|
||||
$this->bodyYaw = $this->getFloat();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putFloat($this->yaw);
|
||||
$this->putFloat($this->pitch);
|
||||
$this->putFloat($this->bodyYaw);
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/PingPacket.php
Normal file
38
src/network/protocol/packet/PingPacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 PingPacket extends RakNetDataPacket{
|
||||
public $time = 0;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::PING_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->time = $this->getLong();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putLong($this->time);
|
||||
}
|
||||
|
||||
}
|
||||
47
src/network/protocol/packet/PlayerActionPacket.php
Normal file
47
src/network/protocol/packet/PlayerActionPacket.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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 PlayerActionPacket extends RakNetDataPacket{
|
||||
public $action;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $face;
|
||||
public $eid;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::PLAYER_ACTION_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->action = $this->getInt();
|
||||
$this->x = $this->getInt();
|
||||
$this->y = $this->getInt();
|
||||
$this->z = $this->getInt();
|
||||
$this->face = $this->getInt();
|
||||
$this->eid = $this->getInt();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
src/network/protocol/packet/PlayerArmorEquipmentPacket.php
Normal file
47
src/network/protocol/packet/PlayerArmorEquipmentPacket.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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 PlayerArmorEquipmentPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $slots = array();
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->slots[0] = $this->getByte();
|
||||
$this->slots[1] = $this->getByte();
|
||||
$this->slots[2] = $this->getByte();
|
||||
$this->slots[3] = $this->getByte();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putByte($this->slots[0]);
|
||||
$this->putByte($this->slots[1]);
|
||||
$this->putByte($this->slots[2]);
|
||||
$this->putByte($this->slots[3]);
|
||||
}
|
||||
|
||||
}
|
||||
47
src/network/protocol/packet/PlayerEquipmentPacket.php
Normal file
47
src/network/protocol/packet/PlayerEquipmentPacket.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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 PlayerEquipmentPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $item;
|
||||
public $meta;
|
||||
public $slot;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::PLAYER_EQUIPMENT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->item = $this->getShort();
|
||||
$this->meta = $this->getShort();
|
||||
$this->slot = $this->getByte();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putShort($this->item);
|
||||
$this->putShort($this->meta);
|
||||
$this->putByte($this->slot);
|
||||
}
|
||||
|
||||
}
|
||||
41
src/network/protocol/packet/PongPacket.php
Normal file
41
src/network/protocol/packet/PongPacket.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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 PongPacket extends RakNetDataPacket{
|
||||
public $time = 0;
|
||||
public $ptime = 0;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::PONG_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->ptime = $this->getLong();
|
||||
$this->time = $this->getLong();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putLong($this->ptime);
|
||||
$this->putLong($this->time);
|
||||
}
|
||||
|
||||
}
|
||||
37
src/network/protocol/packet/ReadyPacket.php
Normal file
37
src/network/protocol/packet/ReadyPacket.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?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 ReadyPacket extends RakNetDataPacket{
|
||||
public $status;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::READY_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->status = $this->getByte();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
43
src/network/protocol/packet/RemoveBlockPacket.php
Normal file
43
src/network/protocol/packet/RemoveBlockPacket.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?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 RemoveBlockPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::REMOVE_BLOCK_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->x = $this->getInt();
|
||||
$this->z = $this->getInt();
|
||||
$this->y = $this->getByte();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/RemoveEntityPacket.php
Normal file
38
src/network/protocol/packet/RemoveEntityPacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 RemoveEntityPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::REMOVE_ENTITY_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
}
|
||||
40
src/network/protocol/packet/RemovePlayerPacket.php
Normal file
40
src/network/protocol/packet/RemovePlayerPacket.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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 RemovePlayerPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $clientID;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::REMOVE_PLAYER_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putLong($this->clientID);
|
||||
}
|
||||
|
||||
}
|
||||
39
src/network/protocol/packet/RequestChunkPacket.php
Normal file
39
src/network/protocol/packet/RequestChunkPacket.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?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 RequestChunkPacket extends RakNetDataPacket{
|
||||
public $chunkX;
|
||||
public $chunkZ;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::REQUEST_CHUNK_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->chunkX = $this->getInt();
|
||||
$this->chunkZ = $this->getInt();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
src/network/protocol/packet/RespawnPacket.php
Normal file
47
src/network/protocol/packet/RespawnPacket.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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 RespawnPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::RESPAWN_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->x = $this->getFloat();
|
||||
$this->y = $this->getFloat();
|
||||
$this->z = $this->getFloat();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
}
|
||||
|
||||
}
|
||||
40
src/network/protocol/packet/RotateHeadPacket.php
Normal file
40
src/network/protocol/packet/RotateHeadPacket.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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 RotateHeadPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $yaw;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::ROTATE_HEAD_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putByte($this->yaw);
|
||||
}
|
||||
|
||||
}
|
||||
61
src/network/protocol/packet/SendInventoryPacket.php
Normal file
61
src/network/protocol/packet/SendInventoryPacket.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?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 SendInventoryPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $windowid;
|
||||
public $slots = array();
|
||||
public $armor = array();
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::SEND_INVENTORY_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getInt();
|
||||
$this->windowid = $this->getByte();
|
||||
$count = $this->getShort();
|
||||
for($s = 0; $s < $count and !$this->feof(); ++$s){
|
||||
$this->slots[$s] = $this->getSlot();
|
||||
}
|
||||
if($this->windowid === 1){ //Armir is sent
|
||||
for($s = 0; $s < 4; ++$s){
|
||||
$this->armor[$s] = $this->getSlot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putByte($this->windowid);
|
||||
$this->putShort(count($this->slots));
|
||||
foreach($this->slots as $slot){
|
||||
$this->putSlot($slot);
|
||||
}
|
||||
if($this->windowid === 1 and count($this->armor) === 4){
|
||||
for($s = 0; $s < 4; ++$s){
|
||||
$this->putSlot($this->armor[$s]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
57
src/network/protocol/packet/ServerHandshakePacket.php
Normal file
57
src/network/protocol/packet/ServerHandshakePacket.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?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 ServerHandshakePacket extends RakNetDataPacket{
|
||||
public $port;
|
||||
public $session;
|
||||
public $session2;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::SERVER_HANDSHAKE_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->put("\x04\x3f\x57\xfe"); //cookie
|
||||
$this->put("\xcd"); //Security flags
|
||||
$this->putShort($this->port);
|
||||
$this->putDataArray(array(
|
||||
"\xf5\xff\xff\xf5",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
"\xff\xff\xff\xff",
|
||||
));
|
||||
$this->put("\x00\x00");
|
||||
$this->putLong($this->session);
|
||||
$this->putLong($this->session2);
|
||||
}
|
||||
|
||||
}
|
||||
40
src/network/protocol/packet/SetEntityDataPacket.php
Normal file
40
src/network/protocol/packet/SetEntityDataPacket.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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 SetEntityDataPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $metadata;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::SET_ENTITY_DATA_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
|
||||
}
|
||||
44
src/network/protocol/packet/SetEntityMotionPacket.php
Normal file
44
src/network/protocol/packet/SetEntityMotionPacket.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?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 SetEntityMotionPacket extends RakNetDataPacket{
|
||||
public $eid;
|
||||
public $speedX;
|
||||
public $speedY;
|
||||
public $speedZ;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::SET_ENTITY_MOTION_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
$this->putShort((int) ($this->speedX * 400));
|
||||
$this->putShort((int) ($this->speedY * 400));
|
||||
$this->putShort((int) ($this->speedZ * 400));
|
||||
}
|
||||
|
||||
}
|
||||
38
src/network/protocol/packet/SetHealthPacket.php
Normal file
38
src/network/protocol/packet/SetHealthPacket.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?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 SetHealthPacket extends RakNetDataPacket{
|
||||
public $health;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::SET_HEALTH_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->health = $this->getByte();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->health);
|
||||
}
|
||||
|
||||
}
|
||||
42
src/network/protocol/packet/SetSpawnPositionPacket.php
Normal file
42
src/network/protocol/packet/SetSpawnPositionPacket.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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 SetSpawnPositionPacket extends RakNetDataPacket{
|
||||
public $x;
|
||||
public $z;
|
||||
public $y;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::SET_SPAWN_POSITION_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->x);
|
||||
$this->putInt($this->z);
|
||||
$this->putByte($this->y);
|
||||
}
|
||||
|
||||
}
|
||||
40
src/network/protocol/packet/SetTimePacket.php
Normal file
40
src/network/protocol/packet/SetTimePacket.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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 SetTimePacket extends RakNetDataPacket{
|
||||
public $time;
|
||||
public $started = true;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::SET_TIME_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->time);
|
||||
$this->putByte($this->started == true ? 0x80:0x00);
|
||||
}
|
||||
|
||||
}
|
||||
50
src/network/protocol/packet/StartGamePacket.php
Normal file
50
src/network/protocol/packet/StartGamePacket.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?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 StartGamePacket extends RakNetDataPacket{
|
||||
public $seed;
|
||||
public $generator;
|
||||
public $gamemode;
|
||||
public $eid;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::START_GAME_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->seed);
|
||||
$this->putInt($this->generator);
|
||||
$this->putInt($this->gamemode);
|
||||
$this->putInt($this->eid);
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
}
|
||||
|
||||
}
|
||||
40
src/network/protocol/packet/TakeItemEntity.php
Normal file
40
src/network/protocol/packet/TakeItemEntity.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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 TakeItemEntityPacket extends RakNetDataPacket{
|
||||
public $target;
|
||||
public $eid;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::TAKE_ITEM_ENTITY_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->target);
|
||||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
}
|
||||
46
src/network/protocol/packet/TileEventPacket.php
Normal file
46
src/network/protocol/packet/TileEventPacket.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?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 TileEventPacket extends RakNetDataPacket{
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $case1;
|
||||
public $case2;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::TILE_EVENT_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->x);
|
||||
$this->putInt($this->y);
|
||||
$this->putInt($this->z);
|
||||
$this->putInt($this->case1);
|
||||
$this->putInt($this->case2);
|
||||
}
|
||||
|
||||
}
|
||||
37
src/network/protocol/packet/UnknownPacket.php
Normal file
37
src/network/protocol/packet/UnknownPacket.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?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 UnknownPacket extends RakNetDataPacket{
|
||||
public $packetID = -1;
|
||||
|
||||
public function pid(){
|
||||
return $this->packetID;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
46
src/network/protocol/packet/UpdateBlockPacket.php
Normal file
46
src/network/protocol/packet/UpdateBlockPacket.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?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 UpdateBlockPacket extends RakNetDataPacket{
|
||||
public $x;
|
||||
public $z;
|
||||
public $y;
|
||||
public $block;
|
||||
public $meta;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::UPDATE_BLOCK_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putInt($this->x);
|
||||
$this->putInt($this->z);
|
||||
$this->putByte($this->y);
|
||||
$this->putByte($this->block);
|
||||
$this->putByte($this->meta);
|
||||
}
|
||||
|
||||
}
|
||||
61
src/network/protocol/packet/UseItemPacket.php
Normal file
61
src/network/protocol/packet/UseItemPacket.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?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 UseItemPacket extends RakNetDataPacket{
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $face;
|
||||
public $item;
|
||||
public $meta;
|
||||
public $eid;
|
||||
public $fx;
|
||||
public $fy;
|
||||
public $fz;
|
||||
public $posX;
|
||||
public $posY;
|
||||
public $posZ;
|
||||
|
||||
public function pid(){
|
||||
return ProtocolInfo::USE_ITEM_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->x = $this->getInt();
|
||||
$this->y = $this->getInt();
|
||||
$this->z = $this->getInt();
|
||||
$this->face = $this->getInt();
|
||||
$this->item = $this->getShort();
|
||||
$this->meta = $this->getByte(); //Mojang: fix this
|
||||
$this->eid = $this->getInt();
|
||||
$this->fx = $this->getFloat();
|
||||
$this->fy = $this->getFloat();
|
||||
$this->fz = $this->getFloat();
|
||||
$this->posX = $this->getFloat();
|
||||
$this->posY = $this->getFloat();
|
||||
$this->posZ = $this->getFloat();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
134
src/network/query/QueryHandler.php
Normal file
134
src/network/query/QueryHandler.php
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Implementation of the UT3 Query Protocol (GameSpot)
|
||||
Source: http://wiki.unrealadmin.org/UT3_query_protocol
|
||||
*/
|
||||
|
||||
class QueryHandler{
|
||||
private $socket, $server, $lastToken, $token, $longData, $timeout;
|
||||
|
||||
public function __construct(){
|
||||
console("[INFO] Starting GS4 status listener");
|
||||
$this->server = ServerAPI::request();
|
||||
$addr = ($ip = $this->server->api->getProperty("server-ip")) != "" ? $ip:"0.0.0.0";
|
||||
$port = $this->server->api->getProperty("server-port");
|
||||
console("[INFO] Setting query port to $port");
|
||||
/*
|
||||
The Query protocol is built on top of the existing Minecraft PE UDP network stack.
|
||||
Because the 0xFE packet does not exist in the MCPE protocol,
|
||||
we can identify Query packets and remove them from the packet queue.
|
||||
|
||||
Then, the Query class handles itself sending the packets in raw form, because
|
||||
packets can conflict with the MCPE ones.
|
||||
*/
|
||||
|
||||
$this->server->schedule(20 * 30, array($this, "regenerateToken"), array(), true);
|
||||
$this->regenerateToken();
|
||||
$this->lastToken = $this->token;
|
||||
$this->regenerateInfo();
|
||||
console("[INFO] Query running on $addr:$port");
|
||||
}
|
||||
|
||||
public function regenerateInfo(){
|
||||
$str = "";
|
||||
$plist = "PocketMine-MP ".MAJOR_VERSION;
|
||||
$pl = $this->server->api->plugin->getList();
|
||||
if(count($pl) > 0){
|
||||
$plist .= ":";
|
||||
foreach($pl as $p){
|
||||
$plist .= " ".str_replace(array(";", ":", " "), array("", "", "_"), $p["name"])." ".str_replace(array(";", ":", " "), array("", "", "_"), $p["version"]).";";
|
||||
}
|
||||
$plist = substr($plist, 0, -1);
|
||||
}
|
||||
$KVdata = array(
|
||||
"splitnum" => chr(128),
|
||||
"hostname" => $this->server->name,
|
||||
"gametype" => ($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP",
|
||||
"game_id" => "MINECRAFTPE",
|
||||
"version" => CURRENT_MINECRAFT_VERSION,
|
||||
"server_engine" => "PocketMine-MP ".MAJOR_VERSION,
|
||||
"plugins" => $plist,
|
||||
"map" => $this->server->api->level->getDefault()->getName(),
|
||||
"numplayers" => count($this->server->clients),
|
||||
"maxplayers" => $this->server->maxClients,
|
||||
"whitelist" => $this->server->api->getProperty("white-list") === true ? "on":"off",
|
||||
"hostport" => $this->server->api->getProperty("server-port"),
|
||||
//"hostip" => $this->server->api->getProperty("server-ip", "0.0.0.0")
|
||||
);
|
||||
foreach($KVdata as $key => $value){
|
||||
$str .= $key."\x00".$value."\x00";
|
||||
}
|
||||
$str .= "\x00\x01player_\x00\x00";
|
||||
foreach($this->server->clients as $player){
|
||||
if($player->username != ""){
|
||||
$str .= $player->username."\x00";
|
||||
}
|
||||
}
|
||||
$str .= "\x00";
|
||||
$this->longData = $str;
|
||||
$this->timeout = microtime(true) + 5;
|
||||
}
|
||||
|
||||
public function regenerateToken(){
|
||||
$this->lastToken = $this->token;
|
||||
$this->token = Utils::readInt("\x00".Utils::getRandomBytes(3, false));
|
||||
}
|
||||
|
||||
public function handle(QueryPacket $packet){
|
||||
$packet->decode();
|
||||
switch($packet->packetType){
|
||||
case QueryPacket::HANDSHAKE: //Handshake
|
||||
$pk = new QueryPacket;
|
||||
$pk->ip = $packet->ip;
|
||||
$pk->port = $packet->port;
|
||||
$pk->packetType = QueryPacket::HANDSHAKE;
|
||||
$pk->sessionID = $packet->sessionID;
|
||||
$pk->payload = $this->token."\x00";
|
||||
$pk->encode();
|
||||
$this->server->send($pk);
|
||||
break;
|
||||
case QueryPacket::STATISTICS: //Stat
|
||||
$token = Utils::readInt(substr($packet->payload, 0, 4));
|
||||
if($token !== $this->token and $token !== $this->lastToken){
|
||||
break;
|
||||
}
|
||||
$pk = new QueryPacket;
|
||||
$pk->ip = $packet->ip;
|
||||
$pk->port = $packet->port;
|
||||
$pk->packetType = QueryPacket::STATISTICS;
|
||||
$pk->sessionID = $packet->sessionID;
|
||||
if(strlen($packet->payload) === 8){
|
||||
if($this->timeout < microtime(true)){
|
||||
$this->regenerateInfo();
|
||||
}
|
||||
$pk->payload = $this->longData;
|
||||
}else{
|
||||
$pk->payload = $this->server->name."\x00".(($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP")."\x00".$this->server->api->level->getDefault()->getName()."\x00".count($this->server->clients)."\x00".$this->server->maxClients."\x00".Utils::writeLShort($this->server->api->getProperty("server-port")).$this->server->api->getProperty("server-ip", "0.0.0.0")."\x00";
|
||||
}
|
||||
$pk->encode();
|
||||
$this->server->send($pk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
41
src/network/query/QueryPacket.php
Normal file
41
src/network/query/QueryPacket.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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 QueryPacket extends Packet{
|
||||
const HANDSHAKE = 9;
|
||||
const STATISTICS = 0;
|
||||
|
||||
public $packetType;
|
||||
public $sessionID;
|
||||
public $payload;
|
||||
|
||||
public function decode(){
|
||||
$this->packetType = ord($this->buffer{2});
|
||||
$this->sessionID = Utils::readInt(substr($this->buffer, 3, 4));
|
||||
$this->payload = substr($this->buffer, 7);
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->buffer .= chr($this->packetType);
|
||||
$this->buffer .= Utils::writeInt($this->sessionID);
|
||||
$this->buffer .= $this->payload;
|
||||
}
|
||||
}
|
||||
184
src/network/raknet/RakNetCodec.php
Normal file
184
src/network/raknet/RakNetCodec.php
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
<?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;
|
||||
}
|
||||
$this->buffer .= chr($this->packet->pid());
|
||||
|
||||
switch($this->packet->pid()){
|
||||
case RakNetInfo::OPEN_CONNECTION_REPLY_1:
|
||||
$this->buffer .= RakNetInfo::MAGIC;
|
||||
$this->putLong($this->packet->serverID);
|
||||
$this->putByte(0); //server security
|
||||
$this->putShort($this->packet->mtuSize);
|
||||
break;
|
||||
case RakNetInfo::OPEN_CONNECTION_REPLY_2:
|
||||
$this->buffer .= RakNetInfo::MAGIC;
|
||||
$this->putLong($this->packet->serverID);
|
||||
$this->putShort($this->packet->port);
|
||||
$this->putShort($this->packet->mtuSize);
|
||||
$this->putByte(0); //Server security
|
||||
break;
|
||||
case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION:
|
||||
$this->putByte(RakNetInfo::STRUCTURE);
|
||||
$this->buffer .= RakNetInfo::MAGIC;
|
||||
$this->putLong($this->packet->serverID);
|
||||
break;
|
||||
case RakNetInfo::UNCONNECTED_PONG:
|
||||
case RakNetInfo::ADVERTISE_SYSTEM:
|
||||
$this->putLong($this->packet->pingID);
|
||||
$this->putLong($this->packet->serverID);
|
||||
$this->buffer .= RakNetInfo::MAGIC;
|
||||
$this->putString($this->packet->serverType);
|
||||
break;
|
||||
case RakNetInfo::DATA_PACKET_0:
|
||||
case RakNetInfo::DATA_PACKET_1:
|
||||
case RakNetInfo::DATA_PACKET_2:
|
||||
case RakNetInfo::DATA_PACKET_3:
|
||||
case RakNetInfo::DATA_PACKET_4:
|
||||
case RakNetInfo::DATA_PACKET_5:
|
||||
case RakNetInfo::DATA_PACKET_6:
|
||||
case RakNetInfo::DATA_PACKET_7:
|
||||
case RakNetInfo::DATA_PACKET_8:
|
||||
case RakNetInfo::DATA_PACKET_9:
|
||||
case RakNetInfo::DATA_PACKET_A:
|
||||
case RakNetInfo::DATA_PACKET_B:
|
||||
case RakNetInfo::DATA_PACKET_C:
|
||||
case RakNetInfo::DATA_PACKET_D:
|
||||
case RakNetInfo::DATA_PACKET_E:
|
||||
case RakNetInfo::DATA_PACKET_F:
|
||||
$this->putLTriad($this->packet->seqNumber);
|
||||
foreach($this->packet->data as $pk){
|
||||
$this->encodeDataPacket($pk);
|
||||
}
|
||||
break;
|
||||
case RakNetInfo::NACK:
|
||||
case RakNetInfo::ACK:
|
||||
$payload = b"";
|
||||
$records = 0;
|
||||
$pointer = 0;
|
||||
sort($this->packet->packets, SORT_NUMERIC);
|
||||
$max = count($this->packet->packets);
|
||||
|
||||
while($pointer < $max){
|
||||
$type = true;
|
||||
$curr = $start = $this->packet->packets[$pointer];
|
||||
for($i = $start + 1; $i < $max; ++$i){
|
||||
$n = $this->packet->packets[$i];
|
||||
if(($n - $curr) === 1){
|
||||
$curr = $end = $n;
|
||||
$type = false;
|
||||
$pointer = $i + 1;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
++$pointer;
|
||||
if($type === false){
|
||||
$payload .= "\x00";
|
||||
$payload .= strrev(Utils::writeTriad($start));
|
||||
$payload .= strrev(Utils::writeTriad($end));
|
||||
}else{
|
||||
$payload .= Utils::writeBool(true);
|
||||
$payload .= strrev(Utils::writeTriad($start));
|
||||
}
|
||||
++$records;
|
||||
}
|
||||
$this->putShort($records);
|
||||
$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 put($str){
|
||||
$this->buffer .= $str;
|
||||
}
|
||||
|
||||
protected function putLong($v){
|
||||
$this->buffer .= Utils::writeLong($v);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
171
src/network/raknet/RakNetDataPacket.php
Normal file
171
src/network/raknet/RakNetDataPacket.php
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?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;
|
||||
public $orderIndex;
|
||||
public $orderChannel;
|
||||
public $splitCount;
|
||||
public $splitID;
|
||||
public $splitIndex;
|
||||
|
||||
|
||||
abstract public function pid();
|
||||
|
||||
abstract public function encode();
|
||||
|
||||
abstract public function decode();
|
||||
|
||||
protected function reset(){
|
||||
$this->setBuffer(chr($this->pid()));
|
||||
}
|
||||
|
||||
public function setBuffer($buffer = ""){
|
||||
$this->buffer = $buffer;
|
||||
$this->offset = 0;
|
||||
}
|
||||
|
||||
public function getBuffer(){
|
||||
return $this->buffer;
|
||||
}
|
||||
|
||||
protected 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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
protected function putFloat($v){
|
||||
$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();
|
||||
for($i = 1; $i <= $len and !$this->feof(); ++$i){
|
||||
$data[] = $this->get($this->getTriad());
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function putDataArray(array $data = array()){
|
||||
foreach($data as $v){
|
||||
$this->putTriad(strlen($v));
|
||||
$this->put($v);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getSlot(){
|
||||
$id = $this->getShort();
|
||||
$cnt = $this->getByte();
|
||||
return BlockAPI::getItem(
|
||||
$id,
|
||||
$this->getShort(),
|
||||
$cnt
|
||||
);
|
||||
}
|
||||
|
||||
protected function putSlot(Item $item){
|
||||
$this->putShort($item->getID());
|
||||
$this->putByte($item->count);
|
||||
$this->putShort($item->getMetadata());
|
||||
}
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
||||
94
src/network/raknet/RakNetInfo.php
Normal file
94
src/network/raknet/RakNetInfo.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?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 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;
|
||||
const UNCONNECTED_PING_OPEN_CONNECTIONS = 0x02;
|
||||
|
||||
const OPEN_CONNECTION_REQUEST_1 = 0x05;
|
||||
const OPEN_CONNECTION_REPLY_1 = 0x06;
|
||||
const OPEN_CONNECTION_REQUEST_2 = 0x07;
|
||||
const OPEN_CONNECTION_REPLY_2 = 0x08;
|
||||
|
||||
const INCOMPATIBLE_PROTOCOL_VERSION = 0x1a; //CHECK THIS
|
||||
|
||||
const UNCONNECTED_PONG = 0x1c;
|
||||
const ADVERTISE_SYSTEM = 0x1d;
|
||||
|
||||
const DATA_PACKET_0 = 0x80;
|
||||
const DATA_PACKET_1 = 0x81;
|
||||
const DATA_PACKET_2 = 0x82;
|
||||
const DATA_PACKET_3 = 0x83;
|
||||
const DATA_PACKET_4 = 0x84;
|
||||
const DATA_PACKET_5 = 0x85;
|
||||
const DATA_PACKET_6 = 0x86;
|
||||
const DATA_PACKET_7 = 0x87;
|
||||
const DATA_PACKET_8 = 0x88;
|
||||
const DATA_PACKET_9 = 0x89;
|
||||
const DATA_PACKET_A = 0x8a;
|
||||
const DATA_PACKET_B = 0x8b;
|
||||
const DATA_PACKET_C = 0x8c;
|
||||
const DATA_PACKET_D = 0x8d;
|
||||
const DATA_PACKET_E = 0x8e;
|
||||
const DATA_PACKET_F = 0x8f;
|
||||
|
||||
const NACK = 0xa0;
|
||||
const ACK = 0xc0;
|
||||
|
||||
|
||||
|
||||
public static function isValid($pid){
|
||||
switch((int) $pid){
|
||||
case RakNetInfo::UNCONNECTED_PING:
|
||||
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
|
||||
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
|
||||
case RakNetInfo::OPEN_CONNECTION_REPLY_1:
|
||||
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
|
||||
case RakNetInfo::OPEN_CONNECTION_REPLY_2:
|
||||
case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION:
|
||||
case RakNetInfo::UNCONNECTED_PONG:
|
||||
case RakNetInfo::ADVERTISE_SYSTEM:
|
||||
case RakNetInfo::DATA_PACKET_0:
|
||||
case RakNetInfo::DATA_PACKET_1:
|
||||
case RakNetInfo::DATA_PACKET_2:
|
||||
case RakNetInfo::DATA_PACKET_3:
|
||||
case RakNetInfo::DATA_PACKET_4:
|
||||
case RakNetInfo::DATA_PACKET_5:
|
||||
case RakNetInfo::DATA_PACKET_6:
|
||||
case RakNetInfo::DATA_PACKET_7:
|
||||
case RakNetInfo::DATA_PACKET_8:
|
||||
case RakNetInfo::DATA_PACKET_9:
|
||||
case RakNetInfo::DATA_PACKET_A:
|
||||
case RakNetInfo::DATA_PACKET_B:
|
||||
case RakNetInfo::DATA_PACKET_C:
|
||||
case RakNetInfo::DATA_PACKET_D:
|
||||
case RakNetInfo::DATA_PACKET_E:
|
||||
case RakNetInfo::DATA_PACKET_F:
|
||||
case RakNetInfo::NACK:
|
||||
case RakNetInfo::ACK:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/network/raknet/RakNetPacket.php
Normal file
34
src/network/raknet/RakNetPacket.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?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(){}
|
||||
}
|
||||
208
src/network/raknet/RakNetParser.php
Normal file
208
src/network/raknet/RakNetParser.php
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
<?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{
|
||||
private $buffer;
|
||||
private $offset;
|
||||
public $packet;
|
||||
|
||||
public function __construct(&$buffer){
|
||||
$this->buffer =& $buffer;
|
||||
$this->offset = 0;
|
||||
if(strlen($this->buffer) > 0){
|
||||
$this->parse();
|
||||
}else{
|
||||
$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;
|
||||
$this->packet->length = strlen($this->buffer);
|
||||
switch($this->packet->pid()){
|
||||
case RakNetInfo::UNCONNECTED_PING:
|
||||
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
|
||||
$this->packet->pingID = $this->getLong();
|
||||
$this->offset += 16; //Magic
|
||||
break;
|
||||
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
|
||||
$this->offset += 16; //Magic
|
||||
$this->packet->structure = $this->getByte();
|
||||
$this->packet->mtuSize = strlen($this->get(true));
|
||||
break;
|
||||
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
|
||||
$this->offset += 16; //Magic
|
||||
$this->packet->security = $this->get(5);
|
||||
$this->packet->port = $this->getShort(false);
|
||||
$this->packet->mtuSize = $this->getShort(false);
|
||||
$this->packet->clientID = $this->getLong();
|
||||
break;
|
||||
case RakNetInfo::DATA_PACKET_0:
|
||||
case RakNetInfo::DATA_PACKET_1:
|
||||
case RakNetInfo::DATA_PACKET_2:
|
||||
case RakNetInfo::DATA_PACKET_3:
|
||||
case RakNetInfo::DATA_PACKET_4:
|
||||
case RakNetInfo::DATA_PACKET_5:
|
||||
case RakNetInfo::DATA_PACKET_6:
|
||||
case RakNetInfo::DATA_PACKET_7:
|
||||
case RakNetInfo::DATA_PACKET_8:
|
||||
case RakNetInfo::DATA_PACKET_9:
|
||||
case RakNetInfo::DATA_PACKET_A:
|
||||
case RakNetInfo::DATA_PACKET_B:
|
||||
case RakNetInfo::DATA_PACKET_C:
|
||||
case RakNetInfo::DATA_PACKET_D:
|
||||
case RakNetInfo::DATA_PACKET_E:
|
||||
case RakNetInfo::DATA_PACKET_F:
|
||||
$this->packet->seqNumber = $this->getLTriad();
|
||||
$this->packet->data = array();
|
||||
while(!$this->feof() and ($pk = $this->parseDataPacket()) instanceof RakNetDataPacket){
|
||||
$this->packet->data[] = $pk;
|
||||
}
|
||||
break;
|
||||
case RakNetInfo::NACK:
|
||||
case RakNetInfo::ACK:
|
||||
$count = $this->getShort();
|
||||
$this->packet->packets = array();
|
||||
for($i = 0; $i < $count and !$this->feof(); ++$i){
|
||||
if($this->getByte() === 0){
|
||||
$start = $this->getLTriad();
|
||||
$end = $this->getLTriad();
|
||||
if(($end - $start) > 4096){
|
||||
$end = $start + 4096;
|
||||
}
|
||||
for($c = $start; $c <= $end; ++$c){
|
||||
$this->packet->packets[] = $c;
|
||||
}
|
||||
}else{
|
||||
$this->packet->packets[] = $this->getLTriad();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->packet = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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){
|
||||
$messageIndex = $this->getLTriad();
|
||||
}else{
|
||||
$messageIndex = false;
|
||||
}
|
||||
|
||||
if($reliability === 1
|
||||
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();
|
||||
$splitIndex = $this->getInt();
|
||||
}else{
|
||||
$splitCount = false;
|
||||
$splitID = false;
|
||||
$splitIndex = false;
|
||||
}
|
||||
|
||||
if($length <= 0
|
||||
or $orderChannel >= 32
|
||||
or ($hasSplit === true and $splitIndex >= $splitCount)){
|
||||
return false;
|
||||
}else{
|
||||
$pid = $this->getByte();
|
||||
$buffer = $this->get($length - 1);
|
||||
if(strlen($buffer) < ($length - 1)){
|
||||
return false;
|
||||
}
|
||||
if(isset(ProtocolInfo::$packets[$pid])){
|
||||
$data = new ProtocolInfo::$packets[$pid];
|
||||
}else{
|
||||
$data = new UnknownPacket();
|
||||
$data->packetID = $pid;
|
||||
}
|
||||
$data->reliability = $reliability;
|
||||
$data->hasSplit = $hasSplit;
|
||||
$data->messageIndex = $messageIndex;
|
||||
$data->orderIndex = $orderIndex;
|
||||
$data->orderChannel = $orderChannel;
|
||||
$data->splitCount = $splitCount;
|
||||
$data->splitID = $splitID;
|
||||
$data->splitIndex = $splitIndex;
|
||||
$data->setBuffer($buffer);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue