/** * Get the encoded contents of the packet (minus packetID/length) * @return String */ protected function encodeContents() { $serverIDEncoded = StringType::write($this->serverID); $encodedPublicKey = base64_decode($this->getPublicKey()); $publicKeyLength = VarInt::writeUnsignedVarInt(strlen($encodedPublicKey)); $encodedToken = $this->getToken(); $tokenLength = VarInt::writeUnsignedVarInt(strlen($encodedToken)); return $serverIDEncoded->getEncoded() . $publicKeyLength->getEncoded() . $encodedPublicKey . $tokenLength->getEncoded() . $encodedToken; }
/** * Get the encoded contents of the packet (minus packetID/length) * @return String */ protected function encodeContents() { return StringType::write($this->reasonJSON)->getEncoded(); }
/** * Get the encoded contents of the packet (minus packetID/length) * @return String */ protected function encodeContents() { $payload = ['version' => ['name' => $this->version, 'protocol' => $this->protocol], 'players' => ['max' => $this->max_players, 'online' => $this->online_count, 'sample' => $this->online_players], 'description' => ['text' => $this->description]]; if ($this->favicon !== null) { $payload['favicon'] = $this->favicon; } $jsonString = utf8_encode(json_encode($payload)); return StringType::write($jsonString)->getEncoded(); }
/** * Parse the raw data into the packet * @param $data String the raw data to parse (minus packet ID and packet length */ public function fromRawData($data) { $username = StringType::read($data); $this->setUsername($username->getValue()); }