Merge branch 'php/7.0' into mcpe-1.2

This commit is contained in:
Dylan K. Taylor 2017-09-07 10:42:20 +01:00
commit fcb3c4820e
15 changed files with 258 additions and 44 deletions

View File

@ -123,6 +123,13 @@ namespace pocketmine {
define('pocketmine\PATH', realpath(getcwd()) . DIRECTORY_SEPARATOR);
}
$requiredSplVer = "0.0.1";
if(!is_file(\pocketmine\PATH . "src/spl/version.php") or version_compare($requiredSplVer, require(\pocketmine\PATH . "src/spl/version.php")) > 0){
echo "[CRITICAL] Incompatible PocketMine-SPL submodule version ($requiredSplVer is required)." . PHP_EOL;
echo "[CRITICAL] Please update your submodules or use provided builds." . PHP_EOL;
exit(1);
}
if(!class_exists("ClassLoader", false)){
if(!is_file(\pocketmine\PATH . "src/spl/ClassLoader.php")){
echo "[CRITICAL] Unable to find the PocketMine-SPL library." . PHP_EOL;
@ -179,40 +186,51 @@ namespace pocketmine {
$logger = new MainLogger(\pocketmine\DATA . "server.log");
$logger->registerStatic();
if(!ini_get("date.timezone")){
do{
$timezone = ini_get("date.timezone");
if($timezone !== ""){
/*
* This is here so that people don't come to us complaining and fill up the issue tracker when they put
* an incorrect timezone abbreviation in php.ini apparently.
*/
if(strpos($timezone, "/") === false){
$default_timezone = timezone_name_from_abbr($timezone);
if($default_timezone !== false){
ini_set("date.timezone", $default_timezone);
date_default_timezone_set($default_timezone);
break;
}else{
//Bad php.ini value, try another method to detect timezone
$logger->warning("Timezone \"$timezone\" could not be parsed as a valid timezone from php.ini, falling back to auto-detection");
}
}else{
date_default_timezone_set($timezone);
break;
}
}
if(($timezone = detect_system_timezone()) and date_default_timezone_set($timezone)){
//Success! Timezone has already been set and validated in the if statement.
//This here is just for redundancy just in case some program wants to read timezone data from the ini.
ini_set("date.timezone", $timezone);
}else{
//If system timezone detection fails or timezone is an invalid value.
if($response = Utils::getURL("http://ip-api.com/json")
and $ip_geolocation_data = json_decode($response, true)
and $ip_geolocation_data['status'] !== 'fail'
and date_default_timezone_set($ip_geolocation_data['timezone'])
){
//Again, for redundancy.
ini_set("date.timezone", $ip_geolocation_data['timezone']);
}else{
ini_set("date.timezone", "UTC");
date_default_timezone_set("UTC");
$logger->warning("Timezone could not be automatically determined. An incorrect timezone will result in incorrect timestamps on console logs. It has been set to \"UTC\" by default. You can change it on the php.ini file.");
}
break;
}
}else{
/*
* This is here so that people don't come to us complaining and fill up the issue tracker when they put
* an incorrect timezone abbreviation in php.ini apparently.
*/
$timezone = ini_get("date.timezone");
if(strpos($timezone, "/") === false){
$default_timezone = timezone_name_from_abbr($timezone);
ini_set("date.timezone", $default_timezone);
date_default_timezone_set($default_timezone);
}else{
date_default_timezone_set($timezone);
if($response = Utils::getURL("http://ip-api.com/json") //If system timezone detection fails or timezone is an invalid value.
and $ip_geolocation_data = json_decode($response, true)
and $ip_geolocation_data['status'] !== 'fail'
and date_default_timezone_set($ip_geolocation_data['timezone'])
){
//Again, for redundancy.
ini_set("date.timezone", $ip_geolocation_data['timezone']);
break;
}
}
ini_set("date.timezone", "UTC");
date_default_timezone_set("UTC");
$logger->warning("Timezone could not be automatically determined or was set to an invalid value. An incorrect timezone will result in incorrect timestamps on console logs. It has been set to \"UTC\" by default. You can change it on the php.ini file.");
}while(false);
function detect_system_timezone(){
switch(Utils::getOS()){
@ -459,6 +477,7 @@ namespace pocketmine {
}
$extensions = [
"bcmath" => "BC Math",
"curl" => "cURL",
"json" => "JSON",
"mbstring" => "Multibyte String",

View File

@ -1612,7 +1612,6 @@ class Server{
register_shutdown_function([$this, "crashDump"]);
$this->queryRegenerateTask = new QueryRegenerateEvent($this, 5);
$this->network->registerInterface(new RakLibInterface($this));
$this->pluginManager->loadPlugins($this->pluginPath);
@ -1620,6 +1619,9 @@ class Server{
$this->enablePlugins(PluginLoadOrder::STARTUP);
$this->network->registerInterface(new RakLibInterface($this));
LevelProviderManager::addProvider(Anvil::class);
LevelProviderManager::addProvider(McRegion::class);
LevelProviderManager::addProvider(PMAnvil::class);
@ -1638,6 +1640,12 @@ class Server{
foreach((array) $this->getProperty("worlds", []) as $name => $worldSetting){
if($this->loadLevel($name) === false){
$seed = $this->getProperty("worlds.$name.seed", time());
if(is_string($seed) and !is_numeric($seed)){
$seed = Utils::javaStringHash($seed);
}elseif(!is_int($seed)){
$seed = (int) $seed;
}
$options = explode(":", $this->getProperty("worlds.$name.generator", Generator::getGenerator("default")));
$generator = Generator::getGenerator(array_shift($options));
if(count($options) > 0){

View 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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\event\server;
use pocketmine\network\SourceInterface;
/**
* Called when a network interface crashes, with relevant crash information.
*/
class NetworkInterfaceCrashEvent extends NetworkInterfaceEvent{
public static $handlerList = null;
/**
* @var \Throwable
*/
private $exception;
public function __construct(SourceInterface $interface, \Throwable $throwable){
parent::__construct($interface);
$this->exception = $throwable;
}
/**
* @return \Throwable
*/
public function getCrashInformation() : \Throwable{
return $this->exception;
}
}

View 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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\event\server;
use pocketmine\network\SourceInterface;
class NetworkInterfaceEvent extends ServerEvent{
/** @var SourceInterface */
protected $interface;
/**
* @param SourceInterface $interface
*/
public function __construct(SourceInterface $interface){
$this->interface = $interface;
}
/**
* @return SourceInterface
*/
public function getInterface() : SourceInterface{
return $this->interface;
}
}

View 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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\event\server;
use pocketmine\event\Cancellable;
use pocketmine\network\SourceInterface;
/**
* Called when a network interface is registered into the network, for example the RakLib interface.
*/
class NetworkInterfaceRegisterEvent extends NetworkInterfaceEvent implements Cancellable{
public static $handlerList = null;
}

View File

@ -0,0 +1,32 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\event\server;
/**
* Called when a network interface is unregistered
*/
class NetworkInterfaceUnregisterEvent extends NetworkInterfaceEvent{
public static $handlerList = null;
}

View File

@ -26,6 +26,9 @@ declare(strict_types=1);
*/
namespace pocketmine\network;
use pocketmine\event\server\NetworkInterfaceCrashEvent;
use pocketmine\event\server\NetworkInterfaceRegisterEvent;
use pocketmine\event\server\NetworkInterfaceUnregisterEvent;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\Server;
@ -90,6 +93,8 @@ class Network{
$logger->logException($e);
}
$this->server->getPluginManager()->callEvent(new NetworkInterfaceCrashEvent($interface, $e));
$interface->emergencyShutdown();
$this->unregisterInterface($interface);
$logger->critical($this->server->getLanguage()->translateString("pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
@ -101,20 +106,24 @@ class Network{
* @param SourceInterface $interface
*/
public function registerInterface(SourceInterface $interface){
$this->interfaces[$hash = spl_object_hash($interface)] = $interface;
if($interface instanceof AdvancedSourceInterface){
$this->advancedInterfaces[$hash] = $interface;
$interface->setNetwork($this);
$this->server->getPluginManager()->callEvent($ev = new NetworkInterfaceRegisterEvent($interface));
if(!$ev->isCancelled()){
$interface->start();
$this->interfaces[$hash = spl_object_hash($interface)] = $interface;
if($interface instanceof AdvancedSourceInterface){
$this->advancedInterfaces[$hash] = $interface;
$interface->setNetwork($this);
}
$interface->setName($this->name);
}
$interface->setName($this->name);
}
/**
* @param SourceInterface $interface
*/
public function unregisterInterface(SourceInterface $interface){
unset($this->interfaces[$hash = spl_object_hash($interface)],
$this->advancedInterfaces[$hash]);
$this->server->getPluginManager()->callEvent(new NetworkInterfaceUnregisterEvent($interface));
unset($this->interfaces[$hash = spl_object_hash($interface)], $this->advancedInterfaces[$hash]);
}
/**

View File

@ -34,6 +34,11 @@ use pocketmine\Player;
*/
interface SourceInterface{
/**
* Performs actions needed to start the interface after it is registered.
*/
public function start();
/**
* Sends a DataPacket to the interface, returns an unique identifier for the packet if $needACK is true
*

View File

@ -67,10 +67,14 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$this->server = $server;
$this->identifiers = [];
$this->rakLib = new RakLibServer($this->server->getLogger(), $this->server->getLoader(), $this->server->getPort(), $this->server->getIp() === "" ? "0.0.0.0" : $this->server->getIp());
$this->rakLib = new RakLibServer($this->server->getLogger(), $this->server->getLoader(), $this->server->getPort(), $this->server->getIp() === "" ? "0.0.0.0" : $this->server->getIp(), false);
$this->interface = new ServerHandler($this->rakLib, $this);
}
public function start(){
$this->rakLib->start();
}
public function setNetwork(Network $network){
$this->network = $network;
}

View File

@ -306,7 +306,8 @@ class PluginManager{
$name,
$this->server->getLanguage()->translateString("%pocketmine.plugin.unknownDependency", [$dependency])
]));
break;
unset($plugins[$name]);
continue 2;
}
}

View File

@ -47,6 +47,7 @@ class MainLogger extends \AttachableThreadedLogger{
* @throws \RuntimeException
*/
public function __construct(string $logFile, bool $logDebug = false){
parent::__construct();
if(static::$logger instanceof MainLogger){
throw new \RuntimeException("MainLogger has been already created");
}
@ -214,8 +215,10 @@ class MainLogger extends \AttachableThreadedLogger{
echo $message . PHP_EOL;
}
if($this->attachment instanceof \ThreadedLoggerAttachment){
$this->attachment->call($level, $message);
foreach($this->attachments as $attachment){
if($attachment instanceof \ThreadedLoggerAttachment){
$attachment->call($level, $message);
}
}
$this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . PHP_EOL;

@ -1 +1 @@
Subproject commit 226772184b6cb3c014477feb41e55ec22850f2dd
Subproject commit 97d2faf6928014ff953922d030f67b1e8b046dd7

@ -1 +1 @@
Subproject commit a5127b224ec35ef6f54d0eae2a69a02d53842640
Subproject commit c4d4841586a19d95f25cc02b23baa00dbbc0b0d7

View File

@ -1,8 +1,11 @@
param (
[string]$php = "",
[switch]$Loop = $false
)
if(Test-Path "bin\php\php.exe"){
if($php -ne ""){
$binary = $php
}elseif(Test-Path "bin\php\php.exe"){
$env:PHPRC = ""
$binary = "bin\php\php.exe"
}else{

@ -1 +1 @@
Subproject commit 893b61f722f2b14b8a4ca5063eff5d89039b0b62
Subproject commit 868a61e579f0d6e69f354a0fb5914dba7e92d084