mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-25 12:54:03 +00:00
Merge branch 'stable' into next-minor
This commit is contained in:
commit
5a17a0d1aa
@ -1720,7 +1720,7 @@ class Server{
|
||||
|
||||
register_shutdown_function([$this, "crashDump"]);
|
||||
|
||||
$this->queryRegenerateTask = new QueryRegenerateEvent($this, 5);
|
||||
$this->queryRegenerateTask = new QueryRegenerateEvent($this);
|
||||
|
||||
$this->pluginManager->loadPlugins($this->pluginPath);
|
||||
|
||||
@ -2587,17 +2587,12 @@ class Server{
|
||||
$this->currentTPS = 20;
|
||||
$this->currentUse = 0;
|
||||
|
||||
($this->queryRegenerateTask = new QueryRegenerateEvent($this))->call();
|
||||
|
||||
$this->network->updateName();
|
||||
$this->network->resetStatistics();
|
||||
}
|
||||
|
||||
if(($this->tickCounter & 0b111111111) === 0){
|
||||
($this->queryRegenerateTask = new QueryRegenerateEvent($this, 5))->call();
|
||||
if($this->queryHandler !== null){
|
||||
$this->queryHandler->regenerateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
if($this->autoSave and ++$this->autoSaveTicker >= $this->autoSaveTicks){
|
||||
$this->autoSaveTicker = 0;
|
||||
$this->getLogger()->debug("[Auto Save] Saving worlds...");
|
||||
|
@ -35,8 +35,6 @@ use function substr;
|
||||
class QueryRegenerateEvent extends ServerEvent{
|
||||
public const GAME_ID = "MINECRAFTPE";
|
||||
|
||||
/** @var int */
|
||||
private $timeout;
|
||||
/** @var string */
|
||||
private $serverName;
|
||||
/** @var bool */
|
||||
@ -68,13 +66,16 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
/** @var array */
|
||||
private $extraData = [];
|
||||
|
||||
/** @var string|null */
|
||||
private $longQueryCache = null;
|
||||
/** @var string|null */
|
||||
private $shortQueryCache = null;
|
||||
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function __construct(Server $server, int $timeout = 5){
|
||||
$this->timeout = $timeout;
|
||||
public function __construct(Server $server){
|
||||
$this->serverName = $server->getMotd();
|
||||
$this->listPlugins = $server->getProperty("settings.query-plugins", true);
|
||||
$this->plugins = $server->getPluginManager()->getPlugins();
|
||||
@ -98,19 +99,25 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the min. timeout for Query Regeneration
|
||||
* @deprecated
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTimeout() : int{
|
||||
return $this->timeout;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function setTimeout(int $timeout) : void{
|
||||
$this->timeout = $timeout;
|
||||
|
||||
}
|
||||
|
||||
private function destroyCache() : void{
|
||||
$this->longQueryCache = null;
|
||||
$this->shortQueryCache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,6 +132,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setServerName(string $serverName) : void{
|
||||
$this->serverName = $serverName;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,6 +147,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setListPlugins(bool $value) : void{
|
||||
$this->listPlugins = $value;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,6 +162,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setPlugins(array $plugins) : void{
|
||||
$this->plugins = $plugins;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,6 +177,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setPlayerList(array $players) : void{
|
||||
$this->players = $players;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,6 +192,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setPlayerCount(int $count) : void{
|
||||
$this->numPlayers = $count;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,6 +207,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setMaxPlayerCount(int $count) : void{
|
||||
$this->maxPlayers = $count;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,6 +222,7 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setWorld(string $world) : void{
|
||||
$this->map = $world;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,12 +239,16 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
*/
|
||||
public function setExtraData(array $extraData) : void{
|
||||
$this->extraData = $extraData;
|
||||
$this->destroyCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLongQuery() : string{
|
||||
if($this->longQueryCache !== null){
|
||||
return $this->longQueryCache;
|
||||
}
|
||||
$query = "";
|
||||
|
||||
$plist = $this->server_engine;
|
||||
@ -273,13 +291,13 @@ class QueryRegenerateEvent extends ServerEvent{
|
||||
}
|
||||
$query .= "\x00";
|
||||
|
||||
return $query;
|
||||
return $this->longQueryCache = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getShortQuery() : string{
|
||||
return $this->serverName . "\x00" . $this->gametype . "\x00" . $this->map . "\x00" . $this->numPlayers . "\x00" . $this->maxPlayers . "\x00" . Binary::writeLShort($this->port) . $this->ip . "\x00";
|
||||
return $this->shortQueryCache ?? ($this->shortQueryCache = $this->serverName . "\x00" . $this->gametype . "\x00" . $this->map . "\x00" . $this->numPlayers . "\x00" . $this->maxPlayers . "\x00" . Binary::writeLShort($this->port) . $this->ip . "\x00");
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ use pocketmine\utils\Binary;
|
||||
use function base64_encode;
|
||||
use function chr;
|
||||
use function hash;
|
||||
use function microtime;
|
||||
use function ord;
|
||||
use function random_bytes;
|
||||
use function strlen;
|
||||
@ -46,12 +45,6 @@ class QueryHandler{
|
||||
private $lastToken;
|
||||
/** @var string */
|
||||
private $token;
|
||||
/** @var string */
|
||||
private $longData;
|
||||
/** @var string */
|
||||
private $shortData;
|
||||
/** @var float */
|
||||
private $timeout;
|
||||
|
||||
public const HANDSHAKE = 9;
|
||||
public const STATISTICS = 0;
|
||||
@ -73,7 +66,6 @@ class QueryHandler{
|
||||
|
||||
$this->regenerateToken();
|
||||
$this->lastToken = $this->token;
|
||||
$this->regenerateInfo();
|
||||
$this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.server.query.running", [$addr, $port]));
|
||||
}
|
||||
|
||||
@ -82,11 +74,11 @@ class QueryHandler{
|
||||
$this->server->getLogger()->debug("[Query] $message");
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function regenerateInfo(){
|
||||
$ev = $this->server->getQueryInformation();
|
||||
$this->longData = $ev->getLongQuery();
|
||||
$this->shortData = $ev->getShortQuery();
|
||||
$this->timeout = microtime(true) + $ev->getTimeout();
|
||||
|
||||
}
|
||||
|
||||
public function regenerateToken(){
|
||||
@ -122,14 +114,10 @@ class QueryHandler{
|
||||
$reply = chr(self::STATISTICS);
|
||||
$reply .= Binary::writeInt($sessionID);
|
||||
|
||||
if($this->timeout < microtime(true)){
|
||||
$this->regenerateInfo();
|
||||
}
|
||||
|
||||
if(strlen($payload) === 8){
|
||||
$reply .= $this->longData;
|
||||
$reply .= $this->server->getQueryInformation()->getLongQuery();
|
||||
}else{
|
||||
$reply .= $this->shortData;
|
||||
$reply .= $this->server->getQueryInformation()->getShortQuery();
|
||||
}
|
||||
$interface->sendRawPacket($address, $port, $reply);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user