mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Avoid use of internal fields in BinaryStream
This commit is contained in:
parent
4a629e1a26
commit
f81bbd60e8
12
composer.lock
generated
12
composer.lock
generated
@ -233,16 +233,16 @@
|
||||
},
|
||||
{
|
||||
"name": "pocketmine/binaryutils",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pmmp/BinaryUtils.git",
|
||||
"reference": "925001c8eff97a36519b16bbd095964b0fc52772"
|
||||
"reference": "8c559e8c437aa56143e1a9231debf734b4de481c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pmmp/BinaryUtils/zipball/925001c8eff97a36519b16bbd095964b0fc52772",
|
||||
"reference": "925001c8eff97a36519b16bbd095964b0fc52772",
|
||||
"url": "https://api.github.com/repos/pmmp/BinaryUtils/zipball/8c559e8c437aa56143e1a9231debf734b4de481c",
|
||||
"reference": "8c559e8c437aa56143e1a9231debf734b4de481c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -260,10 +260,10 @@
|
||||
],
|
||||
"description": "Classes and methods for conveniently handling binary data",
|
||||
"support": {
|
||||
"source": "https://github.com/pmmp/BinaryUtils/tree/0.1.3",
|
||||
"source": "https://github.com/pmmp/BinaryUtils/tree/master",
|
||||
"issues": "https://github.com/pmmp/BinaryUtils/issues"
|
||||
},
|
||||
"time": "2018-12-30T12:17:51+00:00"
|
||||
"time": "2019-01-01T15:58:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pocketmine/math",
|
||||
|
@ -1900,7 +1900,7 @@ class Server{
|
||||
$stream->putPacket($packet);
|
||||
}
|
||||
|
||||
if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->buffer) < NetworkCompression::$THRESHOLD){
|
||||
if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->getBuffer()) < NetworkCompression::$THRESHOLD){
|
||||
foreach($targets as $target){
|
||||
foreach($ev->getPackets() as $pk){
|
||||
$target->addToSendBuffer($pk);
|
||||
@ -1929,17 +1929,18 @@ class Server{
|
||||
Timings::$playerNetworkSendCompressTimer->startTiming();
|
||||
|
||||
$compressionLevel = NetworkCompression::$LEVEL;
|
||||
if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->buffer) < NetworkCompression::$THRESHOLD){
|
||||
$buffer = $stream->getBuffer();
|
||||
if(NetworkCompression::$THRESHOLD < 0 or strlen($buffer) < NetworkCompression::$THRESHOLD){
|
||||
$compressionLevel = 0; //Do not compress packets under the threshold
|
||||
$forceSync = true;
|
||||
}
|
||||
|
||||
$promise = new CompressBatchPromise();
|
||||
if(!$forceSync and $this->networkCompressionAsync){
|
||||
$task = new CompressBatchTask($stream, $compressionLevel, $promise);
|
||||
$task = new CompressBatchTask($buffer, $compressionLevel, $promise);
|
||||
$this->asyncPool->submitTask($task);
|
||||
}else{
|
||||
$promise->resolve(NetworkCompression::compress($stream->buffer, $compressionLevel));
|
||||
$promise->resolve(NetworkCompression::compress($buffer, $compressionLevel));
|
||||
}
|
||||
|
||||
return $promise;
|
||||
|
@ -105,7 +105,7 @@ class CraftingManager{
|
||||
$batch->putPacket($pk);
|
||||
|
||||
$this->craftingDataCache = new CompressBatchPromise();
|
||||
$this->craftingDataCache->resolve(NetworkCompression::compress($batch->buffer));
|
||||
$this->craftingDataCache->resolve(NetworkCompression::compress($batch->getBuffer()));
|
||||
|
||||
Timings::$craftingDataCacheRebuildTimer->stopTiming();
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class ChunkRequestTask extends AsyncTask{
|
||||
$stream = new PacketStream();
|
||||
$stream->putPacket($pk);
|
||||
|
||||
$this->setResult(NetworkCompression::compress($stream->buffer, $this->compressionLevel));
|
||||
$this->setResult(NetworkCompression::compress($stream->getBuffer(), $this->compressionLevel));
|
||||
}
|
||||
|
||||
public function onCompletion() : void{
|
||||
|
@ -31,12 +31,12 @@ class CompressBatchTask extends AsyncTask{
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* @param PacketStream $stream
|
||||
* @param string $data
|
||||
* @param int $compressionLevel
|
||||
* @param CompressBatchPromise $promise
|
||||
*/
|
||||
public function __construct(PacketStream $stream, int $compressionLevel, CompressBatchPromise $promise){
|
||||
$this->data = $stream->buffer;
|
||||
public function __construct(string $data, int $compressionLevel, CompressBatchPromise $promise){
|
||||
$this->data = $data;
|
||||
$this->level = $compressionLevel;
|
||||
$this->storeLocal($promise);
|
||||
}
|
||||
|
@ -198,14 +198,14 @@ class NetworkSession{
|
||||
|
||||
$packet->decode();
|
||||
if(!$packet->feof() and !$packet->mayHaveUnreadBytes()){
|
||||
$remains = substr($packet->buffer, $packet->offset);
|
||||
$remains = substr($packet->getBuffer(), $packet->getOffset());
|
||||
$this->server->getLogger()->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": 0x" . bin2hex($remains));
|
||||
}
|
||||
|
||||
$ev = new DataPacketReceiveEvent($this->player, $packet);
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled() and !$packet->handle($this->handler)){
|
||||
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer));
|
||||
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->getBuffer()));
|
||||
}
|
||||
|
||||
$timings->stopTiming();
|
||||
|
@ -32,7 +32,7 @@ class PacketStream extends NetworkBinaryStream{
|
||||
if(!$packet->isEncoded){
|
||||
$packet->encode();
|
||||
}
|
||||
$this->putString($packet->buffer);
|
||||
$this->putString($packet->getBuffer());
|
||||
}
|
||||
|
||||
public function getPacket() : DataPacket{
|
||||
|
@ -62,7 +62,7 @@ abstract class DataPacket extends NetworkBinaryStream{
|
||||
}
|
||||
|
||||
public function decode() : void{
|
||||
$this->offset = 0;
|
||||
$this->rewind();
|
||||
$this->decodeHeader();
|
||||
$this->decodePayload();
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ class StartGamePacket extends DataPacket{
|
||||
$stream->putString($v["name"]);
|
||||
$stream->putLShort($v["data"]);
|
||||
}
|
||||
self::$runtimeIdTable = $stream->buffer;
|
||||
self::$runtimeIdTable = $stream->getBuffer();
|
||||
}
|
||||
$this->put(self::$runtimeIdTable);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user