当前位置: 首页>>代码示例>>PHP>>正文


PHP Binary::writeInt方法代码示例

本文整理汇总了PHP中pocketmine\utils\Binary::writeInt方法的典型用法代码示例。如果您正苦于以下问题:PHP Binary::writeInt方法的具体用法?PHP Binary::writeInt怎么用?PHP Binary::writeInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\utils\Binary的用法示例。


在下文中一共展示了Binary::writeInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 public function handle($address, $port, $packet)
 {
     $offset = 2;
     $packetType = ord($packet[$offset++]);
     $sessionID = Binary::readInt(substr($packet, $offset, 4));
     $offset += 4;
     $payload = substr($packet, $offset);
     switch ($packetType) {
         case self::HANDSHAKE:
             //Handshake
             $reply = chr(self::HANDSHAKE);
             $reply .= Binary::writeInt($sessionID);
             $reply .= self::getTokenString($this->token, $address) . "";
             $this->server->getNetwork()->sendPacket($address, $port, $reply);
             break;
         case self::STATISTICS:
             //Stat
             $token = Binary::readInt(substr($payload, 0, 4));
             if ($token !== self::getTokenString($this->token, $address) and $token !== self::getTokenString($this->lastToken, $address)) {
                 break;
             }
             $reply = chr(self::STATISTICS);
             $reply .= Binary::writeInt($sessionID);
             if ($this->timeout < microtime(true)) {
                 $this->regenerateInfo();
             }
             if (strlen($payload) === 8) {
                 $reply .= $this->longData;
             } else {
                 $reply .= $this->shortData;
             }
             $this->server->getNetwork()->sendPacket($address, $port, $reply);
             break;
     }
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:35,代码来源:QueryHandler.php

示例2: readChunk

 public function readChunk($x, $z, $generate = true, $forward = false)
 {
     $index = self::getChunkOffset($x, $z);
     if ($index < 0 or $index >= 4096) {
         return null;
     }
     $this->lastUsed = time();
     if (!$this->isChunkGenerated($index)) {
         if ($generate === true) {
             //Allocate space
             $this->locationTable[$index][0] = ++$this->lastSector;
             $this->locationTable[$index][1] = 1;
             fseek($this->filePointer, $this->locationTable[$index][0] << 12);
             fwrite($this->filePointer, str_pad(Binary::writeInt(-1) . chr(self::COMPRESSION_ZLIB), 4096, "", STR_PAD_RIGHT));
             $this->writeLocationIndex($index);
         } else {
             return null;
         }
     }
     fseek($this->filePointer, $this->locationTable[$index][0] << 12);
     $length = Binary::readInt(fread($this->filePointer, 4));
     $compression = ord(fgetc($this->filePointer));
     if ($length <= 0 or $length >= self::MAX_SECTOR_LENGTH) {
         //Not yet generated / corrupted
         if ($length >= self::MAX_SECTOR_LENGTH) {
             $this->locationTable[$index][0] = ++$this->lastSector;
             $this->locationTable[$index][1] = 1;
             MainLogger::getLogger()->error("Corrupted chunk header detected");
         }
         $this->generateChunk($x, $z);
         fseek($this->filePointer, $this->locationTable[$index][0] << 12);
         $length = Binary::readInt(fread($this->filePointer, 4));
         $compression = ord(fgetc($this->filePointer));
     }
     if ($length > $this->locationTable[$index][1] << 12) {
         //Invalid chunk, bigger than defined number of sectors
         MainLogger::getLogger()->error("Corrupted bigger chunk detected");
         $this->locationTable[$index][1] = $length >> 12;
         $this->writeLocationIndex($index);
     } elseif ($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP) {
         MainLogger::getLogger()->error("Invalid compression type");
         return null;
     }
     $chunk = Chunk::fromBinary(fread($this->filePointer, $length - 1), $this->levelProvider);
     if ($chunk instanceof Chunk) {
         return $chunk;
     } elseif ($forward === false) {
         MainLogger::getLogger()->error("Corrupted chunk detected");
         $this->generateChunk($x, $z);
         return $this->readChunk($x, $z, $generate, true);
     } else {
         return null;
     }
 }
开发者ID:hlogeon,项目名称:PocketMineJs-MP,代码行数:54,代码来源:RegionLoader.php

示例3: __construct

 public function __construct($level, CompoundTag $nbt = null)
 {
     if ($nbt === null) {
         $this->provider = $level;
         $this->nbt = new CompoundTag("Level", []);
         return;
     }
     $this->nbt = $nbt;
     if (!isset($this->nbt->Entities) or !$this->nbt->Entities instanceof ListTag) {
         $this->nbt->Entities = new ListTag("Entities", []);
         $this->nbt->Entities->setTagType(NBT::TAG_Compound);
     }
     if (!isset($this->nbt->TileEntities) or !$this->nbt->TileEntities instanceof ListTag) {
         $this->nbt->TileEntities = new ListTag("TileEntities", []);
         $this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
     }
     if (!isset($this->nbt->TileTicks) or !$this->nbt->TileTicks instanceof ListTag) {
         $this->nbt->TileTicks = new ListTag("TileTicks", []);
         $this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
     }
     if (!isset($this->nbt->Sections) or !$this->nbt->Sections instanceof ListTag) {
         $this->nbt->Sections = new ListTag("Sections", []);
         $this->nbt->Sections->setTagType(NBT::TAG_Compound);
     }
     if (!isset($this->nbt->BiomeColors) or !$this->nbt->BiomeColors instanceof IntArrayTag) {
         $this->nbt->BiomeColors = new IntArrayTag("BiomeColors", array_fill(0, 256, 0));
     }
     if (!isset($this->nbt->HeightMap) or !$this->nbt->HeightMap instanceof IntArrayTag) {
         $this->nbt->HeightMap = new IntArrayTag("HeightMap", array_fill(0, 256, 0));
     }
     $sections = [];
     foreach ($this->nbt->Sections as $section) {
         if ($section instanceof CompoundTag) {
             $y = (int) $section["Y"];
             if ($y < 8) {
                 $sections[$y] = new ChunkSection($section);
             }
         }
     }
     for ($y = 0; $y < 8; ++$y) {
         if (!isset($sections[$y])) {
             $sections[$y] = new EmptyChunkSection($y);
         }
     }
     $extraData = [];
     if (!isset($this->nbt->ExtraData) or !$this->nbt->ExtraData instanceof ByteArrayTag) {
         $this->nbt->ExtraData = new ByteArrayTag("ExtraData", Binary::writeInt(0));
     } else {
         $stream = new BinaryStream($this->nbt->ExtraData->getValue());
         $count = $stream->getInt();
         for ($i = 0; $i < $count; ++$i) {
             $key = $stream->getInt();
             $extraData[$key] = $stream->getShort();
         }
     }
     parent::__construct($level, (int) $this->nbt["xPos"], (int) $this->nbt["zPos"], $sections, $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
     if (isset($this->nbt->Biomes)) {
         $this->checkOldBiomes($this->nbt->Biomes->getValue());
         unset($this->nbt->Biomes);
     }
     unset($this->nbt->Sections, $this->nbt->ExtraData);
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:62,代码来源:Chunk.php

示例4: putInt

 public function putInt($v)
 {
     $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Binary::writeInt($v) : Binary::writeLInt($v);
 }
开发者ID:ianju,项目名称:PocketMine-MP,代码行数:4,代码来源:NBT.php

示例5: saveChunk

 public function saveChunk($X, $Z, $force = false)
 {
     $X = (int) $X;
     $Z = (int) $Z;
     if (!$this->isChunkLoaded($X, $Z)) {
         return false;
     }
     $index = self::getIndex($X, $Z);
     if ($force !== true and (!isset($this->chunkChange[$index]) or $this->chunkChange[$index][-1] === false)) {
         //No changes in chunk
         return true;
     }
     $path = $this->getChunkPath($X, $Z);
     if (!file_exists(dirname($path))) {
         @mkdir(dirname($path), 0755);
     }
     $bitmap = 0;
     $this->cleanChunk($X, $Z);
     for ($Y = 0; $Y < 8; ++$Y) {
         if ($this->chunks[$index][$Y] !== false and (isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0 or !$this->isMiniChunkEmpty($X, $Z, $Y))) {
             $bitmap |= 1 << $Y;
         } else {
             $this->chunks[$index][$Y] = false;
         }
         $this->chunkChange[$index][$Y] = 0;
     }
     $this->chunkInfo[$index][0] = $bitmap;
     $this->chunkChange[$index][-1] = false;
     $chunk = "";
     $chunk .= chr($bitmap);
     $chunk .= Binary::writeInt($this->chunkInfo[$index][1]);
     $namedtag = new NBT(NBT::BIG_ENDIAN);
     $namedtag->setData($this->chunkInfo[$index][2]);
     $namedtag = $namedtag->write();
     $chunk .= Binary::writeInt(strlen($namedtag)) . $namedtag;
     $chunk .= $this->chunkInfo[$index][3];
     //biomes
     for ($Y = 0; $Y < 8; ++$Y) {
         $t = 1 << $Y;
         if (($bitmap & $t) === $t) {
             $chunk .= $this->chunks[$index][$Y];
         }
     }
     file_put_contents($path, zlib_encode($chunk, self::ZLIB_ENCODING, self::ZLIB_LEVEL));
     return true;
 }
开发者ID:rryy,项目名称:PocketMine-MP,代码行数:46,代码来源:LevelFormat.php

示例6: toFastBinary

 public function toFastBinary()
 {
     $biomeColors = pack("N*", ...$this->getBiomeColorArray());
     $heightMap = pack("N*", ...$this->getHeightMapArray());
     return Binary::writeInt($this->x) . Binary::writeInt($this->z) . $this->getBlockIdArray() . $this->getBlockDataArray() . $this->getBlockSkyLightArray() . $this->getBlockLightArray() . $this->getBiomeIdArray() . $biomeColors . $heightMap . chr(($this->isPopulated() ? 1 << 1 : 0) + ($this->isGenerated() ? 1 : 0));
 }
开发者ID:TylerGames,项目名称:PocketMine-MP,代码行数:6,代码来源:Chunk.php

示例7: batchPackets

 /**
  * Broadcasts a list of packets in a batch to a list of players
  *
  * @param Player[]            $players
  * @param DataPacket[]|string $packets
  * @param bool                 $forceSync
  */
 public function batchPackets(array $players, array $packets, $forceSync = true)
 {
     $str = "";
     foreach ($packets as $p) {
         if ($p instanceof DataPacket) {
             if (!$p->isEncoded) {
                 $p->encode();
             }
             $str .= Binary::writeInt(strlen($p->buffer)) . $p->buffer;
         } else {
             $str .= Binary::writeInt(strlen($p)) . $p;
         }
     }
     $targets = [];
     foreach ($players as $p) {
         $targets[] = $this->identifiers[spl_object_hash($p)];
     }
     $this->broadcastPacketsCallback(zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets);
 }
开发者ID:RedstoneAlmeida,项目名称:Steadfast2,代码行数:26,代码来源:Server.php

示例8: batchPackets

 /**
  * Broadcasts a list of packets in a batch to a list of players
  *
  * @param Player[]            $players
  * @param DataPacket[]|string $packets
  * @param bool                 $forceSync
  * @param int                 $channel
  */
 public function batchPackets(array $players, array $packets, $forceSync = false, $channel = 0)
 {
     Timings::$playerNetworkTimer->startTiming();
     $str = "";
     foreach ($packets as $p) {
         if ($p instanceof DataPacket) {
             if (!$p->isEncoded) {
                 $p->encode();
             }
             $str .= Binary::writeInt(strlen($p->buffer)) . $p->buffer;
         } else {
             $str .= Binary::writeInt(strlen($p)) . $p;
         }
     }
     $targets = [];
     foreach ($players as $p) {
         if ($p->isConnected()) {
             $targets[] = $this->identifiers[spl_object_hash($p)];
         }
     }
     if (!$forceSync and $this->networkCompressionAsync) {
         $task = new CompressBatchedTask($str, $targets, $this->networkCompressionLevel, $channel);
         $this->getScheduler()->scheduleAsyncTask($task);
     } else {
         $this->broadcastPacketsCallback(zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets, $channel);
     }
     Timings::$playerNetworkTimer->stopTiming();
 }
开发者ID:ZenaGamingsky,项目名称:PocketBox,代码行数:36,代码来源:Server.php

示例9: randomUUID

 public static function randomUUID()
 {
     return Utils::toUUID(Binary::writeInt(time()) . Binary::writeShort(getmypid()) . Binary::writeShort(getmyuid()) . Binary::writeInt(mt_rand(-0x7fffffff, 0x7fffffff)) . Binary::writeInt(mt_rand(-0x7fffffff, 0x7fffffff)), 2);
 }
开发者ID:JungHyun3459,项目名称:PocketMine-MP,代码行数:4,代码来源:Utils.php

示例10: compressName

 public static function compressName($name)
 {
     $name = strtolower($name);
     // [0-9a-z_]{3,16}
     $output = 0;
     for ($offset = 0; $offset < strlen($name); $offset++) {
         $order = ord(substr($name, $offset, 1));
         $zero = ord("0");
         $alpha = ord("a");
         $ord = $order - $zero;
         $alphaOrd = $order - $alpha;
         if (0 <= $ord and $ord <= 9) {
             $output += $ord;
         } elseif (0 <= $alphaOrd and $alphaOrd <= 25) {
             $output += $alphaOrd + 10;
         } elseif ($order === ord("_")) {
             $output += 36;
         }
         $output <<= 6;
     }
     $out = Binary::writeInt($output & 0xffffffff);
     $output >>= 32;
     $out = Binary::writeLong($output) . $out;
     return $out;
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:25,代码来源:Main.php

示例11: putInt

 public function putInt($v, bool $network = false)
 {
     if ($network === true) {
         $this->buffer .= Binary::writeVarInt($v);
     } else {
         $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Binary::writeInt($v) : Binary::writeLInt($v);
     }
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:8,代码来源:NBT.php

示例12: receiveChunk

 protected function receiveChunk($levelID, FullChunk $chunk)
 {
     if (($level = $this->server->getLevel($levelID)) instanceof Level) {
         $level->generateChunkCallback($chunk->getX(), $chunk->getZ(), $chunk);
     } else {
         $buffer = chr(GenerationManager::PACKET_CLOSE_LEVEL) . Binary::writeInt($levelID);
         $this->generationThread->pushMainToThreadPacket($buffer);
     }
 }
开发者ID:rryy,项目名称:PocketMine-MP,代码行数:9,代码来源:GenerationRequestManager.php

示例13: writePacket

 public function writePacket($data)
 {
     @socket_write($this->socket->getSocket(), Binary::writeInt(strlen($data)) . $data);
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:4,代码来源:ServerConnection.php

示例14: appendInt

 public function appendInt($v)
 {
     $this->buffer .= Binary::writeInt($v);
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:4,代码来源:StringWriter.php

示例15: sendChunk

 public function sendChunk($levelID, FullChunk $chunk)
 {
     $binary = chr(self::PACKET_SEND_CHUNK) . Binary::writeInt($levelID) . chr(strlen($class = get_class($chunk))) . $class . $chunk->toBinary();
     $this->thread->pushThreadToMainPacket($binary);
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:5,代码来源:GenerationManager.php


注:本文中的pocketmine\utils\Binary::writeInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。