예제 #1
0
 public function process()
 {
     if (count($this->identifiers) > 0) {
         foreach ($this->identifiers as $id => $player) {
             $player->handleACK($id);
         }
     }
     while (strlen($buffer = $this->thread->readThreadToMainPacket()) > 0) {
         $offset = 1;
         $pid = ord($buffer[0]);
         if ($pid === ServerManager::PACKET_SEND_PACKET) {
             $id = Binary::readInt(substr($buffer, $offset, 4));
             $offset += 4;
             if (isset($this->sessionsPlayers[$id])) {
                 $payload = substr($buffer, $offset);
                 try {
                     $this->handlePacket($this->sessionsPlayers[$id], $payload);
                 } catch (\Exception $e) {
                     if (\pocketmine\DEBUG > 1) {
                         $logger = $this->server->getLogger();
                         if ($logger instanceof MainLogger) {
                             $logger->debug("DesktopPacket 0x" . bin2hex($payload));
                             $logger->logException($e);
                         }
                     }
                 }
             }
         } elseif ($pid === ServerManager::PACKET_OPEN_SESSION) {
             $id = Binary::readInt(substr($buffer, $offset, 4));
             $offset += 4;
             if (isset($this->sessionsPlayers[$id])) {
                 continue;
             }
             $len = ord($buffer[$offset++]);
             $address = substr($buffer, $offset, $len);
             $offset += $len;
             $port = Binary::readShort(substr($buffer, $offset, 2));
             $identifier = "{$id}:{$address}:{$port}";
             $player = new DesktopPlayer($this, $identifier, $address, $port, $this->plugin);
             $this->sessions->attach($player, $id);
             $this->sessionsPlayers[$id] = $player;
             $this->plugin->getServer()->addPlayer($identifier, $player);
         } elseif ($pid === ServerManager::PACKET_CLOSE_SESSION) {
             $id = Binary::readInt(substr($buffer, $offset, 4));
             $offset += 4;
             $flag = Binary::readInt(substr($buffer, $offset, 4));
             if (isset($this->sessionsPlayers[$id])) {
                 if ($flag === 0) {
                     $this->close($this->sessionsPlayers[$id]);
                 } else {
                     $this->closeSession($id);
                 }
             }
         }
     }
     return true;
 }
예제 #2
0
 public function bigBrother_handleAuthentication(BigBrother $plugin, $username, $onlineMode)
 {
     if ($this->bigBrother_status === 0) {
         $this->bigBrother_username = $username;
         if ($onlineMode === true) {
             $pk = new EncryptionRequestPacket();
             $pk->serverID = "";
             $pk->publicKey = $plugin->getASN1PublicKey();
             $pk->verifyToken = $this->bigBrother_checkToken = Utils::getRandomBytes(4, false, true, $pk->publicKey);
             $this->putRawPacket($pk);
         } else {
             $task = new OnlineProfile($this->clientID, $this->bigBrother_username);
             $this->server->getScheduler()->scheduleAsyncTask($task);
         }
     }
 }
예제 #3
0
 public function bigBrother_processAuthentication(BigBrother $plugin, EncryptionResponsePacket $packet)
 {
     $this->bigBrother_secret = $plugin->decryptBinary($packet->sharedSecret);
     $token = $plugin->decryptBinary($packet->verifyToken);
     $this->interface->enableEncryption($this, $this->bigBrother_secret);
     if ($token !== $this->bigBrother_checkToken) {
         $this->close("", "Invalid check token");
     } else {
         $this->getAuthenticateOnline($this->bigBrother_username, Binary::sha1("" . $this->bigBrother_secret . $plugin->getASN1PublicKey()));
     }
 }