本文整理汇总了PHP中raklib\Binary类的典型用法代码示例。如果您正苦于以下问题:PHP Binary类的具体用法?PHP Binary怎么用?PHP Binary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Binary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decode
public function decode()
{
parent::decode();
$this->clientID = Binary::readLong($this->get(8));
$this->session = Binary::readLong($this->get(8));
$this->unknown = $this->get(1);
}
示例2: decode
public function decode()
{
parent::decode();
$this->clientID = Binary::readLong($this->get(8));
$this->sendPing = Binary::readLong($this->get(8));
$this->useSecurity = \ord($this->get(1)) > 0;
}
示例3: decode
public function decode()
{
parent::decode();
$this->pingID = Binary::readLong($this->get(8));
$this->serverID = Binary::readLong($this->get(8));
$this->offset += 16;
//magic
$this->serverName = $this->getString();
}
示例4: decode
public function decode()
{
parent::decode();
$this->offset += 16;
//Magic
$this->getAddress($this->serverAddress, $this->serverPort);
$this->mtuSize = \unpack("n", $this->get(2))[1];
$this->clientID = Binary::readLong($this->get(8));
}
示例5: decode
public function decode()
{
parent::decode();
$this->offset += 16;
//Magic
$this->serverID = Binary::readLong($this->get(8));
$this->clientPort = unpack("n", $this->get(2))[1];
$this->mtuSize = unpack("n", $this->get(2))[1];
//server security
}
示例6: decode
public function decode()
{
parent::decode();
$this->offset += 16;
//Magic
$this->serverID = Binary::readLong($this->get(8));
\ord($this->get(1));
//security
$this->mtuSize = \unpack("n", $this->get(2))[1];
}
示例7: encode
public function encode()
{
parent::encode();
$this->putAddress($this->address, $this->port, 4);
$this->buffer .= pack("n", 0);
for ($i = 0; $i < 10; ++$i) {
$this->putAddress($this->systemAddresses[$i][0], $this->systemAddresses[$i][1], $this->systemAddresses[$i][2]);
}
$this->buffer .= Binary::writeLong($this->sendPing);
$this->buffer .= Binary::writeLong($this->sendPong);
}
示例8: decode
public function decode()
{
parent::decode();
$this->getAddress($this->address, $this->port);
for ($i = 0; $i < 10; ++$i) {
$this->getAddress($addr, $port, $version);
$this->systemAddresses[$i] = [$addr, $port, $version];
}
$this->sendPing = Binary::readLong($this->get(8));
$this->sendPong = Binary::readLong($this->get(8));
}
示例9: decode
public function decode()
{
parent::decode();
$this->cookie = $this->get(4);
$this->security = $this->get(1);
$this->port = unpack("n", $this->get(2))[1];
$this->dataArray0 = $this->get(ord($this->get(1)));
$this->dataArray = $this->getDataArray(9);
$this->timestamp = $this->get(2);
$this->session2 = Binary::readLong($this->get(8));
$this->session = Binary::readLong($this->get(8));
}
示例10: encode
public function encode()
{
parent::encode();
$this->buffer .= "?Wþ";
//cookie
$this->buffer .= "Í";
//security flags
$this->buffer .= pack("n", $this->port);
$this->putDataArray(["õÿÿõ", "ÿÿÿÿ", "ÿÿÿÿ", "ÿÿÿÿ", "ÿÿÿÿ", "ÿÿÿÿ", "ÿÿÿÿ", "ÿÿÿÿ", "ÿÿÿÿ", "ÿÿÿÿ"]);
$this->buffer .= "";
$this->buffer .= Binary::writeLong($this->session);
$this->buffer .= Binary::writeLong($this->session2);
}
示例11: encode
public function encode()
{
parent::encode();
$payload = "";
sort($this->packets, SORT_NUMERIC);
$count = count($this->packets);
$records = 0;
if ($count > 0) {
$pointer = 1;
$start = $this->packets[0];
$last = $this->packets[0];
while ($pointer < $count) {
$current = $this->packets[$pointer++];
$diff = $current - $last;
if ($diff === 1) {
$last = $current;
} elseif ($diff > 1) {
//Forget about duplicated packets (bad queues?)
if ($start === $last) {
$payload .= "";
$payload .= Binary::writeLTriad($start);
$start = $last = $current;
} else {
$payload .= "";
$payload .= Binary::writeLTriad($start);
$payload .= Binary::writeLTriad($last);
$start = $last = $current;
}
++$records;
}
}
if ($start === $last) {
$payload .= "";
$payload .= Binary::writeLTriad($start);
} else {
$payload .= "";
$payload .= Binary::writeLTriad($start);
$payload .= Binary::writeLTriad($last);
}
++$records;
}
$this->putShort($records);
$this->buffer .= $payload;
}
示例12: 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;
}
示例13: 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;
}
示例14: streamOpen
protected function streamOpen(Session $session)
{
$identifier = $session->getAddress() . ":" . $session->getPort();
$buffer = \chr(RakLib::PACKET_OPEN_SESSION) . \chr(\strlen($identifier)) . $identifier . \chr(\strlen($session->getAddress())) . $session->getAddress() . \pack("n", $session->getPort()) . Binary::writeLong($session->getID());
$this->server->pushThreadToMainPacket($buffer);
}
示例15: saveChunkToDisk
public function saveChunkToDisk($x, $z, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS)
{
/** @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();
$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;
}