From 01e9ca78528e600dabdaa3cbe40adabe9fe9a2f0 Mon Sep 17 00:00:00 2001 From: Michael Yoo Date: Sat, 14 Dec 2013 16:06:28 +1030 Subject: [PATCH] Fix #971. Add lowercase checking of Config. --- src/API/BanAPI.php | 23 ++++++++++++++++++----- src/utils/Config.php | 18 +++++++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 82e89f68..1ee8821e 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -21,9 +21,16 @@ class BanAPI{ private $server; + /* + * I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878 + */ + /** @var Config */ private $whitelist; + /** @var Config */ private $banned; + /** @var Config */ private $ops; + /** @var Config */ private $bannedIPs; private $cmdWL = array();//Command WhiteList function __construct(){ @@ -349,10 +356,13 @@ class BanAPI{ public function isIPBanned($ip){ if($this->server->api->dhandle("api.ban.ip.check", $ip) === false){ return true; - }elseif($this->bannedIPs->exists($ip)){ + }elseif($this->bannedIPs->exists($ip, true)){ return true; } - return false; + else + { + return false; + } } /** @@ -364,10 +374,13 @@ class BanAPI{ $username = strtolower($username); if($this->server->api->dhandle("api.ban.check", $username) === false){ return true; - }elseif($this->banned->exists($username)){ + }elseif($this->banned->exists($username, true)){ return true; } - return false; + else + { + return false; + } } /** @@ -381,7 +394,7 @@ class BanAPI{ return true; }elseif($this->server->api->dhandle("api.ban.whitelist.check", $username) === false){ return true; - }elseif($this->whitelist->exists($username)){ + }elseif($this->whitelist->exists($username, true)){ return true; } return false; diff --git a/src/utils/Config.php b/src/utils/Config.php index 1550c497..1099d5fc 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -181,9 +181,21 @@ class Config{ public function setAll($v){ $this->config = $v; } - - public function exists($k){ - return isset($this->config[$k]); + + /** + * @param mixed $k + * @param bool $lowercase If set, searches Config in single-case / lowercase. + * + * @return boolean + */ + public function exists($k, $lowercase = false){ + if($lowercase === true)://Take this ridiculously retarded IF formatting! - @sekjun98888877777778888888888888 + $k = strtolower($k);//Convert requested key to lower + $array = array_change_key_case($this->config, CASE_LOWER);//Change all keys in array to lower + return isset($array[$k]);//Find $k in modified array + else: + return isset($this->config[$k]); + endif; } public function remove($k){