本文整理汇总了PHP中raklib\Binary::writeInt方法的典型用法代码示例。如果您正苦于以下问题:PHP Binary::writeInt方法的具体用法?PHP Binary::writeInt怎么用?PHP Binary::writeInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raklib\Binary
的用法示例。
在下文中一共展示了Binary::writeInt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toBinary
/**
* @param bool $internal
*
* @return string
*/
public function toBinary($internal = false)
{
$binary = chr($this->reliability << 5 | ($this->hasSplit ? 0b10000 : 0));
if ($internal) {
$binary .= Binary::writeInt(strlen($this->buffer));
$binary .= Binary::writeInt($this->identifierACK);
} else {
$binary .= Binary::writeShort(strlen($this->buffer) << 3);
}
if ($this->reliability === 2 or $this->reliability === 3 or $this->reliability === 4 or $this->reliability === 6 or $this->reliability === 7) {
$binary .= Binary::writeLTriad($this->messageIndex);
}
if ($this->reliability === 1 or $this->reliability === 3 or $this->reliability === 4 or $this->reliability === 7) {
$binary .= Binary::writeLTriad($this->orderIndex) . chr($this->orderChannel);
}
if ($this->hasSplit) {
$binary .= Binary::writeInt($this->splitCount) . Binary::writeShort($this->splitID) . Binary::writeInt($this->splitIndex);
}
return $binary . $this->buffer;
}
示例2: getChunkCacheFromData
/**
* @param $chunkX
* @param $chunkZ
* @param $payload
*
* @return DataPacket
*/
public static function getChunkCacheFromData($chunkX, $chunkZ, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
{
$pk = new FullChunkDataPacket();
$pk->chunkX = $chunkX;
$pk->chunkZ = $chunkZ;
$pk->order = $ordering;
$pk->data = $payload;
$pk->encode();
$batch = new BatchPacket();
$batch->payload = zlib_encode(Binary::writeInt(strlen($pk->getBuffer())) . $pk->getBuffer(), ZLIB_ENCODING_DEFLATE, Server::getInstance()->networkCompressionLevel);
$batch->encode();
$batch->isEncoded = true;
return $batch;
}
示例3: batchDataPacket
/**
* Batch a Data packet
*
* @param DataPacket $packet
*
* @return bool
*/
public function batchDataPacket(DataPacket $packet)
{
$str = "";
if ($packet instanceof DataPacket) {
if (!$packet->isEncoded) {
$packet->encode();
}
$str .= Binary::writeInt(strlen($packet->buffer)) . $packet->buffer;
} else {
$str .= Binary::writeInt(strlen($packet)) . $packet;
}
$pk = new BatchPacket();
$pk->payload = zlib_encode($str, ZLIB_ENCODING_DEFLATE, 7);
$pk->encode();
$pk->isEncoded = true;
$this->dataPacket($pk);
}
示例4: streamACK
protected function streamACK($identifier, $identifierACK)
{
$buffer = chr(RakLib::PACKET_ACK_NOTIFICATION) . chr(strlen($identifier)) . $identifier . Binary::writeInt($identifierACK);
$this->server->pushThreadToMainPacket($buffer);
}
示例5: putInt
protected function putInt($v)
{
$this->buffer .= Binary::writeInt($v);
}
示例6: saveChunkToDisk
public function saveChunkToDisk($x, $z, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
{
// When the payload of the chunk has been calculated it, save it if possible to save future CPU cycles
/** @var Player $player */
if (file_exists("chunk_cache/" . $this->getName() . "/" . $x . "_" . $z . ".dat")) {
$this->loadChunkFromDisk($x, $z);
return true;
}
$pk = new FullChunkDataPacket();
$pk->chunkX = $x;
$pk->chunkZ = $z;
$pk->order = $ordering;
$pk->data = $payload;
$pk->encode();
// all chunks are zlib_encoded, level is arbitrary but 6 is a good match between device CPU power needed
// and bandwidth
$data = zlib_encode(Binary::writeInt(strlen($pk->buffer)) . $pk->buffer, ZLIB_ENCODING_DEFLATE, 6);
$this->chunkCache[$x . ":" . $z] = $data;
if (!$this->server->getKatana()->getProperty("cache.save-to-disk", true)) {
return true;
}
file_put_contents("chunk_cache/" . $this->getName() . "/" . $x . "_" . $z . ".dat", $data);
return true;
}
示例7: requestChunkTask
public function requestChunkTask($x, $z)
{
$chunk = $this->getChunk($x, $z, false);
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk sent");
}
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write();
}
}
$extraData = new BinaryStream();
$extraData->putLInt(count($chunk->getBlockExtraDataArray()));
foreach ($chunk->getBlockExtraDataArray() as $key => $value) {
$extraData->putLInt($key);
$extraData->putLShort($value);
}
$ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . pack("C*", ...$chunk->getHeightMapArray()) . pack("N*", ...$chunk->getBiomeColorArray()) . $extraData->getBuffer() . $tiles;
$pk = new FullChunkDataPacket();
$pk->chunkX = $x;
$pk->chunkZ = $z;
$pk->order = FullChunkDataPacket::ORDER_COLUMNS;
$pk->data = $ordered;
$pk->encode();
$str = "";
$str .= Binary::writeInt(strlen($pk->buffer)) . $pk->buffer;
$this->getLevel()->chunkRequestCallback($x, $z, zlib_encode($str, ZLIB_ENCODING_DEFLATE, 7));
return null;
}
示例8: blockAddress
public function blockAddress($address, $timeout)
{
$buffer = chr(RakLib::PACKET_BLOCK_ADDRESS) . chr(strlen($address)) . $address . Binary::writeInt($timeout);
$this->server->pushMainToThreadPacket($buffer);
}
示例9: toBinary
/**
* @param bool $internal
*
* @return string
*/
public function toBinary($internal = false)
{
return chr($this->reliability << 5 | ($this->hasSplit ? 0b10000 : 0)) . ($internal ? Binary::writeInt(strlen($this->buffer)) . Binary::writeInt($this->identifierACK) : Binary::writeShort(strlen($this->buffer) << 3)) . ($this->reliability > 0 ? (($this->reliability >= 2 and $this->reliability !== 5) ? Binary::writeLTriad($this->messageIndex) : "") . (($this->reliability <= 4 and $this->reliability !== 2) ? Binary::writeLTriad($this->orderIndex) . chr($this->orderChannel) : "") : "") . ($this->hasSplit ? Binary::writeInt($this->splitCount) . Binary::writeShort($this->splitID) . Binary::writeInt($this->splitIndex) : "") . $this->buffer;
}
示例10: toBinary
/**
* @param bool $internal
*
* @return string
*/
public function toBinary($internal = false)
{
return chr($this->reliability << 5 | ($this->hasSplit ? 0b10000 : 0)) . ($internal ? Binary::writeInt(strlen($this->buffer)) . Binary::writeInt($this->identifierACK) : Binary::writeShort(strlen($this->buffer) << 3)) . ($this->reliability > PacketReliability::UNRELIABLE ? (($this->reliability >= PacketReliability::RELIABLE and $this->reliability !== PacketReliability::UNRELIABLE_WITH_ACK_RECEIPT) ? Binary::writeLTriad($this->messageIndex) : "") . (($this->reliability <= PacketReliability::RELIABLE_SEQUENCED and $this->reliability !== PacketReliability::RELIABLE) ? Binary::writeLTriad($this->orderIndex) . chr($this->orderChannel) : "") : "") . ($this->hasSplit ? Binary::writeInt($this->splitCount) . Binary::writeShort($this->splitID) . Binary::writeInt($this->splitIndex) : "") . $this->buffer;
}