mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Network: add ability to tick sessions
moved responsibility for login timeout checks to NetworkSession instead of Server
This commit is contained in:
parent
e43496e7e4
commit
10ba3d6359
@ -2375,12 +2375,12 @@ class Server{
|
|||||||
$p->sendDataPacket($pk);
|
$p->sendDataPacket($pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkTickUpdates(int $currentTick, float $tickTime) : void{
|
private function checkTickUpdates(int $currentTick) : void{
|
||||||
foreach($this->players as $p){
|
if($this->alwaysTickPlayers){
|
||||||
if(!$p->loggedIn and ($tickTime - $p->creationTime) >= 10){
|
foreach($this->players as $p){
|
||||||
$p->close("", "Login timeout");
|
if($p->spawned){
|
||||||
}elseif($this->alwaysTickPlayers and $p->spawned){
|
$p->onUpdate($currentTick);
|
||||||
$p->onUpdate($currentTick);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2537,7 +2537,7 @@ class Server{
|
|||||||
++$this->tickCounter;
|
++$this->tickCounter;
|
||||||
|
|
||||||
Timings::$connectionTimer->startTiming();
|
Timings::$connectionTimer->startTiming();
|
||||||
$this->network->tickInterfaces();
|
$this->network->tick();
|
||||||
Timings::$connectionTimer->stopTiming();
|
Timings::$connectionTimer->stopTiming();
|
||||||
|
|
||||||
Timings::$schedulerTimer->startTiming();
|
Timings::$schedulerTimer->startTiming();
|
||||||
@ -2548,7 +2548,7 @@ class Server{
|
|||||||
$this->asyncPool->collectTasks();
|
$this->asyncPool->collectTasks();
|
||||||
Timings::$schedulerAsyncTimer->stopTiming();
|
Timings::$schedulerAsyncTimer->stopTiming();
|
||||||
|
|
||||||
$this->checkTickUpdates($this->tickCounter, $tickTime);
|
$this->checkTickUpdates($this->tickCounter);
|
||||||
|
|
||||||
if(($this->tickCounter % 20) === 0){
|
if(($this->tickCounter % 20) === 0){
|
||||||
if($this->doTitleTick){
|
if($this->doTitleTick){
|
||||||
|
@ -29,6 +29,7 @@ namespace pocketmine\network;
|
|||||||
use pocketmine\event\server\NetworkInterfaceCrashEvent;
|
use pocketmine\event\server\NetworkInterfaceCrashEvent;
|
||||||
use pocketmine\event\server\NetworkInterfaceRegisterEvent;
|
use pocketmine\event\server\NetworkInterfaceRegisterEvent;
|
||||||
use pocketmine\event\server\NetworkInterfaceUnregisterEvent;
|
use pocketmine\event\server\NetworkInterfaceUnregisterEvent;
|
||||||
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
use pocketmine\network\mcpe\protocol\PacketPool;
|
use pocketmine\network\mcpe\protocol\PacketPool;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
|
|
||||||
@ -48,6 +49,9 @@ class Network{
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
|
/** @var NetworkSession[] */
|
||||||
|
private $updateSessions = [];
|
||||||
|
|
||||||
public function __construct(Server $server){
|
public function __construct(Server $server){
|
||||||
PacketPool::init();
|
PacketPool::init();
|
||||||
|
|
||||||
@ -80,7 +84,7 @@ class Network{
|
|||||||
return $this->interfaces;
|
return $this->interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tickInterfaces() : void{
|
public function tick() : void{
|
||||||
foreach($this->interfaces as $interface){
|
foreach($this->interfaces as $interface){
|
||||||
try{
|
try{
|
||||||
$interface->tick();
|
$interface->tick();
|
||||||
@ -97,6 +101,12 @@ class Network{
|
|||||||
$logger->critical($this->server->getLanguage()->translateString("pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
|
$logger->critical($this->server->getLanguage()->translateString("pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($this->updateSessions as $k => $session){
|
||||||
|
if(!$session->isConnected() or !$session->tick()){
|
||||||
|
unset($this->updateSessions[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,4 +193,8 @@ class Network{
|
|||||||
$interface->unblockAddress($address);
|
$interface->unblockAddress($address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scheduleSessionTick(NetworkSession $session) : void{
|
||||||
|
$this->updateSessions[spl_object_hash($session)] = $session;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ class NetworkSession{
|
|||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $connected = true;
|
private $connected = true;
|
||||||
|
/** @var int */
|
||||||
|
private $connectTime;
|
||||||
|
|
||||||
/** @var NetworkCipher */
|
/** @var NetworkCipher */
|
||||||
private $cipher;
|
private $cipher;
|
||||||
@ -72,6 +74,9 @@ class NetworkSession{
|
|||||||
$this->ip = $ip;
|
$this->ip = $ip;
|
||||||
$this->port = $port;
|
$this->port = $port;
|
||||||
|
|
||||||
|
$this->connectTime = time();
|
||||||
|
$this->server->getNetwork()->scheduleSessionTick($this);
|
||||||
|
|
||||||
//TODO: this should happen later in the login sequence
|
//TODO: this should happen later in the login sequence
|
||||||
$this->createPlayer();
|
$this->createPlayer();
|
||||||
|
|
||||||
@ -328,4 +333,18 @@ class NetworkSession{
|
|||||||
public function onRespawn() : void{
|
public function onRespawn() : void{
|
||||||
$this->setHandler(new SimpleSessionHandler($this->player));
|
$this->setHandler(new SimpleSessionHandler($this->player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tick() : bool{
|
||||||
|
if($this->handler instanceof LoginSessionHandler){
|
||||||
|
if(time() >= $this->connectTime + 10){
|
||||||
|
$this->disconnect("Login timeout");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true; //keep ticking until timeout
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: more stuff on tick
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user