Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Commit

Permalink
SimpleAuthHelper-2.0.0dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Aug 21, 2015
1 parent 6bd5950 commit 94b9b78
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion SimpleAuthHelper/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 22 additions & 12 deletions SimpleAuthHelper/src/aliuly/helper/DbMonitorTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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"));
}
Expand Down
2 changes: 1 addition & 1 deletion SimpleAuthHelper/src/aliuly/helper/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 94b9b78

Please sign in to comment.