Allow console parameters

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-07 01:58:15 +01:00
parent a6ddba8d97
commit 19aa4bd527
3 changed files with 54 additions and 15 deletions

View File

@ -87,10 +87,10 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
console("[DEBUG] Loading server.properties...", true, true, 2); console("[DEBUG] Loading server.properties...", true, true, 2);
$this->parseProperties(); $this->parseProperties();
define("DEBUG", $this->config["debug"]); define("DEBUG", $this->getProperty("debug"));
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id")); $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id"));
$this->server->api = $this; $this->server->api = $this;
if($this->getProperty("upnp-forwarding") === true ){ if($this->getProperty("upnp-forwarding") === true){
console("[INFO] [UPnP] Trying to port forward..."); console("[INFO] [UPnP] Trying to port forward...");
UPnP_PortForward($this->getProperty("port")); UPnP_PortForward($this->getProperty("port"));
} }
@ -211,8 +211,8 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
private function loadProperties(){ private function loadProperties(){
if(isset($this->config["memory-limit"])){ if($this->getProperty("memory-limit") !== false){
@ini_set("memory_limit", $this->config["memory-limit"]); @ini_set("memory_limit", $this->getProperty("memory-limit"));
}else{ }else{
$this->config["memory-limit"] = "256M"; $this->config["memory-limit"] = "256M";
} }
@ -220,15 +220,15 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$this->config["invisible"] = false; $this->config["invisible"] = false;
} }
if(is_object($this->server)){ if(is_object($this->server)){
$this->server->setType($this->config["server-type"]); $this->server->setType($this->getProperty("server-type"));
$this->server->timePerSecond = $this->config["time-per-second"]; $this->server->timePerSecond = $this->getProperty("time-per-second");
$this->server->invisible = $this->config["invisible"]; $this->server->invisible = $this->getProperty("invisible");
$this->server->maxClients = $this->config["max-players"]; $this->server->maxClients = $this->getProperty("max-players");
$this->server->description = $this->config["description"]; $this->server->description = $this->getProperty("description");
$this->server->motd = $this->config["motd"]; $this->server->motd = $this->getProperty("motd");
$this->server->gamemode = $this->config["gamemode"]; $this->server->gamemode = $this->getProperty("gamemode");
$this->server->difficulty = $this->config["difficulty"]; $this->server->difficulty = $this->getProperty("difficulty");
$this->server->whitelist = $this->config["white-list"]; $this->server->whitelist = $this->getProperty("white-list");
$this->server->reloadConfig(); $this->server->reloadConfig();
} }
} }
@ -389,6 +389,43 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
} }
public function getProperty($name){ public function getProperty($name){
if(($v = arg($name)) !== false){ //Allow for command-line arguments
switch(strtolower(trim($v))){
case "on":
case "true":
case "yes":
$v = true;
break;
case "off":
case "false":
case "no":
$v = false;
break;
}
switch($name){
case "last-update":
if($v === false){
$v = time();
}else{
$v = (int) $v;
}
break;
case "gamemode":
case "max-players":
case "port":
case "debug":
case "difficulty":
case "time-per-second":
$v = (int) $v;
break;
case "server-id":
if($v !== false){
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
}
break;
}
return $v;
}
if(isset($this->config[$name])){ if(isset($this->config[$name])){
return $this->config[$name]; return $this->config[$name];
} }

View File

@ -335,6 +335,8 @@ class PocketMinecraftServer extends stdClass{
$dump .= "Zend version: ".zend_version()."\r\n"; $dump .= "Zend version: ".zend_version()."\r\n";
$dump .= "OS : " .PHP_OS.", ".Utils::getOS()."\r\n"; $dump .= "OS : " .PHP_OS.", ".Utils::getOS()."\r\n";
$dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\r\n"; $dump .= "Debug Info: ".var_export($this->debugInfo(false), true)."\r\n\r\n\r\n";
global $arguments;
$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";
$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();

View File

@ -107,7 +107,7 @@ function parseNBTData($data){
} }
function arg($name, $default){ function arg($name, $default = false){
global $arguments, $argv; global $arguments, $argv;
if(!isset($arguments)){ if(!isset($arguments)){
$arguments = arguments($argv); $arguments = arguments($argv);
@ -127,7 +127,7 @@ function arguments ( $args ){
array_shift( $args ); array_shift( $args );
$args = join( $args, ' ' ); $args = join( $args, ' ' );
preg_match_all('/ (--\w+ (?:[= ] [^-]+ [^\s-] )? ) | (-\w+) | (\w+) /x', $args, $match ); preg_match_all('/ (--[\w\-]+ (?:[= ] [^-]+ [^\s-] )? ) | (-\w+) | (\w+) /x', $args, $match );
$args = array_shift( $match ); $args = array_shift( $match );
$ret = array( $ret = array(