Did some improvements

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-15 19:25:33 +01:00
parent 4ddb8a298b
commit fe7595e313
7 changed files with 25 additions and 12 deletions

View File

@ -235,8 +235,13 @@ class ServerAPI{
private function loadProperties(){ private function loadProperties(){
if($this->getProperty("memory-limit") !== false){ if(($memory = $this->getProperty("memory-limit")) !== false){
@ini_set("memory_limit", $this->getProperty("memory-limit")); $value = array("M" => 1, "G" => 1024);
$real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)];
if($real < 128){
console("[ERROR] PocketMine doesn't work right with less than 128MB of RAM", true, true, 0);
}
@ini_set("memory_limit", $memory);
}else{ }else{
$this->setProperty("memory-limit", "256M"); $this->setProperty("memory-limit", "256M");
} }

View File

@ -165,7 +165,7 @@ class PocketMinecraftServer{
$reason = "signal stop"; $reason = "signal stop";
} }
$this->api->chat->send(false, "Stopping server..."); $this->api->chat->send(false, "Stopping server...");
$this->ticker->stop = true; //$this->ticker->stop = true;
$this->save(true); $this->save(true);
$this->stop = true; $this->stop = true;
$this->trigger("server.close", $reason); $this->trigger("server.close", $reason);
@ -328,8 +328,8 @@ class PocketMinecraftServer{
} }
console("[INFO] Loading events..."); console("[INFO] Loading events...");
$this->loadEvents(); $this->loadEvents();
$this->ticker = new TickLoop($this); //$this->ticker = new TickLoop($this);
$this->ticker->start(); //$this->ticker->start();
declare(ticks=15); declare(ticks=15);
register_tick_function(array($this, "tick")); register_tick_function(array($this, "tick"));
register_shutdown_function(array($this, "dumpError")); register_shutdown_function(array($this, "dumpError"));
@ -358,6 +358,8 @@ class PocketMinecraftServer{
global $arguments; global $arguments;
$dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n"; $dump .= "Parameters: ".var_export($arguments, true)."\r\n\r\n\r\n";
$dump .= "server.properties: ".var_export($this->api->getProperties(), true)."\r\n\r\n\r\n"; $dump .= "server.properties: ".var_export($this->api->getProperties(), true)."\r\n\r\n\r\n";
global $lasttrace;
$dump .= "Last Backtrace: ".$lasttrace."\r\n\r\n\r\n";
$dump .= "Loaded Modules: ".var_export(get_loaded_extensions(), true)."\r\n\r\n"; $dump .= "Loaded Modules: ".var_export(get_loaded_extensions(), true)."\r\n\r\n";
$name = "error_dump_".time(); $name = "error_dump_".time();
logg($dump, $name, true, 0, true); logg($dump, $name, true, 0, true);
@ -504,7 +506,7 @@ class PocketMinecraftServer{
public function process(){ public function process(){
while($this->stop === false){ while($this->stop === false){
$packet = @$this->interface->readPacket(); $packet = $this->interface->readPacket();
if($packet !== false){ if($packet !== false){
$this->packetHandler($packet); $this->packetHandler($packet);
}else{ }else{

View File

@ -95,7 +95,7 @@ class MinecraftInterface{
} }
$packet = new Packet($pid, $struct, $data[0]); $packet = new Packet($pid, $struct, $data[0]);
$packet->parse(); @$packet->parse();
$this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]); $this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]);
return $this->popPacket(); return $this->popPacket();
} }
@ -121,7 +121,7 @@ class MinecraftInterface{
if($raw === false){ if($raw === false){
$packet = new Packet($pid, $struct); $packet = new Packet($pid, $struct);
$packet->data = $data; $packet->data = $data;
$packet->create(); @$packet->create();
$write = $this->socket->write($packet->raw, $dest, $port); $write = $this->socket->write($packet->raw, $dest, $port);
$this->writeDump($pid, $packet->raw, $data, "client", $dest, $port); $this->writeDump($pid, $packet->raw, $data, "client", $dest, $port);
}else{ }else{

View File

@ -247,7 +247,6 @@ class Utils extends Thread{
(string) mt_rand(), (string) mt_rand(),
(string) rand(), (string) rand(),
function_exists("zend_thread_id") ? ((string) zend_thread_id()):microtime(), function_exists("zend_thread_id") ? ((string) zend_thread_id()):microtime(),
var_export(@get_browser(), true),
function_exists("sys_getloadavg") ? implode(";", sys_getloadavg()):microtime(), function_exists("sys_getloadavg") ? implode(";", sys_getloadavg()):microtime(),
serialize(get_loaded_extensions()), serialize(get_loaded_extensions()),
sys_get_temp_dir(), sys_get_temp_dir(),

View File

@ -34,7 +34,7 @@ ini_set("display_errors", 1);
ini_set('default_charset', 'utf-8'); ini_set('default_charset', 'utf-8');
define("FILE_PATH", dirname(__FILE__)."/../../"); define("FILE_PATH", dirname(__FILE__)."/../../");
set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH . PATH_SEPARATOR . FILE_PATH . "/src/" . PATH_SEPARATOR . FILE_PATH . "/src/classes/"); set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH . PATH_SEPARATOR . FILE_PATH . "/src/" . PATH_SEPARATOR . FILE_PATH . "/src/classes/");
ini_set("memory_limit", "512M"); ini_set("memory_limit", "256M");
define("LOG", true); define("LOG", true);
define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"); define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78");
define("TEST_MD5", "d0ca3786e53b615bb4fb9f5094d5c9a7"); define("TEST_MD5", "d0ca3786e53b615bb4fb9f5094d5c9a7");

View File

@ -32,7 +32,7 @@ if(strpos(strtoupper(php_uname("s")), "WIN") === false or arg("enable-ansi", fal
}else{ }else{
define("ENABLE_ANSI", false); define("ENABLE_ANSI", false);
} }
//set_error_handler("error_handler"); set_error_handler("fatal_handler", E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_DEPRECATED);
$errors = 0; $errors = 0;

View File

@ -202,8 +202,15 @@ function console($message, $EOL = true, $log = true, $level = 1){
} }
} }
function error_handler($errno, $errstr, $errfile, $errline){ function fatal_handler($errno, $errstr, $errfile, $errline){
global $lasttrace;
console("[ERROR] A level ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0); console("[ERROR] A level ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
ob_start();
debug_print_backtrace();
$lasttrace = ob_get_contents();
ob_end_clean();
console("[ERROR] [Backtrace] $lasttrace", true, true, 0);
return false;
} }
function logg($message, $name, $EOL = true, $level = 2, $close = false){ function logg($message, $name, $EOL = true, $level = 2, $close = false){