From ce7c7efc7908dbdc6b52f049748fc18e4816f4b4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sun, 13 Jan 2013 12:18:07 +0100 Subject: [PATCH] Fixes --- src/API/PluginAPI.php | 2 +- src/API/ServerAPI.php | 4 +- src/classes/network/MinecraftInterface.php | 8 +- src/classes/utils/Config.php | 111 +++++++++++++++++++++ 4 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 src/classes/utils/Config.php diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 4dce5689..7e07ff76 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or */ class PluginAPI extends stdClass{ - private $server + private $server; private $plugins = array(); public function __construct(PocketMinecraftServer $server){ $this->server = $server; diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 1ae8ef7d..a73d6cb2 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -27,8 +27,8 @@ the Free Software Foundation, either version 3 of the License, or class ServerAPI{ var $restart = false; - private $server - private $config + private $server; + private $config; private $apiList = array(); public function run(){ diff --git a/src/classes/network/MinecraftInterface.php b/src/classes/network/MinecraftInterface.php index c6606e12..6d9b1351 100644 --- a/src/classes/network/MinecraftInterface.php +++ b/src/classes/network/MinecraftInterface.php @@ -26,11 +26,11 @@ the Free Software Foundation, either version 3 of the License, or */ class MinecraftInterface{ - var $pstruct - var $name - var $client + var $pstruct; + var $name; + var $client; var $dataName; - private $socket + private $socket; private $data; function __construct($server, $port = 25565, $listen = false, $client = true){ $this->socket = new UDPSocket($server, $port, (bool) $listen); diff --git a/src/classes/utils/Config.php b/src/classes/utils/Config.php new file mode 100644 index 00000000..f4014657 --- /dev/null +++ b/src/classes/utils/Config.php @@ -0,0 +1,111 @@ + CONFIG_PROPERTIES, + "cnf" => CONFIG_CNF, + "conf" => CONFIG_CNF, + "config" => CONFIG_CNF, + "json" => CONFIG_JSON, + "js" => CONFIG_JSON, + "yml" => CONFIG_YAML, + "yaml" => CONFIG_YAML, + "export" => CONFIG_EXPORT, + "xport" => CONFIG_EXPORT, + "sl" => CONFIG_SERIALIZE, + "serialize" => CONFIG_SERIALIZE, + "txt" => CONFIG_LIST, + "list" => CONFIG_LIST, + ); + public function __construct($file, $type = CONFIG_DETECT, $default = array()){ + $this->type = (int) $type; + $this->file = $file; + if(!file_exists($file)){ + $this->config = $default; + }else{ + if($this->type === CONFIG_DETECT){ + $extension = explode(".", basename($this->file)); + $extension = strtolower(trim(array_pop($extension))); + if(isset(Config::$formats[$extension])){ + $this->type = Config::$formats[$extension]; + }else{ + $this->correct = false; + } + } + if($this->correct === true){ + $content = @file_get_contents($this->file); + switch($this->type){ + case CONFIG_PROPERTIES: + case CONFIG_CNF: + $this->parseProperties($content); + break; + } + var_dump($this->config); + die(); + } + } + } + + private function parseProperties($content){ + if(preg_match_all('/([a-zA-Z0-9\-_]*)=([^\r\n]*)/u', $content, $matches) == 0){ //false or 0 matches + foreach($matches[1] as $k => $i){ + $v = trim($matches[2][$k]); + switch(strtolower($v)){ + case "on": + case "true": + case "yes": + $v = true; + break; + case "off": + case "false": + case "no": + $v = false; + break; + } + if(isset($this->config[$k])){ + console("[NOTICE] [Config] Repeated property ".$k." on file ".$this->file, true, true, 2); + } + $this->config[$k] = $v; + } + } + } + +} \ No newline at end of file