mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Fixed Memory Leak
This commit is contained in:
parent
8d3ad0c5ec
commit
6102efc809
@ -31,42 +31,16 @@ class EntityAPI{
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->addHandler("player.death", array($this, "handle"), 1);
|
||||
}
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "player.death":
|
||||
$message = $data["name"];
|
||||
if(is_numeric($data["cause"]) and isset($this->entities[$data["cause"]])){
|
||||
$e = $this->api->entity->get($data["cause"]);
|
||||
switch($e->class){
|
||||
case ENTITY_PLAYER:
|
||||
$message .= " was killed by ".$e->name;
|
||||
break;
|
||||
default:
|
||||
$message .= " was killed";
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
switch($data["cause"]){
|
||||
default:
|
||||
$message .= " was killed";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->server->chat(false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function get($eid){
|
||||
if(isset($this->server->entities[$eid])){
|
||||
return $this->server->entities[$eid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function init(){
|
||||
|
||||
}
|
||||
|
||||
public function getAll(){
|
||||
return $this->server->entities;
|
||||
|
@ -32,7 +32,8 @@ class PlayerAPI{
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->event("server.regeneration", array($this, "handle"));
|
||||
$this->server->addHandler("server.regeneration", array($this, "handle"));
|
||||
$this->server->addHandler("player.death", array($this, "handle"), 1);
|
||||
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
|
||||
@ -51,6 +52,27 @@ class PlayerAPI{
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "player.death":
|
||||
$message = $data["name"];
|
||||
if(is_numeric($data["cause"]) and isset($this->entities[$data["cause"]])){
|
||||
$e = $this->api->entity->get($data["cause"]);
|
||||
switch($e->class){
|
||||
case ENTITY_PLAYER:
|
||||
$message .= " was killed by ".$e->name;
|
||||
break;
|
||||
default:
|
||||
$message .= " was killed";
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
switch($data["cause"]){
|
||||
default:
|
||||
$message .= " was killed";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->server->chat(false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,9 +202,7 @@ class PlayerAPI{
|
||||
public function remove($CID){
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$player = $this->server->clients[$CID];
|
||||
if(is_object($player->entity)){
|
||||
$player->entity->close();
|
||||
}
|
||||
$this->server->api->entity->remove($player->entity->eid);
|
||||
$this->saveOffline($player->username, $player->data);
|
||||
$this->server->query("DELETE FROM players WHERE name = '".$player->username."';");
|
||||
unset($this->server->entities[$player->eid]);
|
||||
|
@ -92,23 +92,25 @@ class Player{
|
||||
}
|
||||
|
||||
public function close($reason = "", $msg = true){
|
||||
$reason = $reason == "" ? "server stop":$reason;
|
||||
$this->save();
|
||||
foreach($this->evid as $ev){
|
||||
$this->server->deleteEvent($ev);
|
||||
}
|
||||
$this->eventHandler("You have been kicked. Reason: ".$reason, "server.chat");
|
||||
$this->dataPacket(MC_LOGIN_STATUS, array(
|
||||
"status" => 1,
|
||||
));
|
||||
$this->dataPacket(MC_DISCONNECT);
|
||||
if($this->connected === true){
|
||||
$reason = $reason == "" ? "server stop":$reason;
|
||||
$this->save();
|
||||
foreach($this->evid as $ev){
|
||||
$this->server->deleteEvent($ev);
|
||||
}
|
||||
$this->eventHandler("You have been kicked. Reason: ".$reason, "server.chat");
|
||||
$this->dataPacket(MC_LOGIN_STATUS, array(
|
||||
"status" => 1,
|
||||
));
|
||||
$this->dataPacket(MC_DISCONNECT);
|
||||
|
||||
$this->connected = false;
|
||||
if($msg === true){
|
||||
$this->server->api->dhandle("server.chat", $this->username." left the game");
|
||||
$this->connected = false;
|
||||
if($msg === true){
|
||||
$this->server->api->dhandle("server.chat", $this->username." left the game");
|
||||
}
|
||||
console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason);
|
||||
$this->server->api->player->remove($this->CID);
|
||||
}
|
||||
console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason);
|
||||
$this->server->api->player->remove($this->CID);
|
||||
}
|
||||
|
||||
public function eventHandler($data, $event){
|
||||
|
@ -210,6 +210,7 @@ class PocketMinecraftServer{
|
||||
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
||||
$handlers = $this->preparedSQL->selectHandlers->execute();
|
||||
$result = true;
|
||||
console("[INTERNAL] Handling ".$event, true, true, 3);
|
||||
if($handlers !== false and $handlers !== true){
|
||||
while(false !== ($hn = $handlers->fetchArray(SQLITE3_ASSOC)) and $result !== false){
|
||||
$handler = $this->handlers[(int) $hn["ID"]];
|
||||
|
Loading…
x
Reference in New Issue
Block a user