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

Added login timeout #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 |
Expand Down
5 changes: 2 additions & 3 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +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
#TODO
authenticateTimeout: 120
#Number of seconds to wait for a player to be authenticated. If 0 or -1, disables the timeout
authenticateTimeout: 60
3 changes: 2 additions & 1 deletion resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ login:
error:
password: "Incorrect password!"
registered: "This account is not registered."
block: "Too many tries!"
block: "Too many tries!"
timeout: "Login timer expired!"
5 changes: 5 additions & 0 deletions src/SimpleAuth/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -56,6 +57,10 @@ public function onPlayerJoin(PlayerJoinEvent $event){
}
}
$this->plugin->deauthenticatePlayer($event->getPlayer());
$timer = $this->plugin->getConfig()->get("authenticateTimeout");
if($timer and $timer > 0){
$this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new TimeoutTask($this->plugin,$event->getPlayer()),$timer * 20);
}
}

/**
Expand Down
55 changes: 55 additions & 0 deletions src/SimpleAuth/task/TimeoutTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* SimpleAuth plugin for PocketMine-MP
* Copyright (C) 2015 PocketMine Team <https://github.com/PocketMine/SimpleAuth>
*
* 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"));
}
}
}
}