diff --git a/src/network/Network.php b/src/network/Network.php index fc65e3aca..2502809b1 100644 --- a/src/network/Network.php +++ b/src/network/Network.php @@ -191,7 +191,7 @@ class Network{ } public function processRawPacket(AdvancedNetworkInterface $interface, string $address, int $port, string $packet) : void{ - if(isset($this->bannedIps[$address]) and time() < $this->bannedIps[$address]){ + if(isset($this->bannedIps[$address]) && time() < $this->bannedIps[$address]){ $this->logger->debug("Dropped raw packet from banned address $address $port"); return; } diff --git a/src/network/mcpe/InventoryManager.php b/src/network/mcpe/InventoryManager.php index 2c3fff30c..e7e53b4d3 100644 --- a/src/network/mcpe/InventoryManager.php +++ b/src/network/mcpe/InventoryManager.php @@ -138,7 +138,7 @@ class InventoryManager{ public function onTransactionStart(InventoryTransaction $tx) : void{ foreach($tx->getActions() as $action){ - if($action instanceof SlotChangeAction and ($windowId = $this->getWindowId($action->getInventory())) !== null){ + if($action instanceof SlotChangeAction && ($windowId = $this->getWindowId($action->getInventory())) !== null){ //in some cases the inventory might not have a window ID, but still be referenced by a transaction (e.g. crafting grid changes), so we can't unconditionally record the change here or we might leak things $this->initiatedSlotChanges[$windowId][$action->getSlot()] = $action->getTargetItem(); } @@ -236,7 +236,7 @@ class InventoryManager{ if($windowId !== null){ $currentItem = $inventory->getItem($slot); $clientSideItem = $this->initiatedSlotChanges[$windowId][$slot] ?? null; - if($clientSideItem === null or !$clientSideItem->equalsExact($currentItem)){ + if($clientSideItem === null || !$clientSideItem->equalsExact($currentItem)){ $itemStackWrapper = ItemStackWrapper::legacy(TypeConverter::getInstance()->coreItemStackToNet($currentItem)); if($windowId === ContainerIds::OFFHAND){ //TODO: HACK! diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 66b77fbb3..3c97db45e 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -392,7 +392,7 @@ class NetworkSession{ $ev = new DataPacketReceiveEvent($this, $packet); $ev->call(); - if(!$ev->isCancelled() and ($this->handler === null or !$packet->handle($this->handler))){ + if(!$ev->isCancelled() && ($this->handler === null || !$packet->handle($this->handler))){ $this->logger->debug("Unhandled " . $packet->getName() . ": " . base64_encode($stream->getBuffer())); } }finally{ @@ -402,7 +402,7 @@ class NetworkSession{ public function sendDataPacket(ClientboundPacket $packet, bool $immediate = false) : bool{ //Basic safety restriction. TODO: improve this - if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){ + if(!$this->loggedIn && !$packet->canBeSentBeforeLogin()){ throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getDisplayName() . " too early"); } @@ -473,7 +473,7 @@ class NetworkSession{ }else{ $this->compressedQueue->enqueue($payload); $payload->onResolve(function(CompressBatchPromise $payload) : void{ - if($this->connected and $this->compressedQueue->bottom() === $payload){ + if($this->connected && $this->compressedQueue->bottom() === $payload){ $this->compressedQueue->dequeue(); //result unused $this->sendEncoded($payload->getResult()); @@ -507,7 +507,7 @@ class NetworkSession{ * @phpstan-param \Closure() : void $func */ private function tryDisconnect(\Closure $func, string $reason) : void{ - if($this->connected and !$this->disconnectGuard){ + if($this->connected && !$this->disconnectGuard){ $this->disconnectGuard = true; $func(); $this->disconnectGuard = false; @@ -586,7 +586,7 @@ class NetworkSession{ return; } if($error === null){ - if($authenticated and !($this->info instanceof XboxLivePlayerInfo)){ + if($authenticated && !($this->info instanceof XboxLivePlayerInfo)){ $error = "Expected XUID but none found"; }elseif($clientPubKey === null){ $error = "Missing client public key"; //failsafe @@ -633,7 +633,7 @@ class NetworkSession{ continue; } $info = $existingSession->getPlayerInfo(); - if($info !== null and ($info->getUsername() === $this->info->getUsername() or $info->getUuid()->equals($this->info->getUuid()))){ + if($info !== null && ($info->getUsername() === $this->info->getUsername() || $info->getUuid()->equals($this->info->getUuid()))){ if($kickForXUIDMismatch($info instanceof XboxLivePlayerInfo ? $info->getXuid() : "")){ return; } @@ -840,7 +840,7 @@ class NetworkSession{ public function syncAvailableCommands() : void{ $commandData = []; foreach($this->server->getCommandMap()->getCommands() as $name => $command){ - if(isset($commandData[$command->getName()]) or $command->getName() === "help" or !$command->testPermissionSilent($this->player)){ + if(isset($commandData[$command->getName()]) || $command->getName() === "help" || !$command->testPermissionSilent($this->player)){ continue; } @@ -920,7 +920,7 @@ class NetworkSession{ return; } $currentWorld = $this->player->getLocation()->getWorld(); - if($world !== $currentWorld or ($status = $this->player->getUsedChunkStatus($chunkX, $chunkZ)) === null){ + if($world !== $currentWorld || ($status = $this->player->getUsedChunkStatus($chunkX, $chunkZ)) === null){ $this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName()); return; } diff --git a/src/network/mcpe/auth/ProcessLoginTask.php b/src/network/mcpe/auth/ProcessLoginTask.php index 15cafe952..940dd8bad 100644 --- a/src/network/mcpe/auth/ProcessLoginTask.php +++ b/src/network/mcpe/auth/ProcessLoginTask.php @@ -174,11 +174,11 @@ class ProcessLoginTask extends AsyncTask{ } $time = time(); - if(isset($claims->nbf) and $claims->nbf > $time + self::CLOCK_DRIFT_MAX){ + if(isset($claims->nbf) && $claims->nbf > $time + self::CLOCK_DRIFT_MAX){ throw new VerifyLoginException(KnownTranslationKeys::POCKETMINE_DISCONNECT_INVALIDSESSION_TOOEARLY); } - if(isset($claims->exp) and $claims->exp < $time - self::CLOCK_DRIFT_MAX){ + if(isset($claims->exp) && $claims->exp < $time - self::CLOCK_DRIFT_MAX){ throw new VerifyLoginException(KnownTranslationKeys::POCKETMINE_DISCONNECT_INVALIDSESSION_TOOLATE); } diff --git a/src/network/mcpe/cache/ChunkCache.php b/src/network/mcpe/cache/ChunkCache.php index 1eb02a118..f8107e356 100644 --- a/src/network/mcpe/cache/ChunkCache.php +++ b/src/network/mcpe/cache/ChunkCache.php @@ -160,7 +160,7 @@ class ChunkCache implements ChunkListener{ private function restartPendingRequest(int $chunkX, int $chunkZ) : void{ $chunkHash = World::chunkHash($chunkX, $chunkZ); $existing = $this->caches[$chunkHash] ?? null; - if($existing === null or $existing->hasResult()){ + if($existing === null || $existing->hasResult()){ throw new \InvalidArgumentException("Restart can only be applied to unresolved promises"); } $existing->cancel(); diff --git a/src/network/mcpe/compression/ZlibCompressor.php b/src/network/mcpe/compression/ZlibCompressor.php index 284a8dcb7..a489aa153 100644 --- a/src/network/mcpe/compression/ZlibCompressor.php +++ b/src/network/mcpe/compression/ZlibCompressor.php @@ -60,7 +60,7 @@ final class ZlibCompressor implements Compressor{ } public function willCompress(string $data) : bool{ - return $this->threshold > -1 and strlen($data) >= $this->threshold; + return $this->threshold > -1 && strlen($data) >= $this->threshold; } /** diff --git a/src/network/mcpe/convert/ItemTranslator.php b/src/network/mcpe/convert/ItemTranslator.php index 87e1a6ae6..d00a6f90c 100644 --- a/src/network/mcpe/convert/ItemTranslator.php +++ b/src/network/mcpe/convert/ItemTranslator.php @@ -69,7 +69,7 @@ final class ItemTranslator{ private static function make() : self{ $data = Utils::assumeNotFalse(file_get_contents(Path::join(\pocketmine\BEDROCK_DATA_PATH, 'r16_to_current_item_map.json')), "Missing required resource file"); $json = json_decode($data, true); - if(!is_array($json) or !isset($json["simple"], $json["complex"]) || !is_array($json["simple"]) || !is_array($json["complex"])){ + if(!is_array($json) || !isset($json["simple"], $json["complex"]) || !is_array($json["simple"]) || !is_array($json["complex"])){ throw new AssumptionFailedError("Invalid item table format"); } diff --git a/src/network/mcpe/convert/TypeConverter.php b/src/network/mcpe/convert/TypeConverter.php index efa4e79c0..d03918efd 100644 --- a/src/network/mcpe/convert/TypeConverter.php +++ b/src/network/mcpe/convert/TypeConverter.php @@ -156,7 +156,7 @@ class TypeConverter{ }else{ [$id, $meta] = $idMeta; - if($itemStack instanceof Durable and $itemStack->getDamage() > 0){ + if($itemStack instanceof Durable && $itemStack->getDamage() > 0){ if($nbt !== null){ if(($existing = $nbt->getTag(self::DAMAGE_TAG)) !== null){ $nbt->removeTag(self::DAMAGE_TAG); @@ -266,7 +266,7 @@ class TypeConverter{ switch($action->sourceType){ case NetworkInventoryAction::SOURCE_CONTAINER: $window = null; - if($action->windowId === ContainerIds::UI and $action->inventorySlot > 0){ + if($action->windowId === ContainerIds::UI && $action->inventorySlot > 0){ if($action->inventorySlot === UIInventorySlotOffset::CREATED_ITEM_OUTPUT){ return null; //useless noise } diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index cd91f4f7f..baa0d22d7 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -201,7 +201,7 @@ class InGamePacketHandler extends PacketHandler{ $curPos = $this->player->getLocation(); $newPos = $rawPos->round(4)->subtract(0, 1.62, 0); - if($this->forceMoveSync and $newPos->distanceSquared($curPos) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks + if($this->forceMoveSync && $newPos->distanceSquared($curPos) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks $this->session->getLogger()->debug("Got outdated pre-teleport movement, received " . $newPos . ", expected " . $curPos); //Still getting movements from before teleport, ignore them return false; @@ -316,11 +316,11 @@ class InGamePacketHandler extends PacketHandler{ foreach($data->getActions() as $networkInventoryAction){ if( ( - $networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_TODO and ( - $networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_RESULT or + $networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_TODO && ( + $networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_RESULT || $networkInventoryAction->windowId === NetworkInventoryAction::SOURCE_TYPE_CRAFTING_USE_INGREDIENT ) - ) or ( + ) || ( $this->craftingTransaction !== null && !$networkInventoryAction->oldItem->getItemStack()->equals($networkInventoryAction->newItem->getItemStack()) && $networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER && @@ -415,10 +415,10 @@ class InGamePacketHandler extends PacketHandler{ case UseItemTransactionData::ACTION_CLICK_BLOCK: //TODO: start hack for client spam bug $clickPos = $data->getClickPosition(); - $spamBug = ($this->lastRightClickData !== null and - microtime(true) - $this->lastRightClickTime < 0.1 and //100ms - $this->lastRightClickData->getPlayerPosition()->distanceSquared($data->getPlayerPosition()) < 0.00001 and - $this->lastRightClickData->getBlockPosition()->equals($data->getBlockPosition()) and + $spamBug = ($this->lastRightClickData !== null && + microtime(true) - $this->lastRightClickTime < 0.1 && //100ms + $this->lastRightClickData->getPlayerPosition()->distanceSquared($data->getPlayerPosition()) < 0.00001 && + $this->lastRightClickData->getBlockPosition()->equals($data->getBlockPosition()) && $this->lastRightClickData->getClickPosition()->distanceSquared($clickPos) < 0.00001 //signature spam bug has 0 distance, but allow some error ); //get rid of continued spam if the player clicks and holds right-click @@ -731,7 +731,7 @@ class InGamePacketHandler extends PacketHandler{ public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ $blockPosition = $packet->blockPosition; $block = $this->player->getWorld()->getBlockAt($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ()); - if($block instanceof ItemFrame and $block->getFramedItem() !== null){ + if($block instanceof ItemFrame && $block->getFramedItem() !== null){ return $this->player->attackBlock(new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ()), $block->getFacing()); } return false; @@ -822,7 +822,7 @@ class InGamePacketHandler extends PacketHandler{ $modifiedPages[] = $packet->pageNumber; break; case BookEditPacket::TYPE_SWAP_PAGES: - if(!$newBook->pageExists($packet->pageNumber) or !$newBook->pageExists($packet->secondaryPageNumber)){ + if(!$newBook->pageExists($packet->pageNumber) || !$newBook->pageExists($packet->secondaryPageNumber)){ //the client will create pages on its own without telling us until it tries to switch them $newBook->addPage(max($packet->pageNumber, $packet->secondaryPageNumber)); } @@ -897,7 +897,7 @@ class InGamePacketHandler extends PacketHandler{ $newParts = []; $inQuotes = false; for($i = 0, $len = strlen($raw); $i <= $len; ++$i){ - if($i === $len or ($raw[$i] === "," and !$inQuotes)){ + if($i === $len || ($raw[$i] === "," && !$inQuotes)){ $part = substr($raw, $lastComma + 1, $i - ($lastComma + 1)); if(trim($part) === ""){ //regular parts will have quotes or something else that makes them non-empty $part = '""'; diff --git a/src/network/mcpe/handler/LoginPacketHandler.php b/src/network/mcpe/handler/LoginPacketHandler.php index 3ff77e2c4..f2ff2e0df 100644 --- a/src/network/mcpe/handler/LoginPacketHandler.php +++ b/src/network/mcpe/handler/LoginPacketHandler.php @@ -145,7 +145,7 @@ class LoginPacketHandler extends PacketHandler{ if(!$this->server->isWhitelisted($playerInfo->getUsername())){ $ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_WHITELISTED, "Server is whitelisted"); } - if($this->server->getNameBans()->isBanned($playerInfo->getUsername()) or $this->server->getIPBans()->isBanned($this->session->getIp())){ + if($this->server->getNameBans()->isBanned($playerInfo->getUsername()) || $this->server->getIPBans()->isBanned($this->session->getIp())){ $ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_BANNED, "You are banned"); } diff --git a/src/network/mcpe/handler/ResourcePacksPacketHandler.php b/src/network/mcpe/handler/ResourcePacksPacketHandler.php index f82ed1232..356a95a76 100644 --- a/src/network/mcpe/handler/ResourcePacksPacketHandler.php +++ b/src/network/mcpe/handler/ResourcePacksPacketHandler.php @@ -163,7 +163,7 @@ class ResourcePacksPacketHandler extends PacketHandler{ } $offset = $packet->chunkIndex * self::PACK_CHUNK_SIZE; - if($offset < 0 or $offset >= $pack->getPackSize()){ + if($offset < 0 || $offset >= $pack->getPackSize()){ $this->disconnectWithError("Invalid out-of-bounds request for chunk $packet->chunkIndex of $packet->packId: offset $offset, file size " . $pack->getPackSize()); return false; } diff --git a/src/network/mcpe/raklib/RakLibInterface.php b/src/network/mcpe/raklib/RakLibInterface.php index 15a8177fb..5d34ad352 100644 --- a/src/network/mcpe/raklib/RakLibInterface.php +++ b/src/network/mcpe/raklib/RakLibInterface.php @@ -180,7 +180,7 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{ public function onPacketReceive(int $sessionId, string $packet) : void{ if(isset($this->sessions[$sessionId])){ - if($packet === "" or $packet[0] !== self::MCPE_RAKNET_PACKET_ID){ + if($packet === "" || $packet[0] !== self::MCPE_RAKNET_PACKET_ID){ $this->sessions[$sessionId]->getLogger()->debug("Non-FE packet received: " . base64_encode($packet)); return; } diff --git a/src/network/mcpe/raklib/RakLibServer.php b/src/network/mcpe/raklib/RakLibServer.php index 94ea2c973..e7ee44d2c 100644 --- a/src/network/mcpe/raklib/RakLibServer.php +++ b/src/network/mcpe/raklib/RakLibServer.php @@ -129,7 +129,7 @@ class RakLibServer extends Thread{ public function startAndWait(int $options = PTHREADS_INHERIT_NONE) : void{ $this->start($options); $this->synchronized(function() : void{ - while(!$this->ready and $this->crashInfo === null){ + while(!$this->ready && $this->crashInfo === null){ $this->wait(); } $crashInfo = $this->crashInfo; diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php index 1fe207969..06b3c5ab0 100644 --- a/src/network/query/QueryHandler.php +++ b/src/network/query/QueryHandler.php @@ -104,7 +104,7 @@ class QueryHandler implements RawPacketHandler{ return true; case self::STATISTICS: //Stat $token = $stream->getInt(); - if($token !== ($t1 = self::getTokenString($this->token, $address)) and $token !== ($t2 = self::getTokenString($this->lastToken, $address))){ + if($token !== ($t1 = self::getTokenString($this->token, $address)) && $token !== ($t2 = self::getTokenString($this->lastToken, $address))){ $this->logger->debug("Bad token $token from $address $port, expected $t1 or $t2"); return true; diff --git a/src/network/query/QueryInfo.php b/src/network/query/QueryInfo.php index 559f9a653..5275edba7 100644 --- a/src/network/query/QueryInfo.php +++ b/src/network/query/QueryInfo.php @@ -204,7 +204,7 @@ final class QueryInfo{ $query = ""; $plist = $this->server_engine; - if(count($this->plugins) > 0 and $this->listPlugins){ + if(count($this->plugins) > 0 && $this->listPlugins){ $plist .= ":"; foreach($this->plugins as $p){ $d = $p->getDescription();