From ef76138a1cfa8ad4e0b7c060bfeaa4ade8cf8a2d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Mon, 21 Jan 2013 00:19:49 +0100 Subject: [PATCH] Internal Fixes --- src/API/EntityAPI.php | 2 +- src/classes/Player.php | 7 ++++++- src/classes/PocketMinecraftServer.php | 6 +++--- src/classes/world/Entity.php | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 54f14f37..41d464a4 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -55,7 +55,7 @@ class EntityAPI{ if($e === false or $e->dead === true){ return false; } - $e->setHealth($e->getHealth()-$attack, $cause); + $e->setHealth($e->getHealth() - $attack, $cause); } public function add($class, $type = 0, $data = array()){ diff --git a/src/classes/Player.php b/src/classes/Player.php index 646957b8..4551b82d 100644 --- a/src/classes/Player.php +++ b/src/classes/Player.php @@ -47,6 +47,7 @@ class Player{ var $spawned = false; var $inventory; var $equipment = array(1, 0); + var $loggedIn = false; function __construct(PocketMinecraftServer $server, $clientID, $ip, $port, $MTU){ $this->MTU = $MTU; $this->server = $server; @@ -345,6 +346,10 @@ class Player{ break; case MC_LOGIN: + if($this->loggedIn === true){ + break; + } + $this->loggedIn = true; $this->username = str_replace(array("\x00", "/", " ", "\r", "\n"), array("", "-", "_", "", ""), $data["username"]); if($this->username == ""){ $this->close("bad username", false); @@ -371,7 +376,7 @@ class Player{ } $this->server->api->player->add($this->CID); $this->auth = true; - if(!isset($this->data["inventory"])){ + if(!isset($this->data["inventory"]) or $this->server->gamemode === 1){ $this->data["inventory"] = $this->inventory; } $this->inventory = &$this->data["inventory"]; diff --git a/src/classes/PocketMinecraftServer.php b/src/classes/PocketMinecraftServer.php index 0c1d556a..94be2432 100644 --- a/src/classes/PocketMinecraftServer.php +++ b/src/classes/PocketMinecraftServer.php @@ -283,7 +283,7 @@ class PocketMinecraftServer{ if($this->map !== false){ console("[INFO] Loading entities..."); $entities = unserialize(file_get_contents($this->mapDir."entities.dat")); - if($entities === false){ + if($entities === false or !is_array($entities)){ console("[ERROR] Invalid world data for \"".$this->mapDir."\. Please import the world correctly"); $this->close("invalid world data"); } @@ -564,7 +564,7 @@ class PocketMinecraftServer{ return $chcnt; } - public function action($microseconds, $code, $repeat = true){ + public function action($microseconds, $code, $repeat = true){ $this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");"); console("[INTERNAL] Attached to action ".$microseconds, true, true, 3); } @@ -579,7 +579,7 @@ class PocketMinecraftServer{ if($actions === false or $actions === true){ return; } - while(false !== ($action = $actions->fetchArray(SQLITE3_ASSOC))){ + while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){ $return = eval(base64_decode($action["code"])); if($action["repeat"] === 0 or $return === false){ $this->query("DELETE FROM actions WHERE ID = ".$action["ID"].";"); diff --git a/src/classes/world/Entity.php b/src/classes/world/Entity.php index eb72189d..d6362207 100644 --- a/src/classes/world/Entity.php +++ b/src/classes/world/Entity.php @@ -49,7 +49,7 @@ class Entity extends stdClass{ $this->closed = false; $this->name = ""; $this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");"); - $this->server->schedule(2, array($this, "update"), array(), true); + $this->server->schedule(4, array($this, "update"), array(), true); $this->metadata = array(); $this->x = isset($this->data["x"]) ? $this->data["x"]:0; $this->y = isset($this->data["y"]) ? $this->data["y"]:0; @@ -82,7 +82,7 @@ class Entity extends stdClass{ public function update(){ $this->calculateVelocity(); $this->server->api->dhandle("entity.move", $this); - if($this->class === ENTITY_ITEM and $this->closed === false){ + if($this->class === ENTITY_ITEM and $this->closed === false and $this->server->gamemode === 0){ $player = $this->server->query("SELECT EID FROM entities WHERE class == ".ENTITY_PLAYER." AND abs(x - {$this->x}) <= 1.5 AND abs(y - {$this->y}) <= 1.5 AND abs(z - {$this->z}) <= 1.5 LIMIT 1;", true); if($player !== true and $player !== false){ if($this->server->api->dhandle("player.pickup", array(