mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 12:27:51 +00:00
Added an event for handling duplicate logins (#2430)
This commit is contained in:
parent
535d4e2c9b
commit
653fa1213e
@ -58,6 +58,7 @@ use pocketmine\event\player\PlayerJoinEvent;
|
|||||||
use pocketmine\event\player\PlayerJumpEvent;
|
use pocketmine\event\player\PlayerJumpEvent;
|
||||||
use pocketmine\event\player\PlayerKickEvent;
|
use pocketmine\event\player\PlayerKickEvent;
|
||||||
use pocketmine\event\player\PlayerLoginEvent;
|
use pocketmine\event\player\PlayerLoginEvent;
|
||||||
|
use pocketmine\event\player\PlayerDuplicateLoginEvent;
|
||||||
use pocketmine\event\player\PlayerMoveEvent;
|
use pocketmine\event\player\PlayerMoveEvent;
|
||||||
use pocketmine\event\player\PlayerPreLoginEvent;
|
use pocketmine\event\player\PlayerPreLoginEvent;
|
||||||
use pocketmine\event\player\PlayerQuitEvent;
|
use pocketmine\event\player\PlayerQuitEvent;
|
||||||
@ -1787,11 +1788,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
foreach($this->server->getLoggedInPlayers() as $p){
|
foreach($this->server->getLoggedInPlayers() as $p){
|
||||||
if($p !== $this and ($p->iusername === $this->iusername or $this->getUniqueId()->equals($p->getUniqueId()))){
|
if($p !== $this and ($p->iusername === $this->iusername or $this->getUniqueId()->equals($p->getUniqueId()))){
|
||||||
if(!$p->kick("logged in from another location")){
|
$this->server->getPluginManager()->callEvent($ev = new PlayerDuplicateLoginEvent($this->networkSession, $p->networkSession));
|
||||||
$this->close($this->getLeaveMessage(), "Logged in from another location");
|
if($ev->isCancelled()){
|
||||||
|
$this->networkSession->disconnect($ev->getDisconnectMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$p->networkSession->disconnect($ev->getDisconnectMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
71
src/pocketmine/event/player/PlayerDuplicateLoginEvent.php
Normal file
71
src/pocketmine/event/player/PlayerDuplicateLoginEvent.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\event\player;
|
||||||
|
|
||||||
|
use pocketmine\event\Cancellable;
|
||||||
|
use pocketmine\event\Event;
|
||||||
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player connects with a username or UUID that is already used by another player on the server.
|
||||||
|
* If cancelled, the newly connecting session will be disconnected; otherwise, the existing player will be disconnected.
|
||||||
|
*/
|
||||||
|
class PlayerDuplicateLoginEvent extends Event implements Cancellable{
|
||||||
|
|
||||||
|
/** @var NetworkSession */
|
||||||
|
private $connectingSession;
|
||||||
|
/** @var NetworkSession */
|
||||||
|
private $existingSession;
|
||||||
|
/** @var string */
|
||||||
|
private $disconnectMessage = "Logged in from another location";
|
||||||
|
|
||||||
|
public function __construct(NetworkSession $connectingSession, NetworkSession $existingSession){
|
||||||
|
$this->connectingSession = $connectingSession;
|
||||||
|
$this->existingSession = $existingSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConnectingSession() : NetworkSession{
|
||||||
|
return $this->connectingSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExistingSession() : NetworkSession{
|
||||||
|
return $this->existingSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the message shown to the session which gets disconnected.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDisconnectMessage() : string{
|
||||||
|
return $this->disconnectMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
*/
|
||||||
|
public function setDisconnectMessage(string $message) : void{
|
||||||
|
$this->disconnectMessage = $message;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user