From 12ff5b5e6744ae7f52bee3e40856202f5c610fbf Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Tue, 26 May 2015 10:31:00 +0200 Subject: [PATCH 1/2] Added login timeout --- README.md | 2 +- resources/config.yml | 3 +- resources/messages.yml | 3 +- src/SimpleAuth/EventListener.php | 5 +++ src/SimpleAuth/task/TimeoutTask.php | 55 +++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/SimpleAuth/task/TimeoutTask.php diff --git a/README.md b/README.md index 61fb74e..43579ea 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You can modify the _SimpleAuth/config.yml_ file on the _plugins_ directory once | Configuration | Type | Default | Description | | :---: | :---: | :---: | :--- | -| timeout | integer | 60 | Unauthenticated players will be kicked after this period of time. Set it to 0 to disable. (TODO) | +| timeout | integer | 60 | Unauthenticated players will be kicked after this period of time. Set it to "false" to disable. | | forceSingleSession | boolean | true | New players won't kick an authenticated player if using the same name. | | minPasswordLength | integer | 6 | Minimum length of the register password. | | blockAfterFail | integer | 6 | Block clients after several failed attempts | diff --git a/resources/config.yml b/resources/config.yml index e534691..15d17ab 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -33,5 +33,4 @@ disableRegister: false disableLogin: false #Number of seconds to wait for a player to be authenticated. If false, disables the timeout -#TODO -authenticateTimeout: 120 \ No newline at end of file +authenticateTimeout: 60 diff --git a/resources/messages.yml b/resources/messages.yml index 221cc07..2d943f1 100644 --- a/resources/messages.yml +++ b/resources/messages.yml @@ -24,4 +24,5 @@ login: error: password: "Incorrect password!" registered: "This account is not registered." - block: "Too many tries!" \ No newline at end of file + block: "Too many tries!" + timeout: "Login timer expired!" diff --git a/src/SimpleAuth/EventListener.php b/src/SimpleAuth/EventListener.php index 10fe512..7a2735f 100644 --- a/src/SimpleAuth/EventListener.php +++ b/src/SimpleAuth/EventListener.php @@ -33,6 +33,7 @@ use pocketmine\event\player\PlayerRespawnEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\Player; +use SimpleAuth\task\TimeoutTask; class EventListener implements Listener{ /** @var SimpleAuth */ @@ -56,6 +57,10 @@ public function onPlayerJoin(PlayerJoinEvent $event){ } } $this->plugin->deauthenticatePlayer($event->getPlayer()); + $timer = $this->plugin->getConfig()->get("authenticateTimeout"); + if($timer !== false){ + $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new TimeoutTask($this->plugin,$event->getPlayer()),$timer * 20); + } } /** diff --git a/src/SimpleAuth/task/TimeoutTask.php b/src/SimpleAuth/task/TimeoutTask.php new file mode 100644 index 0000000..3b25c1b --- /dev/null +++ b/src/SimpleAuth/task/TimeoutTask.php @@ -0,0 +1,55 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. +*/ +namespace SimpleAuth\task; + +use pocketmine\scheduler\PluginTask; +use SimpleAuth\SimpleAuth; + +/** + * Allows the creation of simple callbacks with extra data + * The last parameter in the callback will be this object + * + */ +class TimeoutTask extends PluginTask{ + + /** @var player */ + protected $player; + + public function __construct(SimpleAuth $plugin,$player){ + parent::__construct($plugin); + $this->player = $player->getName(); + } + /** + * @return SimpleAuth + */ + public function getPlugin(){ + return $this->owner; + } + + public function onRun($currentTicks){ + $plugin = $this->getPlugin(); + if($plugin->isDisabled()){ + return; + } + $player = $plugin->getServer()->getPlayer($this->player); + if($player !== null){ + if (!$plugin->isPlayerAuthenticated($player)) { + $player->kick($plugin->getMessage("login.error.timeout")); + } + } + } +} From 70eb7e68c8032ca3107d5413f1ab6b5c670a27d2 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Tue, 26 May 2015 15:41:40 +0200 Subject: [PATCH 2/2] Change disable settings to 0 or -1 --- README.md | 2 +- resources/config.yml | 2 +- src/SimpleAuth/EventListener.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 43579ea..ad6efef 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You can modify the _SimpleAuth/config.yml_ file on the _plugins_ directory once | Configuration | Type | Default | Description | | :---: | :---: | :---: | :--- | -| timeout | integer | 60 | Unauthenticated players will be kicked after this period of time. Set it to "false" to disable. | +| timeout | integer | 60 | Unauthenticated players will be kicked after this period of time. Set it to 0 or -1 to disable. | forceSingleSession | boolean | true | New players won't kick an authenticated player if using the same name. | | minPasswordLength | integer | 6 | Minimum length of the register password. | | blockAfterFail | integer | 6 | Block clients after several failed attempts | diff --git a/resources/config.yml b/resources/config.yml index 15d17ab..6fcd89e 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -32,5 +32,5 @@ disableRegister: false #If enabled, will set all the permissions for simleauth.command.login to false disableLogin: false -#Number of seconds to wait for a player to be authenticated. If false, disables the timeout +#Number of seconds to wait for a player to be authenticated. If 0 or -1, disables the timeout authenticateTimeout: 60 diff --git a/src/SimpleAuth/EventListener.php b/src/SimpleAuth/EventListener.php index 7a2735f..0063ef4 100644 --- a/src/SimpleAuth/EventListener.php +++ b/src/SimpleAuth/EventListener.php @@ -58,7 +58,7 @@ public function onPlayerJoin(PlayerJoinEvent $event){ } $this->plugin->deauthenticatePlayer($event->getPlayer()); $timer = $this->plugin->getConfig()->get("authenticateTimeout"); - if($timer !== false){ + if($timer and $timer > 0){ $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new TimeoutTask($this->plugin,$event->getPlayer()),$timer * 20); } }