PHP7 to master

This commit is contained in:
Intyre
2016-02-21 12:47:30 +01:00
153 changed files with 2836 additions and 3536 deletions

View File

@ -29,26 +29,24 @@ class CompressBatchedTask extends AsyncTask{
public $level = 7;
public $data;
public $final;
public $channel = 0;
public $targets = [];
public function __construct($data, array $targets, $level = 7, $channel = 0){
public function __construct($data, array $targets, $level = 7){
$this->data = $data;
$this->targets = $targets;
$this->level = $level;
$this->channel = $channel;
}
public function onRun(){
try{
$this->final = zlib_encode($this->data, ZLIB_ENCODING_DEFLATE, $this->level);
$this->data = null;
}catch(\Exception $e){
}catch(\Throwable $e){
}
}
public function onCompletion(Server $server){
$server->broadcastPacketsCallback($this->final, $this->targets, $this->channel);
$server->broadcastPacketsCallback($this->final, $this->targets);
}
}

View File

@ -85,25 +85,6 @@ class Network{
public static $BATCH_THRESHOLD = 512;
/** @deprecated */
const CHANNEL_NONE = 0;
/** @deprecated */
const CHANNEL_PRIORITY = 1; //Priority channel, only to be used when it matters
/** @deprecated */
const CHANNEL_WORLD_CHUNKS = 2; //Chunk sending
/** @deprecated */
const CHANNEL_MOVEMENT = 3; //Movement sending
/** @deprecated */
const CHANNEL_BLOCKS = 4; //Block updates or explosions
/** @deprecated */
const CHANNEL_WORLD_EVENTS = 5; //Entity, level or tile entity events
/** @deprecated */
const CHANNEL_ENTITY_SPAWNING = 6; //Entity spawn/despawn channel
/** @deprecated */
const CHANNEL_TEXT = 7; //Chat and other text stuff
/** @deprecated */
const CHANNEL_END = 31;
/** @var \SplFixedArray */
private $packetPool;
@ -158,12 +139,10 @@ class Network{
foreach($this->interfaces as $interface){
try {
$interface->process();
}catch(\Exception $e){
}catch(\Throwable $e){
$logger = $this->server->getLogger();
if(\pocketmine\DEBUG > 1){
if($logger instanceof MainLogger){
$logger->logException($e);
}
$logger->logException($e);
}
$interface->emergencyShutdown();
@ -239,12 +218,12 @@ class Network{
$buf = substr($str, $offset, $pkLen);
$offset += $pkLen;
if(($pk = $this->getPacket(ord($buf{0}))) !== null){
if(($pk = $this->getPacket(ord($buf{1}))) !== null){ // #blameshoghi
if($pk::NETWORK_ID === Info::BATCH_PACKET){
throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket");
}
$pk->setBuffer($buf, 1);
$pk->setBuffer($buf, 2); // #blameshoghi
$pk->decode();
$p->handleDataPacket($pk);
@ -254,13 +233,11 @@ class Network{
}
}
}
}catch(\Exception $e){
}catch(\Throwable $e){
if(\pocketmine\DEBUG > 1){
$logger = $this->server->getLogger();
if($logger instanceof MainLogger){
$logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
$logger->logException($e);
}
$logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
$logger->logException($e);
}
}
}

View File

@ -64,10 +64,6 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$this->rakLib = new RakLibServer($this->server->getLogger(), $this->server->getLoader(), $this->server->getPort(), $this->server->getIp() === "" ? "0.0.0.0" : $this->server->getIp());
$this->interface = new ServerHandler($this->rakLib, $this);
for($i = 0; $i < 256; ++$i){
$this->channelCounts[$i] = 0;
}
}
public function setNetwork(Network $network){
@ -83,9 +79,9 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
}
if($this->rakLib->isTerminated()){
$info = $this->rakLib->getTerminationInfo();
$this->network->unregisterInterface($this);
\ExceptionHandler::handler(E_ERROR, "RakLib Thread crashed [".$info["scope"]."]: " . (isset($info["message"]) ? $info["message"] : ""), $info["file"], $info["line"]);
throw new \Exception("RakLib Thread crashed");
}
return $work;
@ -140,13 +136,11 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$this->players[$identifier]->handleDataPacket($pk);
}
}
}catch(\Exception $e){
}catch(\Throwable $e){
if(\pocketmine\DEBUG > 1 and isset($pk)){
$logger = $this->server->getLogger();
if($logger instanceof MainLogger){
$logger->debug("Packet " . get_class($pk) . " 0x" . bin2hex($packet->buffer));
$logger->logException($e);
}
$logger->debug("Packet " . get_class($pk) . " 0x" . bin2hex($packet->buffer));
$logger->logException($e);
}
if(isset($this->players[$identifier])){
@ -205,14 +199,9 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
if(!isset($packet->__encapsulatedPacket)){
$packet->__encapsulatedPacket = new CachedEncapsulatedPacket;
$packet->__encapsulatedPacket->identifierACK = null;
$packet->__encapsulatedPacket->buffer = $packet->buffer;
if($packet->getChannel() !== 0){
$packet->__encapsulatedPacket->reliability = 3;
$packet->__encapsulatedPacket->orderChannel = $packet->getChannel();
$packet->__encapsulatedPacket->orderIndex = 0;
}else{
$packet->__encapsulatedPacket->reliability = 2;
}
$packet->__encapsulatedPacket->buffer = chr(0x8e) . $packet->buffer; // #blameshoghi
$packet->__encapsulatedPacket->reliability = 3;
$packet->__encapsulatedPacket->orderChannel = 0;
}
$pk = $packet->__encapsulatedPacket;
}
@ -220,20 +209,15 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
if(!$immediate and !$needACK and $packet::NETWORK_ID !== ProtocolInfo::BATCH_PACKET
and Network::$BATCH_THRESHOLD >= 0
and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){
$this->server->batchPackets([$player], [$packet], true, $packet->getChannel());
$this->server->batchPackets([$player], [$packet], true);
return null;
}
if($pk === null){
$pk = new EncapsulatedPacket();
$pk->buffer = $packet->buffer;
if($packet->getChannel() !== 0){
$packet->reliability = 3;
$packet->orderChannel = $packet->getChannel();
$packet->orderIndex = 0;
}else{
$packet->reliability = 2;
}
$pk->buffer = chr(0x8e) . $packet->buffer; // #blameshoghi
$packet->reliability = 3;
$packet->orderChannel = 0;
if($needACK === true){
$pk->identifierACK = $this->identifiersACK[$identifier]++;
@ -249,12 +233,12 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
}
private function getPacket($buffer){
$pid = ord($buffer{0});
$pid = ord($buffer{1}); // #blameshoghi
if(($data = $this->network->getPacket($pid)) === null){
return null;
}
$data->setBuffer($buffer, 1);
$data->setBuffer($buffer, 2); // #blameshoghi
return $data;
}

View File

@ -37,7 +37,6 @@ abstract class DataPacket extends BinaryStream{
const NETWORK_ID = 0;
public $isEncoded = false;
private $channel = 0;
public function pid(){
return $this::NETWORK_ID;
@ -52,18 +51,6 @@ abstract class DataPacket extends BinaryStream{
$this->offset = 0;
}
/**
* @deprecated This adds extra overhead on the network, so its usage is now discouraged. It was a test for the viability of this.
*/
public function setChannel($channel){
$this->channel = (int) $channel;
return $this;
}
public function getChannel(){
return $this->channel;
}
public function clean(){
$this->buffer = null;
$this->isEncoded = false;

View File

@ -30,7 +30,7 @@ interface Info{
/**
* Actual Minecraft: PE protocol version
*/
const CURRENT_PROTOCOL = 39;
const CURRENT_PROTOCOL = 45;
const LOGIN_PACKET = 0x8f;
const PLAY_STATUS_PACKET = 0x90;
@ -79,14 +79,20 @@ interface Info{
const CRAFTING_EVENT_PACKET = 0xbb;
const ADVENTURE_SETTINGS_PACKET = 0xbc;
const BLOCK_ENTITY_DATA_PACKET = 0xbd;
//const PLAYER_INPUT_PACKET = 0xbe;
// const PLAYER_INPUT_PACKET = 0xbe;
const FULL_CHUNK_DATA_PACKET = 0xbf;
const SET_DIFFICULTY_PACKET = 0xc0;
//const CHANGE_DIMENSION_PACKET = 0xc1;
// const CHANGE_DIMENSION_PACKET = 0xc1;
const SET_PLAYER_GAMETYPE_PACKET = 0xc2;
const PLAYER_LIST_PACKET = 0xc3;
//const TELEMETRY_EVENT_PACKET = 0xc4;
//const SPAWN_EXPERIENCE_ORB_PACKET = 0xc5
// const TELEMETRY_EVENT_PACKET = 0xc4;
// const SPAWN_EXPERIENCE_ORB_PACKET = 0xc5
// const CLIENTBOUND_MAP_ITEM_DATA_PACKET = 0xc6;
// const MAP_INFO_REQUEST_PACKET = 0xc7;
// const REQUEST_CHUNK_RADIUS_PACKET = 0xc8;
// const CHUNK_RADIUS_UPDATE_PACKET = 0xc9;
// const ITEM_FRAME_DROP_ITEM_PACKET = 0xca;
// const REPLACE_SELECTED_ITEM_PACKET = 0xcb;
}

View File

@ -70,7 +70,7 @@ class RCON{
public function stop(){
for($n = 0; $n < $this->threads; ++$n){
$this->workers[$n]->close();
usleep(50000);
Server::microSleep(50000);
$this->workers[$n]->kill();
}
@socket_close($this->socket);

View File

@ -31,6 +31,11 @@ class RCONInstance extends Thread{
private $socket;
private $password;
private $maxClients;
private $waiting;
public function isWaiting(){
return $this->waiting === true;
}
public function __construct($socket, $password, $maxClients = 50){
@ -85,7 +90,9 @@ class RCONInstance extends Thread{
public function run(){
while($this->stop !== true){
usleep(2000);
$this->synchronized(function(){
$this->wait(2000);
});
$r = [$socket = $this->socket];
$w = null;
$e = null;
@ -135,8 +142,10 @@ class RCONInstance extends Thread{
socket_getpeername($client, $addr, $port);
$this->response = "[INFO] Successful Rcon connection from: /$addr:$port";
$this->synchronized(function (){
$this->waiting = true;
$this->wait();
});
$this->waiting = false;
$this->response = "";
$this->writePacket($client, $requestID, 2, "");
$this->{"status" . $n} = 1;
@ -154,15 +163,17 @@ class RCONInstance extends Thread{
if(strlen($payload) > 0){
$this->cmd = ltrim($payload);
$this->synchronized(function (){
$this->waiting = true;
$this->wait();
});
$this->waiting = false;
$this->writePacket($client, $requestID, 0, str_replace("\n", "\r\n", trim($this->response)));
$this->response = "";
$this->cmd = "";
}
break;
}
usleep(1);
}else{
@socket_set_option($client, SOL_SOCKET, SO_LINGER, ["l_onoff" => 1, "l_linger" => 1]);
@socket_shutdown($client, 2);

View File

@ -42,7 +42,7 @@ abstract class UPnP{
return false;
}
$com->StaticPortMappingCollection->Add($port, "UDP", $port, $myLocalIP, true, "PocketMine-MP");
}catch(\Exception $e){
}catch(\Throwable $e){
return false;
}
@ -63,7 +63,7 @@ abstract class UPnP{
return false;
}
$com->StaticPortMappingCollection->Remove($port, "UDP");
}catch(\Exception $e){
}catch(\Throwable $e){
return false;
}