backport a753c1342: Clean up Query cache handling, remove useless timeouts

the timeout was entirely useless, because:
- when shorter than 25.6 seconds (512 ticks) it would cause caches to be needlessly destroyed and regenerated
- when longer than 25.6 seconds, just made outdated caches persist for longer, even after the query info was regenerated.

This now uses a mark-dirty model to deal with caches, which means that plugin modifications to the query data will be reflected immediately, regardless of when they are made. Previously, modifying the result of Server->getQueryInformation() would have inconsistent results.
This commit is contained in:
Dylan K. Taylor
2019-03-24 17:42:41 +00:00
parent dbf4054b1f
commit 60b183b0d9
3 changed files with 36 additions and 33 deletions

View File

@@ -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;