Some changes.

This commit is contained in:
kotyaralih 2021-12-04 12:45:34 -08:00
parent 20c16068ec
commit d6cc8415dc
30 changed files with 359 additions and 106 deletions

View file

@ -145,6 +145,10 @@ class BanAPI{
break;
case "op":
$user = strtolower($params[0]);
if($user == NULL){
$output .= "Usage: /op <player>\n";
break;
}
$player = $this->server->api->player->get($user);
if(!($player instanceof Player)){
$this->ops->set($user);

View file

@ -422,7 +422,7 @@ class BlockAPI{
if($target->isReplaceable === true){
$block = $target;
$hand->position($block);
$face = -1;
//$face = -1;
}
if($hand->isSolid === true and $player->entity->inBlock($block)){

View file

@ -128,7 +128,7 @@ class ConsoleAPI{
$max = ceil(count($cmds) / 5);
$page = (int) (isset($params[0]) ? min($max, max(1, intval($params[0]))):1);
$output .= "\x1b[31;1m-\x1b[0m Showing help page $page of $max (/help <page>) \x1b[31;1m-\x1b[0m\n";
$output .= FORMAT_RED."-".FORMAT_RESET." Showing help page $page of $max (/help <page>) ".FORMAT_RED."-".FORMAT_RESET."\n";
$current = 1;
foreach($cmds as $c => $h){
$curpage = (int) ceil($current / 5);

View file

@ -110,7 +110,7 @@ class EntityAPI{
public function spawnToAll(Entity $e){
foreach($this->server->api->player->getAll($e->level) as $player){
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER){
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
$e->spawn($player);
}
}
@ -124,6 +124,7 @@ class EntityAPI{
"x" => $pos->x + mt_rand(-10, 10) / 50,
"y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(-10, 10) / 50,
"level" => $pos->level,
//"speedX" => mt_rand(-3, 3) / 8,
"speedY" => mt_rand(5, 8) / 2,
//"speedZ" => mt_rand(-3, 3) / 8,

View file

@ -32,7 +32,7 @@ class PlayerAPI{
$this->server->api->console->register("kill", "<player>", array($this, "commandHandler"));
$this->server->api->console->register("gamemode", "<mode> [player]", array($this, "commandHandler"));
$this->server->api->console->register("tp", "[target player] <destination player|w:world> OR /tp [target player] <x> <y> <z>", array($this, "commandHandler"));
$this->server->api->console->register("spawnpoint", "[player] [x] [y] [z]", array($this, "commandHandler"));
$this->server->api->console->register("setspawn", "[player] [x] [y] [z]", array($this, "commandHandler"));
$this->server->api->console->register("spawn", "", array($this, "commandHandler"));
$this->server->api->console->register("ping", "", array($this, "commandHandler"));
$this->server->api->console->alias("lag", "ping");
@ -118,7 +118,7 @@ class PlayerAPI{
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "spawnpoint":
case "setspawn":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.\n";
break;
@ -306,17 +306,34 @@ class PlayerAPI{
return false;
}
public function get($name, $alike = true){
public function get($name, $alike = true, $multiple = false){
$name = trim(strtolower($name));
if($name === ""){
return false;
}
$CID = $this->server->query("SELECT ip,port FROM players WHERE name ".($alike === true ? "LIKE '%".$name."%'":"= '".$name."'").";", true);
$CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]);
if(isset($this->server->clients[$CID])){
return $this->server->clients[$CID];
}
return false;
$query = $this->server->query("SELECT ip,port,name FROM players WHERE name ".($alike === true ? "LIKE '%".$name."%'":"= '".$name."'").";");
$players = array();
if($query !== false and $query !== true){
while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){
$CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]);
if(isset($this->server->clients[$CID])){
$players[$CID] = $this->server->clients[$CID];
if($multiple === false and $d["name"] === $name){
return $players[$CID];
}
}
}
}
if($multiple === false){
if(count($players) > 0){
return array_shift($players);
}else{
return false;
}
}else{
return $players;
}
}
public function getAll($level = null){
@ -429,7 +446,7 @@ class PlayerAPI{
$this->server->query("DELETE FROM players WHERE name = '".$player->username."';");
if($player->entity instanceof Entity){
unset($player->entity->player);
unset($player->entity);
//unset($player->entity);
}
$this->server->api->entity->remove($player->eid);
$player = null;
@ -454,6 +471,7 @@ class PlayerAPI{
"z" => $this->server->spawn->z,
),
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)),
"hotbar" => array(0, -1, -1, -1, -1, -1, -1, -1, -1),
"armor" => array_fill(0, 4, array(AIR, 0)),
"gamemode" => $this->server->gamemode,
"health" => 20,

View file

@ -28,6 +28,13 @@ class PluginAPI extends stdClass{
$this->randomNonce = Utils::getRandomBytes(16, false);
}
public function __destruct(){
foreach($this->plugins as $p){
$p[0]->__destruct();
}
unset($plugins);
}
public function getList(){
$list = array();
foreach($this->plugins as $p){

View file

@ -135,6 +135,7 @@ class ServerAPI{
$this->parseProperties();
define("DEBUG", $this->getProperty("debug", 1));
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
if($this->getProperty("port") !== false){
$this->setProperty("server-port", $this->getProperty("port"));
$this->config->remove("port");
@ -146,6 +147,10 @@ class ServerAPI{
console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.")", true, true, 0);
console("[INFO] PocketMine-MP is distibuted under the LGPL License", true, true, 0);
if(ADVANCED_CACHE == true){
console("[INFO] Advanced cache enabled");
}
if($this->getProperty("upnp-forwarding") === true){
console("[INFO] [UPnP] Trying to port forward...");
UPnP_PortForward($this->getProperty("server-port"));
@ -290,7 +295,6 @@ class ServerAPI{
$this->server->gamemode = $this->getProperty("gamemode");
$this->server->difficulty = $this->getProperty("difficulty");
$this->server->whitelist = $this->getProperty("white-list");
$this->server->reloadConfig();
}
}

View file

@ -52,6 +52,7 @@ class Player{
public $spawned = false;
public $inventory;
public $slot;
public $hotbar;
public $armor = array();
public $loggedIn = false;
public $gamemode;
@ -111,6 +112,7 @@ class Player{
$this->gamemode = $this->server->gamemode;
$this->level = $this->server->api->level->getDefault();
$this->slot = 0;
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
$this->packetStats = array(0,0);
$this->server->schedule(2, array($this, "handlePacketQueues"), array(), true);
$this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true);
@ -217,6 +219,9 @@ class Player{
"z" => $Z,
"data" => $this->level->getOrderedChunk($X, $Z, $Yndex),
));
if($cnt === false){
return false;
}
$this->chunkCount = array();
foreach($cnt as $i => $count){
$this->chunkCount[$count] = true;
@ -251,6 +256,7 @@ class Player{
}
}
$this->data->set("inventory", $inv);
$this->data->set("hotbar", $this->hotbar);
$armor = array();
foreach($this->armor as $slot => $item){
@ -887,7 +893,7 @@ class Player{
return false;
}
if($pos instanceof Position and $pos->level !== $this->level){
if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){
if($this->server->api->dhandle("player.teleport.level", array("player" => $this, "origin" => $this->level, "target" => $pos->level)) === false){
$this->entity->check = true;
return false;
@ -1279,6 +1285,8 @@ class Player{
$this->username = $data["username"];
$this->iusername = strtolower($this->username);
}else{
$this->username = $data["username"];
$this->iusername = strtolower($this->username);
$this->close("Bad username", false);
break;
}
@ -1362,8 +1370,13 @@ class Player{
));
if(($this->gamemode & 0x01) === 0x01){
$this->slot = 0;
$this->hotbar = array();
}elseif($this->data->exists("hotbar")){
$this->hotbar = $this->data->get("hotbar");
$this->slot = $this->hotbar[0];
}else{
$this->slot = -1;//0
$this->hotbar = array(-1, -1, -1, -1, -1, -1, -1, -1, -1);
}
$this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, array("player" => $this));
$this->eid = $this->entity->eid;
@ -1405,7 +1418,7 @@ class Player{
if($this->spawned !== false){
break;
}
$this->entity->setHealth($this->data->get("health"));
$this->entity->setHealth($this->data->get("health"), "spawn", true);
$this->spawned = true;
$this->server->api->player->spawnAllPlayers($this);
$this->server->api->player->spawnToAllPlayers($this);
@ -1523,8 +1536,15 @@ class Player{
$data["meta"] = $data["item"]->getMetadata();
if($this->server->handle("player.equipment.change", $data) !== false){
$this->slot = $data["slot"];
if(($this->gamemode & 0x01) === SURVIVAL){
if(!in_array($this->slot, $this->hotbar)){
array_pop($this->hotbar);
array_unshift($this->hotbar, $this->slot);
}
}
}else{
$this->sendInventorySlot($data["slot"]);
//$this->sendInventorySlot($data["slot"]);
$this->sendInventory();
}
if($this->entity->inAction === true){
$this->entity->inAction = false;
@ -1822,7 +1842,7 @@ class Player{
if($this->spawned === false){
break;
}
if($this->entity->dead === false){
if(@$this->entity->dead === false){
break;
}
$this->craftingItems = array();
@ -1831,7 +1851,7 @@ class Player{
if($this->entity instanceof Entity){
$this->entity->fire = 0;
$this->entity->air = 300;
$this->entity->setHealth(20, "respawn");
$this->entity->setHealth(20, "respawn", true);
$this->entity->updateMetadata();
} else {
break;
@ -1856,7 +1876,7 @@ class Player{
switch($data["event"]){
case 9: //Eating
$items = array(
APPLE => 2,
APPLE => 4,
MUSHROOM_STEW => 10,
BEETROOT_SOUP => 10,
BREAD => 5,
@ -2194,10 +2214,15 @@ class Player{
if(($this->gamemode & 0x01) === CREATIVE){
return;
}
$hotbar = array();
foreach($this->hotbar as $slot){
$hotbar[] = $slot <= -1 ? -1 : $slot + 9;
}
$this->dataPacket(MC_CONTAINER_SET_CONTENT, array(
"windowid" => 0,
"count" => count($this->inventory),
"slots" => $this->inventory,
"hotbar" => $hotbar,
));
}

View file

@ -36,7 +36,7 @@ class PocketMinecraftServer{
}*/
console("[INFO] Starting Minecraft PE server on ".($this->serverip === "0.0.0.0" ? "*":$this->serverip).":".$this->port);
define("BOOTUP_RANDOM", Utils::getRandomBytes(16));
$this->serverID = $this->serverID === false ? Utils::readLong(Utils::getRandomBytes(8, false)):$this->serverID;
$this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)):$this->serverID;
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed;
$this->startDatabase();
$this->api = false;
@ -65,7 +65,6 @@ class PocketMinecraftServer{
$this->tickMeasure = array_fill(0, 40, 0);
$this->setType("normal");
$this->interface = new MinecraftInterface($this, "255.255.255.255", $this->port, true, false, $this->serverip);
$this->reloadConfig();
$this->stop = false;
$this->ticks = 0;
if(!defined("NO_THREADS")){
@ -108,6 +107,7 @@ class PocketMinecraftServer{
}
$this->schedule(20 * 15, array($this, "checkTicks"), array(), true);
$this->schedule(20 * 60, array($this, "checkMemory"), array(), true);
$this->schedule(20 * 45, "Cache::cleanup", array(), true);
$this->schedule(20, array($this, "asyncOperationChecker"), array(), true);
}
@ -156,10 +156,6 @@ class PocketMinecraftServer{
return $result;
}
public function reloadConfig(){
}
public function debugInfo($console = false){
$info = array();
$info["tps"] = $this->getTPS();
@ -372,46 +368,7 @@ class PocketMinecraftServer{
public function init(){
register_tick_function(array($this, "tick"));
console("[DEBUG] Starting internal ticker calculation", true, true, 2);
$t = 0;
while(true){
switch($t){
case 0:
declare(ticks=100);
break;
case 1:
declare(ticks=60);
break;
case 2:
declare(ticks=40);
break;
case 3:
declare(ticks=30);
break;
case 4:
declare(ticks=20);
break;
case 5:
declare(ticks=15);
break;
default:
declare(ticks=10);
break;
}
if($t > 5){
break;
}
$this->ticks = 0;
while($this->ticks < 20){
usleep(1);
}
if($this->getTPS() < 19.5){
++$t;
}else{
break;
}
}
declare(ticks=5000); //Minimum TPS for main thread locks
$this->loadEvents();
register_shutdown_function(array($this, "dumpError"));
@ -431,10 +388,32 @@ class PocketMinecraftServer{
if($this->stop === true){
return;
}
console("[ERROR] An Unrecovereable has ocurred and the server has Crashed. Creating an Error Dump");
console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump");
$dump = "```\r\n# PocketMine-MP Error Dump ".date("D M j H:i:s T Y")."\r\n";
$er = error_get_last();
$errorConversion = array(
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE",
E_NOTICE => "E_NOTICE",
E_CORE_ERROR => "E_CORE_ERROR",
E_CORE_WARNING => "E_CORE_WARNING",
E_COMPILE_ERROR => "E_COMPILE_ERROR",
E_COMPILE_WARNING => "E_COMPILE_WARNING",
E_USER_ERROR => "E_USER_ERROR",
E_USER_WARNING => "E_USER_WARNING",
E_USER_NOTICE => "E_USER_NOTICE",
E_STRICT => "E_STRICT",
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
);
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]]:$er["type"];
$dump .= "Error: ".var_export($er, true)."\r\n\r\n";
if(stripos($er["file"], "plugin") !== false){
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
}
$dump .= "Code: \r\n";
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
@ -465,7 +444,13 @@ class PocketMinecraftServer{
}
$dump .= "\r\n\r\n";
}
$dump .= "Loaded Modules: ".var_export(get_loaded_extensions(), true)."\r\n";
$extensions = array();
foreach(get_loaded_extensions() as $ext){
$extensions[$ext] = phpversion($ext);
}
$dump .= "Loaded Modules: ".var_export($extensions, true)."\r\n";
$dump .= "Memory Usage Tracking: \r\n".chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9)))."\r\n";
ob_start();
phpinfo();
@ -474,7 +459,7 @@ class PocketMinecraftServer{
$dump .= "\r\n```";
$name = "Error_Dump_".date("D_M_j-H.i.s-T_Y");
logg($dump, $name, true, 0, true);
console("[ERROR] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
}
public function tick(){
@ -594,6 +579,7 @@ class PocketMinecraftServer{
usleep(10000);
}
}
$this->tick();
}
}
@ -643,11 +629,10 @@ class PocketMinecraftServer{
$this->preparedSQL->updateAction->bindValue(":time", $time, SQLITE3_FLOAT);
$this->preparedSQL->updateAction->bindValue(":id", $cid, SQLITE3_INTEGER);
$this->preparedSQL->updateAction->execute();
$schedule = $this->schedule[$cid];
if(!is_callable($schedule[0])){
if(!@is_callable($this->schedule[$cid][0])){
$return = false;
}else{
$return = call_user_func($schedule[0], $schedule[1], $schedule[2]);
$return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]);
}
if($action["repeat"] == 0 or $return === false){

View file

@ -1,13 +1,13 @@
#!/bin/bash
COMPILER_VERSION="0.14"
PHP_VERSION="5.5.7"
PHP_VERSION="5.5.8"
ZEND_VM="GOTO"
LIBEDIT_VERSION="0.3"
ZLIB_VERSION="1.2.8"
PTHREADS_VERSION="0.0.45"
CURL_VERSION="curl-7_33_0"
CURL_VERSION="curl-7_34_0"
echo "[PocketMine] PHP installer and compiler for Linux & Mac"
DIR="$(pwd)"

View file

@ -37,10 +37,6 @@ if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){
$daylight = (int) date("I");
if($daylight === 0){
$offset -= 3600;
}
date_default_timezone_set(timezone_name_from_abbr("", $offset, $daylight));
gc_enable();
@ -60,7 +56,7 @@ ini_set("memory_limit", "128M"); //Default
define("LOG", true);
define("START_TIME", microtime(true));
define("MAJOR_VERSION", "Alpha_1.3.11");
define("CODENAME", "甘いビートルート");
define("CODENAME", "kotyara :3");
define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha");
define("CURRENT_API_VERSION", 11);
define("CURRENT_PHP_VERSION", "5.5");
@ -69,4 +65,4 @@ if(file_exists(FILE_PATH.".git/refs/heads/master")){ //Found Git information!
define("GIT_COMMIT", strtolower(trim(file_get_contents(FILE_PATH.".git/refs/heads/master"))));
}else{ //Unknown :(
define("GIT_COMMIT", str_repeat("00", 20));
}
}

View file

@ -101,7 +101,7 @@ define("DOOR_BLOCK", 64);
define("WOODEN_DOOR_BLOCK", 64);
define("WOOD_DOOR_BLOCK", 64);
define("LADDER", 65);
define("RAIL", 66);
define("COBBLE_STAIRS", 67);
define("COBBLESTONE_STAIRS", 67);
define("WALL_SIGN", 68);

View file

@ -113,6 +113,7 @@ define("SUGARCANE", 338);
define("SUGAR_CANE", 338);
define("SUGAR_CANES", 338);
define("PAPER", 339);
define("BOOK", 340);
define("SLIMEBALL", 341);
define("EGG", 344);

View file

@ -72,7 +72,7 @@ if(!extension_loaded("zlib") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") .
}
if($errors > 0){
console("[ERROR] Please use the installer provided on the homepage.", true, true, 0);
console("[ERROR] Please use the installer provided on the homepage, or recompile PHP again.", true, true, 0);
exit(1); //Exit with error
}

View file

@ -192,6 +192,7 @@ function console($message, $EOL = true, $log = true, $level = 1){
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){
switch($matches[1]){
case "ERROR":
case "SEVERE":
$add .= FORMAT_RED;
break;
case "INTERNAL":
@ -221,7 +222,25 @@ function error_handler($errno, $errstr, $errfile, $errline){
if(error_reporting() === 0){ //@ error-control
return false;
}
console("[ERROR] A level ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
$errorConversion = array(
E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING",
E_PARSE => "E_PARSE",
E_NOTICE => "E_NOTICE",
E_CORE_ERROR => "E_CORE_ERROR",
E_CORE_WARNING => "E_CORE_WARNING",
E_COMPILE_ERROR => "E_COMPILE_ERROR",
E_COMPILE_WARNING => "E_COMPILE_WARNING",
E_USER_ERROR => "E_USER_ERROR",
E_USER_WARNING => "E_USER_WARNING",
E_USER_NOTICE => "E_USER_NOTICE",
E_STRICT => "E_STRICT",
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
);
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno]:$errno;
console("[ERROR] A ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
return true;
}

View file

@ -79,7 +79,7 @@ abstract class Block extends Position{
SIGN_POST => "SignPostBlock",
WOOD_DOOR_BLOCK => "WoodDoorBlock",
LADDER => "LadderBlock",
RAIL => "RailBlock",
COBBLESTONE_STAIRS => "CobblestoneStairsBlock",
WALL_SIGN => "WallSignBlock",

View file

@ -45,11 +45,11 @@ class LadderBlock extends TransparentBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
/*if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(LADDER, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, true, true);
return BLOCK_UPDATE_NORMAL;
}
}*/
}
return false;
}

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/
*
*
*/
class RailBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(RAIL, 0, "Rail");
$this->hardness = 0.7;
$this->isFullBlock = false;
$this->isSolid = true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() !== AIR and $down instanceof SolidBlock){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
}

View file

@ -30,6 +30,7 @@ class SlabBlock extends TransparentBlock{
4 => "Brick",
5 => "Stone Brick",
6 => "Quartz",
7 => "",
);
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
if(($this->meta & 0x08) === 0x08){

View file

@ -59,8 +59,14 @@ class TallGrassBlock extends FlowableBlock{
0,
0,
0,
0,
0,
0,
0,
);
if(($item = $possibleDrops[mt_rand(0, count($possibleDrops) - 1)]) !== 0){
if ($item->isShears()){
$drops[] = array(TALL_GRASS, 0, 1);
}elseif(($item = $possibleDrops[mt_rand(0, count($possibleDrops) - 1)]) !== 0){
$drops[] = $item;
}
return $drops;

View file

@ -800,12 +800,29 @@ class CustomPacketHandler{
for($s = 0; $s < $this->data["count"] and !$this->feof(); ++$s){
$this->data["slots"][$s] = Utils::readSlot($this);
}
if($this->data["windowid"] == 0){
$slots = min(9, Utils::readShort($this->get(2), false));
$this->data["hotbar"] = array();
if($slots > 0){
for($s = 0; $s < $slots; ++$s){
$this->data["hotbar"][$s] = Utils::readInt($this->get(4));
}
}
}
}else{
$this->raw .= chr($this->data["windowid"]);
$this->raw .= Utils::writeShort(count($this->data["slots"]));
foreach($this->data["slots"] as $slot){
$this->raw .= Utils::writeSlot($slot);
}
if($this->data["windowid"] == 0 and isset($this->data["hotbar"])){
if(count($this->data["hotbar"]) > 0){
$this->raw .= Utils::writeShort(count($this->data["hotbar"]));
foreach($this->data["hotbar"] as $slot){
$this->raw .= Utils::writeInt($slot);
}
}
}
}
break;
case MC_CONTAINER_SET_DATA:

View file

@ -283,7 +283,7 @@ class PMFLevel extends PMF{
return str_repeat("\x00", 8192);
}
$index = $this->getIndex($X, $Z);
if($this->chunks[$index][$Y] === false){
if(!isset($this->chunks[$index][$Y]) or $this->chunks[$index][$Y] === false){
return str_repeat("\x00", 8192);
}
return $this->chunks[$index][$Y];

View file

@ -55,6 +55,7 @@ class CraftingRecipes{
"IRON_INGOT:?x2=>SHEARS:0x1",
"COAL:0x1,STICK:?x1=>TORCH:0x4",
"COAL:1x1,STICK:?x1=>TORCH:0x4",
"BEETROOT:?x1=>DYE:1x2",
//Food & protection
"MELON_SLICE:?x1=>MELON_SEEDS:0x1",
@ -106,9 +107,9 @@ class CraftingRecipes{
"WOODEN_PLANKS:1x6=>SPRUCE_WOOD_STAIRS:0x4",
"WOODEN_PLANKS:1x3=>WOOD_SLAB:1x6",
"WOODEN_PLANKS:2x6=>BIRCH_WOOD_STAIRS:0x4",
"WOODEN_PLANKS:2x3=>BIRCH_WOOD_SLAB:2x6",
"WOODEN_PLANKS:2x3=>WOOD_SLAB:2x6",
"WOODEN_PLANKS:3x6=>JUNGLE_WOOD_STAIRS:0x4",
"WOODEN_PLANKS:3x3=>JUNGLE_WOOD_SLAB:3x6",
"WOODEN_PLANKS:3x3=>WOOD_SLAB:3x6",
//Tools
"STICK:?x1,FEATHER:?x1,FLINT:?x1=>ARROW:0x4",
@ -142,6 +143,7 @@ class CraftingRecipes{
"WOODEN_PLANKS:?x3,STICK:?x2=>WOODEN_PICKAXE:0x1",
"WOODEN_PLANKS:?x1,STICK:?x2=>WOODEN_SHOVEL:0x1",
"WOODEN_PLANKS:?x2,STICK:?x1=>WOODEN_SWORD:0x1",
"IRON_INGOT:?x6,STICK:?x1=>RAIL:0x16",
//Food & protection
"BEETROOT:?x4,BOWL:?x1=>BEETROOT_SOUP:0x1",
@ -184,6 +186,7 @@ class CraftingRecipes{
"IRON_INGOT:?x6=>IRON_BARS:0x16",
"COAL:0x9=>COAL_BLOCK:0x1",
"COAL_BLOCK:?x1=>COAL:0x9",
"MELON_SLICE:?x9=>MELON_BLOCK:?x1",
);
private static $stone = array(

View file

@ -37,6 +37,10 @@ class SmeltingData{
RAW_CHICKEN => array(COOKED_CHICKEN, 0),
RED_MUSHROOM => array(DYE, 1),
POTATO => array(BAKED_POTATO, 0),
BEETROOT => array(DYE, 1),
COAL => array(DYE, 0),
STONE_BRICKS => array(STONE_BRICKS, 2),
);
}

54
src/utils/Cache.php Normal file
View file

@ -0,0 +1,54 @@
<?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 Cache{
public static $cached = array();
public static function add($identifier, $blob, $minTTL = 30){
self::$cached[$identifier] = array($blob, microtime(true) + $minTTL, $minTTL);
}
public static function get($identifier){
if(isset(self::$cached[$identifier])){
self::$cached[$identifier][1] += $minTTL;
return self::$cached[$identifier][0];
}
return false;
}
public static function exists($identifier){
return isset(self::$cached[$identifier]);
}
public static function remove($identifier){
unset(self::$cached[$identifier]);
}
public static function cleanup(){
$time = microtime(true);
foreach(self::$cached as $index => $data){
if($data[1] < $time){
unset(self::$cached[$index]);
}
}
}
}

View file

@ -256,13 +256,13 @@ class Config{
* @return boolean
*/
public function exists($k, $lowercase = false){
if($lowercase === true)://Take this ridiculously retarded IF formatting! - @sekjun98888877777778888888888888
if($lowercase === true){
$k = strtolower($k);//Convert requested key to lower
$array = array_change_key_case($this->config, CASE_LOWER);//Change all keys in array to lower
return isset($array[$k]);//Find $k in modified array
else:
}else{
return isset($this->config[$k]);
endif;
}
}
/**

View file

@ -30,6 +30,33 @@ class Utils{
public static function isOnline(){
return ((@fsockopen("google.com", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false);
}
public static function getUniqueID($raw = false, $extra = ""){
$machine = php_uname("a");
$machine .= file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : "";
$machine .= sys_get_temp_dir();
$machine .= $extra;
if(Utils::getOS() == "win"){
exec("ipconfig /ALL", $mac);
$mac = implode("\n", $mac);
if(preg_match_all("#Physical Address[. ]{1,}: ([0-9A-F\-]{17})#", $mac, $matches)){
foreach($matches[1] as $i => $v){
if($v == "00-00-00-00-00-00"){
unset($matches[1][$i]);
}
}
$machine .= implode(" ", $matches[1]); //Mac Addresses
}
}
$data = $machine . PHP_MAXPATHLEN;
$data .= PHP_INT_MAX;
$data .= PHP_INT_SIZE;
$data .= get_current_user();
foreach(get_loaded_extensions() as $ext){
$data .= $ext.":".phpversion($ext);
}
return hash("md5", $machine, $raw).hash("sha512", $data, $raw);
}
public static function getIP($force = false){
if(Utils::$online === false){

View file

@ -80,15 +80,15 @@ class Entity extends Position{
$this->name = "";
$this->tickCounter = 0;
$this->server->query("INSERT OR REPLACE INTO entities (EID, level, type, class, health, hasUpdate) VALUES (".$this->eid.", '".$this->level->getName()."', ".$this->type.", ".$this->class.", ".$this->health.", 0);");
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
$this->z = isset($this->data["z"]) ? $this->data["z"]:0;
$this->speedX = isset($this->data["speedX"]) ? $this->data["speedX"]:0;
$this->speedY = isset($this->data["speedY"]) ? $this->data["speedY"]:0;
$this->speedZ = isset($this->data["speedZ"]) ? $this->data["speedZ"]:0;
$this->x = isset($this->data["x"]) ? (float) $this->data["x"]:0;
$this->y = isset($this->data["y"]) ? (float) $this->data["y"]:0;
$this->z = isset($this->data["z"]) ? (float) $this->data["z"]:0;
$this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"]:0;
$this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"]:0;
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"]:0;
$this->speed = 0;
$this->yaw = isset($this->data["yaw"]) ? $this->data["yaw"]:0;
$this->pitch = isset($this->data["pitch"]) ? $this->data["pitch"]:0;
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"]:0;
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"]:0;
$this->position = array("level" => $this->level, "x" => &$this->x, "y" => &$this->y, "z" => &$this->z, "yaw" => &$this->yaw, "pitch" => &$this->pitch);
switch($this->class){
case ENTITY_PLAYER:
@ -130,6 +130,9 @@ class Entity extends Position{
if($this->type === OBJECT_PAINTING){
$this->isStatic = true;
}elseif($this->type === OBJECT_PRIMEDTNT){
if(!isset($this->data["fuse"])){
$this->data["fuse"] = 0;
}
$this->setHealth(10000000, "generic");
$this->server->schedule(5, array($this, "updateFuse"), array(), true);
$this->update();
@ -141,6 +144,9 @@ class Entity extends Position{
}
$this->updateLast();
$this->updatePosition();
if($this->y < 0 and $this->class !== ENTITY_PLAYER){
$this->close();
}
}
public function updateFuse(){
@ -239,7 +245,7 @@ class Entity extends Position{
$time = microtime(true);
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true){
foreach($this->server->api->entity->getRadius($this, 1.5, ENTITY_ITEM) as $item){
if($item->spawntime > 0 and ($time - $item->spawntime) >= 0.6){
if($item->closed === false and $item->spawntime > 0 and ($time - $item->spawntime) >= 0.6){
if((($this->player->gamemode & 0x01) === 1 or $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) and $this->server->api->dhandle("player.pickup", array(
"eid" => $this->player->eid,
"player" => $this->player,
@ -817,7 +823,7 @@ class Entity extends Position{
}
public function setPosition(Vector3 $pos, $yaw = false, $pitch = false){
if($pos instanceof Position and $this->level !== $pos->level){
if($pos instanceof Position and $pos->level instanceof Level and $this->level !== $pos->level){
$this->level = $pos->level;
$this->server->preparedSQL->entity->setLevel->reset();
$this->server->preparedSQL->entity->setLevel->clear();
@ -965,7 +971,7 @@ class Entity extends Position{
}else{
return false; //Entity inmunity
}
}elseif($health === $this->health){
}elseif($health === $this->health and !$this->dead){
return false;
}
if($this->server->api->dhandle("entity.health.change", array("entity" => $this, "eid" => $this->eid, "health" => $health, "cause" => $cause)) !== false or $force === true){

View file

@ -299,6 +299,9 @@ class Level{
}
$block->position($pos);
$i = ($pos->x >> 4).":".($pos->y >> 4).":".($pos->z >> 4);
if(ADVANCED_CACHE == true){
Cache::remove("world:{$this->name}:".($pos->x >> 4).":".($pos->z >> 4));
}
if(!isset($this->changedBlocks[$i])){
$this->changedBlocks[$i] = array();
$this->changedCount[$i] = 0;
@ -336,6 +339,9 @@ class Level{
$this->changedBlocks[$i] = array();
$this->changedCount[$i] = 0;
}
if(ADVANCED_CACHE == true){
Cache::remove("world:{$this->name}:".($pos->x >> 4).":".($pos->z >> 4));
}
$this->changedBlocks[$i][] = clone $block;
++$this->changedCount[$i];
}
@ -365,6 +371,9 @@ class Level{
return false;
}
$this->changedCount[$X.":".$Y.":".$Z] = 4096;
if(ADVANCED_CACHE == true){
Cache::remove("world:{$this->name}:$X:$Z");
}
return $this->level->setMiniChunk($X, $Z, $Y, $data);
}
@ -379,6 +388,7 @@ class Level{
if(!isset($this->level)){
return false;
}
Cache::remove("world:{$this->name}:$X:$Z");
return $this->level->unloadChunk($X, $Z);
}
@ -386,6 +396,15 @@ class Level{
if(!isset($this->level)){
return false;
}
if(ADVANCED_CACHE == true and $Yndex == 0xff){
$identifier = "world:{$this->name}:$X:$Z";
if(($cache = Cache::get($identifier)) !== false){
return $cache;
}
}
$raw = array();
for($Y = 0; $Y < 8; ++$Y){
if(($Yndex & (1 << $Y)) > 0){
@ -401,6 +420,9 @@ class Level{
$ordered .= substr($mini, $j << 5, 24); //16 + 8
}
}
if(ADVANCED_CACHE == true and $Yndex == 0xff){
Cache::add($identifier, $ordered, 60);
}
return $ordered;
}
@ -434,7 +456,10 @@ class Level{
$z = (int) round($spawn->z);
for(; $y > 0; --$y){
$v = new Vector3($x, $y, $z);
if(!($this->getBlock($v->getSide(0)) instanceof AirBlock)){
$b = $this->getBlock($v->getSide(0));
if($b === false){
return $spawn;
}elseif(!($b instanceof AirBlock)){
break;
}
}

View file

@ -234,7 +234,7 @@ class Tile extends Position{
$raw = $this->getSlot(0);
$product = $this->getSlot(2);
$smelt = $raw->getSmeltItem();
$canSmelt = $smelt !== false and $raw->count > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->count < $product->getMaxStackSize()) or $product->getID() === AIR);
$canSmelt = ($smelt !== false and $raw->count > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->count < $product->getMaxStackSize()) or $product->getID() === AIR));
if($this->data["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->count > 0){
$this->lastUpdate = microtime(true);
$this->data["MaxTime"] = $this->data["BurnTime"] = floor($fuel->getFuelTime() * 20);