writeLShort() public static method

Writes a 16-bit signed/unsigned little-endian number
public static writeLShort ( $value ) : string
$value
return string
Exemplo n.º 1
0
 public function putLShort($v)
 {
     $this->buffer .= Binary::writeLShort($v);
 }
Exemplo n.º 2
0
 public function putShort($v)
 {
     $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Binary::writeShort($v) : Binary::writeLShort($v);
 }
Exemplo n.º 3
0
 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->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 (strlen($payload) === 8) {
                 if ($this->timeout < microtime(true)) {
                     $this->regenerateInfo();
                 }
                 $reply .= $this->longData;
             } else {
                 $reply .= $this->server->getServerName() . "" . (($this->server->getGamemode() & 0x1) === 0 ? "SMP" : "CMP") . "" . ($this->server->getDefaultLevel() === null ? "unknown" : $this->server->getDefaultLevel()->getName()) . "" . count($this->server->getOnlinePlayers()) . "" . $this->server->getMaxPlayers() . "" . Binary::writeLShort($this->server->getPort()) . $this->server->getIp() . "";
             }
             $this->server->sendPacket($address, $port, $reply);
             break;
     }
 }
Exemplo n.º 4
0
 public function getShortQuery()
 {
     return $this->serverName . "" . $this->gametype . "" . $this->map . "" . $this->numPlayers . "" . $this->maxPlayers . "" . Binary::writeLShort($this->port) . $this->ip . "";
 }
Exemplo n.º 5
0
 public function putString($string)
 {
     $this->buffer .= Binary::writeLShort(strlen($string));
     $this->buffer .= $string;
 }