GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
pocketmine Namespace Reference

Namespaces

 block
 
 command
 
 entity
 
 event
 
 inventory
 
 item
 
 lang
 
 level
 
 math
 
 
 nbt
 
 network
 
 permission
 
 plugin
 
 resourcepacks
 
 scheduler
 
 tile
 
 utils
 
 wizard
 

Data Structures

class  Achievement
 
class  CrashDump
 
interface  IPlayer
 
class  MemoryManager
 
class  OfflinePlayer
 
class  Player
 
class  Server
 
class  Thread
 
class  ThreadManager
 
class  Worker
 

Functions

 detect_system_timezone ()
 
 parse_offset ($offset)
 
if(isset($opts["enable-profiler"])) kill ($pid)
 
 getReferenceCount ($value, $includeCurrent=true)
 
 getTrace ($start=1, $trace=null)
 
 cleanPath ($path)
 

Variables

const VERSION = "1.1dev"
 
const API_VERSION = "3.0.1"
 
const CODENAME = "LlamaSpit"
 
const GENISYS_API_VERSION = '2.0.0'
 
if(\Phar::running(true) !=="") else
 
if(version_compare("7.0", PHP_VERSION) > 0) if(!extension_loaded("pthreads")) if(!class_exists("ClassLoader", false)) $autoloader = new \BaseClassLoader()
 
const START_TIME microtime(true)
 
 $opts = getopt("", ["data:", "plugins:", "no-wizard", "enable-profiler"])
 
const DATA isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR
 
const PLUGIN_PATH isset($opts["plugins"]) ? $opts["plugins"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR
 
const ANSI Terminal::hasFormattingCodes()
 
 $logger = new MainLogger(\pocketmine\DATA . "server.log", \pocketmine\ANSI)
 
 $errors = 0
 
if(php_sapi_name() !=="cli") if(!extension_loaded("sockets")) $pthreads_version = phpversion("pthreads")
 
const ENDIANNESS (!defined('pocketmine\GIT_COMMIT')) (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN)
 
const INT32_MASK is_int(0xffffffff) ? 0xffffffff : -1
 
 $killer = new ServerKiller(8)
 
 $erroredThreads = 0
 

Function Documentation

◆ cleanPath()

pocketmine\cleanPath (   $path)
Parameters
$path
Returns
string
394  {
395  return rtrim(str_replace(["\\", ".php", "phar://", rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), "/"), rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH), "/")], ["/", "", "", "", ""], $path), "/");
396  }
397 
398  $errors = 0;
399 
400  if(php_sapi_name() !== "cli"){
401  $logger->critical("You must run GenisysPro using the CLI.");
402  ++$errors;
403  }
404 
405  if(!extension_loaded("sockets")){
406  $logger->critical("Unable to find the Socket extension.");
407  ++$errors;
408  }
409 
410  $pthreads_version = phpversion("pthreads");
411  if(substr_count($pthreads_version, ".") < 2){
412  $pthreads_version = "0.$pthreads_version";
413  }
414  if(version_compare($pthreads_version, "3.1.5") < 0){
415  $logger->critical("pthreads >= 3.1.5 is required, while you have $pthreads_version.");
416  ++$errors;
417  }
418 
419  if(!extension_loaded("uopz")){
420  //$logger->notice("Couldn't find the uopz extension. Some functions may be limited");
421  }
422 
423  if(extension_loaded("pocketmine")){
424  if(version_compare(phpversion("pocketmine"), "0.0.1") < 0){
425  $logger->critical("You have the native GenisysPro extension, but your version is lower than 0.0.1.");
426  ++$errors;
427  }elseif(version_compare(phpversion("pocketmine"), "0.0.4") > 0){
428  $logger->critical("You have the native GenisysPro extension, but your version is higher than 0.0.4.");
429  ++$errors;
430  }
431  }
432 
433  if(extension_loaded("xdebug")){
434  $logger->warning("You are running GenisysPro with Xdebug enabled. This has a major impact on performance.");
435  }
436 
437  if(!extension_loaded("curl")){
438  $logger->critical("Unable to find the cURL extension.");
439  ++$errors;
440  }
441 
442  if(!extension_loaded("yaml")){
443  $logger->critical("Unable to find the YAML extension.");
444  ++$errors;
445  }
446 
447  if(!extension_loaded("zlib")){
448  $logger->critical("Unable to find the Zlib extension.");
449  ++$errors;
450  }
451 
452  if($errors > 0){
453  $logger->critical("Please update or recompile PHP.");
454  $logger->shutdown();
455  $logger->join();
456  exit(1); //Exit with error
457  }
458 
459  if(file_exists(\pocketmine\PATH . ".git/HEAD")){ //Found Git information!
460  $ref = trim(file_get_contents(\pocketmine\PATH . ".git/HEAD"));
461  if(preg_match('/^[0-9a-f]{40}$/i', $ref)){
462  define('pocketmine\GIT_COMMIT', strtolower($ref));
463  }elseif(substr($ref, 0, 5) === "ref: "){
464  $refFile = \pocketmine\PATH . ".git/" . substr(trim(file_get_contents(\pocketmine\PATH . ".git/HEAD")), 5);
465  if(is_file($refFile)){
466  define('pocketmine\GIT_COMMIT', strtolower(trim(file_get_contents($refFile))));
467  }
468  }
469  }
470  if(!defined('pocketmine\GIT_COMMIT')){
471  define('pocketmine\GIT_COMMIT', "0000000000000000000000000000000000000000");
472  }
473 
474  @define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN));
475  @define("INT32_MASK", is_int(0xffffffff) ? 0xffffffff : -1);
476  @ini_set("opcache.mmap_base", bin2hex(random_bytes(8))); //Fix OPCache address errors
477 
478  if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){
479  $installer = new Installer();
480  if(!$installer->run()){
481  $logger->shutdown();
482  $logger->join();
483  exit(-1);
484  }
485  }
486 
487  if(\Phar::running(true) === ""){
488  $logger->warning("Non-packaged GenisysPro installation detected, do not use on production.");
489  }
490 
491  ThreadManager::init();
492  new Server($autoloader, $logger, \pocketmine\PATH, \pocketmine\DATA, \pocketmine\PLUGIN_PATH);
493 
494  $logger->info("Stopping other threads");
495 
496  $killer = new ServerKiller(8);
497  $killer->start();
498  usleep(10000); //Fixes ServerKiller not being able to start on single-core machines
499 
500  $erroredThreads = 0;
501  foreach(ThreadManager::getInstance()->getAll() as $id => $thread){
502  $logger->debug("Stopping " . $thread->getThreadName() . " thread");
503  try{
504  $thread->quit();
505  $logger->debug($thread->getThreadName() . " thread stopped successfully.");
506  }catch(\ThreadException $e){
507  ++$erroredThreads;
508  $logger->debug("Could not stop " . $thread->getThreadName() . " thread: " . $e->getMessage());
509  }
510  }
511 
512  $logger->shutdown();
513  $logger->join();
514 
515  echo Terminal::$FORMAT_RESET . PHP_EOL;
516 
517  if($erroredThreads > 0){
518  if(\pocketmine\DEBUG > 1){
519  echo "Some threads could not be stopped, performing a force-kill" . PHP_EOL . PHP_EOL;
520  }
521  kill(getmypid());
522  }else{

◆ detect_system_timezone()

pocketmine\detect_system_timezone ( )
Returns
bool|string
188  {
189  switch(Utils::getOS()){
190  case 'win':
191  $regex = '/(UTC)(\+*\-*\d*\d*\:*\d*\d*)/';
192 
193  /*
194  * wmic timezone get Caption
195  * Get the timezone offset
196  *
197  * Sample Output var_dump
198  * array(3) {
199  * [0] =>
200  * string(7) "Caption"
201  * [1] =>
202  * string(20) "(UTC+09:30) Adelaide"
203  * [2] =>
204  * string(0) ""
205  * }
206  */
207  exec("wmic timezone get Caption", $output);
208 
209  $string = trim(implode("\n", $output));
210 
211  //Detect the Time Zone string
212  preg_match($regex, $string, $matches);
213 
214  if(!isset($matches[2])){
215  return false;
216  }
217 
218  $offset = $matches[2];
219 
220  if($offset == ""){
221  return "UTC";
222  }
223 
224  return parse_offset($offset);
225  case 'linux':
226  // Ubuntu / Debian.
227  if(file_exists('/etc/timezone')){
228  $data = file_get_contents('/etc/timezone');
229  if($data){
230  return trim($data);
231  }
232  }
233 
234  // RHEL / CentOS
235  if(file_exists('/etc/sysconfig/clock')){
236  $data = parse_ini_file('/etc/sysconfig/clock');
237  if(!empty($data['ZONE'])){
238  return trim($data['ZONE']);
239  }
240  }
241 
242  //Portable method for incompatible linux distributions.
243 
244  $offset = trim(exec('date +%:z'));
245 
246  if($offset == "+00:00"){
247  return "UTC";
248  }
249 
250  return parse_offset($offset);
251  case 'mac':
252  if(is_link('/etc/localtime')){
253  $filename = readlink('/etc/localtime');
254  if(strpos($filename, '/usr/share/zoneinfo/') === 0){
255  $timezone = substr($filename, 20);
256  return trim($timezone);
257  }
258  }
259 
260  return false;
261  default:
262  return false;
263  }
264  }

◆ getReferenceCount()

pocketmine\getReferenceCount (   $value,
  $includeCurrent = true 
)
Parameters
object$value
bool$includeCurrent
Returns
int
341  {
342  ob_start();
343  debug_zval_dump($value);
344  $ret = explode("\n", ob_get_contents());
345  ob_end_clean();
346 
347  if(count($ret) >= 1 and preg_match('/^.* refcount\\(([0-9]+)\\)\\{$/', trim($ret[0]), $m) > 0){
348  return ((int) $m[1]) - ($includeCurrent ? 3 : 4); //$value + zval call + extra call
349  }
350  return -1;
351  }

◆ getTrace()

pocketmine\getTrace (   $start = 1,
  $trace = null 
)
Parameters
int$start
null$trace
Returns
array
359  {
360  if($trace === null){
361  if(function_exists("xdebug_get_function_stack")){
362  $trace = array_reverse(xdebug_get_function_stack());
363  }else{
364  $e = new \Exception();
365  $trace = $e->getTrace();
366  }
367  }
368 
369  $messages = [];
370  $j = 0;
371  for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
372  $params = "";
373  if(isset($trace[$i]["args"]) or isset($trace[$i]["params"])){
374  if(isset($trace[$i]["args"])){
375  $args = $trace[$i]["args"];
376  }else{
377  $args = $trace[$i]["params"];
378  }
379  foreach($args as $name => $value){
380  $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value)))) . ", ";
381  }
382  }
383  $messages[] = "#$j " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable(substr($params, 0, -2)) . ")";
384  }
385 
386  return $messages;
387  }

◆ kill()

if (isset( $opts["enable-profiler"])) pocketmine\kill (   $pid)
Parameters
$pid
319  {
320  switch(Utils::getOS()){
321  case "win":
322  exec("taskkill.exe /F /PID " . ((int) $pid) . " > NUL");
323  break;
324  case "mac":
325  case "linux":
326  default:
327  if(function_exists("posix_kill")){
328  posix_kill($pid, SIGKILL);
329  }else{
330  exec("kill -9 " . ((int) $pid) . " > /dev/null 2>&1");
331  }
332  }
333  }

◆ parse_offset()

pocketmine\parse_offset (   $offset)
Parameters
string$offsetIn the format of +09:00, +02:00, -04:00 etc.
Returns
string
271  {
272  //Make signed offsets unsigned for date_parse
273  if(strpos($offset, '-') !== false){
274  $negative_offset = true;
275  $offset = str_replace('-', '', $offset);
276  }else{
277  if(strpos($offset, '+') !== false){
278  $negative_offset = false;
279  $offset = str_replace('+', '', $offset);
280  }else{
281  return false;
282  }
283  }
284 
285  $parsed = date_parse($offset);
286  $offset = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];
287 
288  //After date_parse is done, put the sign back
289  if($negative_offset == true){
290  $offset = -abs($offset);
291  }
292 
293  //And then, look the offset up.
294  //timezone_name_from_abbr is not used because it returns false on some(most) offsets because it's mapping function is weird.
295  //That's been a bug in PHP since 2008!
296  foreach(timezone_abbreviations_list() as $zones){
297  foreach($zones as $timezone){
298  if($timezone['offset'] == $offset){
299  return $timezone['timezone_id'];
300  }
301  }
302  }
303 
304  return false;
305  }
306 
307  if(isset($opts["enable-profiler"])){
308  if(function_exists("profiler_enable")){
309  \profiler_enable();
310  $logger->notice("Execution is being profiled");
311  }else{
312  $logger->notice("No profiler found. Please install https://github.com/krakjoe/profiler");
313  }
314  }

Variable Documentation

◆ $autoloader

if (version_compare("7.0", PHP_VERSION) > 0) if (!extension_loaded("pthreads")) if (!class_exists("ClassLoader", false)) $autoloader = new \BaseClassLoader()

◆ $erroredThreads

$erroredThreads = 0

◆ $errors

$errors = 0

◆ $killer

$killer = new ServerKiller(8)

◆ $logger

$logger = new MainLogger(\pocketmine\DATA . "server.log", \pocketmine\ANSI)

◆ $opts

$opts = getopt("", ["data:", "plugins:", "no-wizard", "enable-profiler"])

◆ $pthreads_version

if (php_sapi_name() !=="cli") if (!extension_loaded("sockets")) $pthreads_version = phpversion("pthreads")

◆ ANSI

◆ API_VERSION

const API_VERSION = "3.0.1"

◆ CODENAME

const CODENAME = "LlamaSpit"

◆ DATA

const DATA isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR

◆ else

if ( $erroredThreads > 0) else
Initial value:
{
@define('pocketmine\PATH', \getcwd() . DIRECTORY_SEPARATOR)

◆ ENDIANNESS

const ENDIANNESS(!defined( 'pocketmine\GIT_COMMIT')) (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN)

◆ GENISYS_API_VERSION

const GENISYS_API_VERSION = '2.0.0'

◆ INT32_MASK

const INT32_MASK is_int(0xffffffff) ? 0xffffffff : -1

◆ PLUGIN_PATH

const PLUGIN_PATH isset($opts["plugins"]) ? $opts["plugins"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR

◆ START_TIME

const START_TIME microtime(true)

◆ VERSION

const VERSION = "1.1dev"