From 94b9b78658d8ad93c45a8e8e8a89eeece1e7f737 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Fri, 21 Aug 2015 07:32:09 +0200 Subject: [PATCH] SimpleAuthHelper-2.0.0dev2 --- SimpleAuthHelper/plugin.yml | 2 +- .../src/aliuly/helper/DbMonitorTask.php | 34 ++++++++++++------- SimpleAuthHelper/src/aliuly/helper/Main.php | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/SimpleAuthHelper/plugin.yml b/SimpleAuthHelper/plugin.yml index 681ed71..21e3296 100644 --- a/SimpleAuthHelper/plugin.yml +++ b/SimpleAuthHelper/plugin.yml @@ -5,7 +5,7 @@ depend: [SimpleAuth] name: SimpleAuthHelper description: Simplifies the way people authenticate to servers -version: 2.0.0dev1 +version: 2.0.0dev2 author: aliuly commands: diff --git a/SimpleAuthHelper/src/aliuly/helper/DbMonitorTask.php b/SimpleAuthHelper/src/aliuly/helper/DbMonitorTask.php index 526a945..77b49ce 100644 --- a/SimpleAuthHelper/src/aliuly/helper/DbMonitorTask.php +++ b/SimpleAuthHelper/src/aliuly/helper/DbMonitorTask.php @@ -9,13 +9,7 @@ use aliuly\helper\Main as HelperPlugin; use aliuly\helper\common\mc; use pocketmine\utils\TextFormat; -use pocketmine\event\player\PlayerLoginEvent; - -use pocketmine\Player; -use pocketmine\event\player\PlayerCommandPreprocessEvent; -use pocketmine\event\player\PlayerQuitEvent; -use pocketmine\event\player\PlayerCommandPreprocessEvent; - +use pocketmine\event\player\PlayerJoinEvent; class DbMonitorTask extends PluginTask implements Listener{ protected $canary; @@ -50,7 +44,26 @@ private function setStatus($mode) { $this->getOwner()->getServer()->broadcastMessage(TextFormat::RED.mc::_("Detected loss of database connectivity!")); } } + private function enableAuth($mgr,$auth) { + if ($auth === null) return false; // OK, this is weird! + if ($auth->isEnabled()) return true; + $this->getOwner()->getLogger()->info(mc::_("Enabling SimpleAuth")); + $mgr->enablePlugin($auth); + if (!$auth->isEnabled()) return false; + $this->dbm = $auth->getDataProvider(); + return true; + } + public function onRun($currentTicks){ + //echo __METHOD__.",".__LINE__."\n";//##DEBUG + $mgr = $this->getOwner()->getServer()->getPluginManager(); + $auth = $mgr->getPlugin("SimpleAuth"); + if ($auth === null) return; // OK, this is weird! + + if (!$auth->isEnabled()) { + if (!$this->enableAuth($mgr,$auth)) return; // Ouch... + } + $player = $this->getOwner()->getServer()->getOfflinePlayer($this->canary); if ($player == null) return;//We can't proceed! if ($this->dbm->isPlayerRegistered($player)) { @@ -64,20 +77,17 @@ public function onRun($currentTicks){ /* * let's try to reconnect by resetting SimpleAuth */ - $mgr = $this->getOwner()->getServer()->getPluginManager(); - $auth = $mgr->getPlugin("SimpleAuth"); - if ($auth === null) return; // OK, this is weird! if ($auth->isEnabled()) { $this->getOwner()->getLogger()->info(mc::_("Disabling SimpleAuth")); $mgr->disablePlugin($auth); } if (!$auth->isEnabled()) { $this->getOwner()->getLogger()->info(mc::_("Enabling SimpleAuth")); - $mgr->enablePlugin($auth); + if (!$this->enableAuth($mgr,$auth)) return; // Ouch... } if ($this->dbm->isPlayerRegistered($player)) $this->setStatus(true); } - public function onConnect(PlayerLoginEvent $ev) { + public function onConnect(PlayerJoinEvent $ev) { if ($this->ok) return; $ev->getPlayer()->kick(mc::_("Database is experiencing technical difficulties")); } diff --git a/SimpleAuthHelper/src/aliuly/helper/Main.php b/SimpleAuthHelper/src/aliuly/helper/Main.php index abfffae..f8c0345 100644 --- a/SimpleAuthHelper/src/aliuly/helper/Main.php +++ b/SimpleAuthHelper/src/aliuly/helper/Main.php @@ -91,7 +91,7 @@ public function onEnable(){ if ($this->cfg["hack-login-perms"] || $this->cfg["hack-register-perms"]) { $this->permshacker = new PermsHacker($this,$this->cfg["hack-login-perms"],$this->cfg["hack-register-perms"]); } - if ($this->cfg["mysql-monitor"]) { + if ($this->cfg["db-monitor"]) { $this->monitor = new DbMonitorTask($this,$this->cfg["monitor-settings"]); } $this->pwds = [];