diff --git a/src/pocketmine/ChunkMaker.php b/src/pocketmine/ChunkMaker.php index e59de6675..440e37730 100644 --- a/src/pocketmine/ChunkMaker.php +++ b/src/pocketmine/ChunkMaker.php @@ -5,7 +5,6 @@ use raklib\protocol\EncapsulatedPacket; use raklib\RakLib; use pocketmine\network\protocol\DataPacket; -use pocketmine\network\ProxyInterface; class ChunkMaker extends Thread { @@ -13,14 +12,12 @@ class ChunkMaker extends Thread { protected $shutdown; protected $internalQueue; protected $raklib; - protected $proxy; - public function __construct(\ClassLoader $loader, $raklib, $proxy) { + public function __construct(\ClassLoader $loader, $raklib) { $this->internalQueue = new \Threaded; $this->shutdown = false; $this->classLoader = $loader; $this->raklib = $raklib; - $this->proxy = $proxy; $this->start(PTHREADS_INHERIT_CONSTANTS); } @@ -41,19 +38,12 @@ public function run() { new ChunkStorage($this); } - public function sendData($data, $buffer) { - if (!is_null($this->proxy) && !empty($data['proxySessionId']) && !empty($data['proxyId'])) { - $infoData = pack('N', $data['proxySessionId']) . chr(ProxyInterface::STANDART_PACKET_ID) . $buffer; - $info = chr(strlen($data['proxyId'])) . $data['proxyId'] . $infoData; - $this->proxy->writeToProxyServer($info); - } elseif(!is_null($this->raklib)) { - $identifier = $data['identifier']; - $pk = new EncapsulatedPacket(); - $pk->buffer = $buffer; - $pk->reliability = 3; - $enBuffer = chr(RakLib::PACKET_ENCAPSULATED) . chr(strlen($identifier)) . $identifier . chr(RakLib::PRIORITY_NORMAL) . $pk->toBinary(true); - $this->raklib->pushMainToThreadPacket($enBuffer); - } + public function sendData($identifier, $buffer) { + $pk = new EncapsulatedPacket(); + $pk->buffer = $buffer; + $pk->reliability = 3; + $enBuffer = chr(RakLib::PACKET_ENCAPSULATED) . chr(strlen($identifier)) . $identifier . chr(RakLib::PRIORITY_NORMAL) . $pk->toBinary(true); + $this->raklib->pushMainToThreadPacket($enBuffer); } public function pushMainToThreadPacket($data) { diff --git a/src/pocketmine/ChunkStorage.php b/src/pocketmine/ChunkStorage.php index d4fae4029..2dd845c9f 100644 --- a/src/pocketmine/ChunkStorage.php +++ b/src/pocketmine/ChunkStorage.php @@ -51,7 +51,7 @@ protected function clearChunkCache($data) { protected function sendFromCache($data) { $buffer = $this->getCache(Level::chunkHash($data['chunkX'], $data['chunkZ']), ($data['protocol'] << 4) | $data['subClientId']); - $this->server->sendData($data, $buffer); + $this->server->sendData($data['identifier'], $buffer); } protected function doChunk($data) { @@ -103,7 +103,7 @@ protected function doChunk($data) { $buffer = $pk->getBuffer(); $decodedBuffer = Binary::writeVarInt(strlen($buffer)) . $buffer; $buffer = zlib_encode($decodedBuffer, ZLIB_ENCODING_DEFLATE, 7); - $this->server->sendData($data, $buffer); + $this->server->sendData($data['identifier'], $buffer); $this->setCache(Level::chunkHash($data['chunkX'], $data['chunkZ']), ($protocol << 4) | $subClientId, $buffer); } diff --git a/src/pocketmine/PacketMaker.php b/src/pocketmine/PacketMaker.php index 4600fa27c..7a0465d0a 100644 --- a/src/pocketmine/PacketMaker.php +++ b/src/pocketmine/PacketMaker.php @@ -10,8 +10,6 @@ use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\network\protocol\MovePlayerPacket; -use pocketmine\network\proxylib\ProxyServer; -use pocketmine\network\ProxyInterface; class PacketMaker extends Thread { @@ -19,14 +17,12 @@ class PacketMaker extends Thread { protected $shutdown; protected $internalQueue; protected $raklib; - protected $proxy; - public function __construct(\ClassLoader $loader, $raklib, $proxy) { + public function __construct(\ClassLoader $loader, $raklib) { $this->internalQueue = new \Threaded; $this->shutdown = false; $this->classLoader = $loader; $this->raklib = $raklib; - $this->proxy = $proxy; $this->start(PTHREADS_INHERIT_CONSTANTS); } @@ -110,23 +106,17 @@ protected function checkPacket($data) { } if (!empty($moveStr)) { $buffer = zlib_encode($moveStr, ZLIB_ENCODING_DEFLATE, 7); - $this->sendData($identifier, $buffer, $playerData); + $this->sendData($identifier, $buffer); } } } - protected function sendData($identifier, $buffer, $data) { - if (!is_null($this->proxy) && !empty($data['proxySessionId']) && !empty($data['proxyId'])) { - $infoData = pack('N', $data['proxySessionId']) . chr(ProxyInterface::STANDART_PACKET_ID) . $buffer; - $info = chr(strlen($data['proxyId'])) . $data['proxyId'] . $infoData; - $this->proxy->writeToProxyServer($info); - } elseif(!is_null($this->raklib)) { - $pk = new EncapsulatedPacket(); - $pk->buffer = $buffer; - $pk->reliability = 3; - $enBuffer = chr(RakLib::PACKET_ENCAPSULATED) . chr(strlen($identifier)) . $identifier . chr(RakLib::PRIORITY_NORMAL) . $pk->toBinary(true); - $this->raklib->pushMainToThreadPacket($enBuffer); - } + protected function sendData($identifier, $buffer) { + $pk = new EncapsulatedPacket(); + $pk->buffer = $buffer; + $pk->reliability = 3; + $enBuffer = chr(RakLib::PACKET_ENCAPSULATED) . chr(strlen($identifier)) . $identifier . chr(RakLib::PRIORITY_NORMAL) . $pk->toBinary(true); + $this->raklib->pushMainToThreadPacket($enBuffer); } } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 2773e4f89..d56711e26 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -161,13 +161,6 @@ use pocketmine\network\protocol\ResourcePackClientResponsePacket; use pocketmine\network\protocol\LevelSoundEventPacket; -use pocketmine\network\proxy\Info as ProtocolProxyInfo; -use pocketmine\network\proxy\DisconnectPacket as ProxyDisconnectPacket; -use pocketmine\network\ProxyInterface; -use pocketmine\network\proxy\RedirectPacket; -use pocketmine\network\proxy\ProxyPacket; - - use pocketmine\network\protocol\v120\InventoryTransactionPacket; use pocketmine\network\protocol\v120\Protocol120; use pocketmine\network\multiversion\MultiversionEnums; @@ -182,7 +175,6 @@ use pocketmine\utils\Binary; use pocketmine\network\protocol\v310\NetworkChunkPublisherUpdatePacket; use pocketmine\network\multiversion\Entity as MultiversionEntity; -use pocketmine\network\proxy\DisconnectCompletePacket; use pocketmine\network\protocol\GameRulesChangedPacket; use pocketmine\player\PlayerSettingsTrait; use pocketmine\event\entity\EntityLevelChangeEvent; @@ -329,11 +321,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer { protected $identifier; - public $proxyId = ''; - public $proxySessionId = ''; - - protected $closeFromProxy = false; - protected static $availableCommands = []; protected $movementSpeed = self::DEFAULT_SPEED; @@ -438,14 +425,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer { protected $commandsData = []; protected $joinCompleted = false; protected $platformChatId = ""; - protected $forcedPlayerId = false; - protected $incomingTransferData = ""; protected $doDaylightCycle = true; private $lastQuickCraftTransactionGroup = []; protected $additionalSkinData = []; protected $playerListIsSent = false; - public function getLeaveMessage(){ return ""; } @@ -888,16 +872,12 @@ protected function sendNextChunk(){ $this->dataPacket($pk); $this->setDaylightCycle(!$this->level->stopTime); + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::PLAYER_SPAWN; + $this->dataPacket($pk); + $this->noDamageTicks = 60; $this->spawned = true; - if ($this->isFirstConnect) { - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::PLAYER_SPAWN; - $this->dataPacket($pk); - } else { - $this->setHealth($this->getHealth()); - Player::setFood($this->getFood()); - } $chunkX = $chunkZ = null; foreach ($this->usedChunks as $index => $c) { Level::getXZ($index, $chunkX, $chunkZ); @@ -983,9 +963,6 @@ protected function orderChunks() { * @return int|bool */ public function dataPacket(DataPacket $packet){ - if (!($this->interface instanceof ProxyInterface) && ($packet instanceof ProxyPacket)) { - return; - } if($this->connected === false){ return false; } @@ -994,11 +971,6 @@ public function dataPacket(DataPacket $packet){ $packet->senderSubClientID = $this->subClientId; return $this->parent->dataPacket($packet); } - if ($packet instanceof ProxyPacket) { - $packet->encode(); - $this->interface->putPacket($this, $packet->getBuffer(), true); - return; - } switch($packet->pname()){ case 'INVENTORY_CONTENT_PACKET': @@ -1134,12 +1106,6 @@ public function directDataPacket(DataPacket $packet){ return $this->parent->dataPacket($packet); } - if ($packet instanceof ProxyPacket) { - $packet->encode(); - $this->interface->putPacket($this, $packet->getBuffer(), true); - return; - } - $packet->encode($this->protocol); $packet->senderSubClientID = 0; $buffer = $packet->getBuffer(); @@ -1255,16 +1221,16 @@ public function getGamemode() { * * @return bool */ - - public function setGamemode($gm, $isForce = false){ - if ($gm < 0 || $gm > 3 || ($this->gamemode === $gm && !$isForce)) { - + public function setGamemode($gm) { + if ($gm < 0 || $gm > 3 || $this->gamemode === $gm) { return false; } + $this->server->getPluginManager()->callEvent($ev = new PlayerGameModeChangeEvent($this, (int) $gm)); if ($ev->isCancelled()) { return false; } + $this->gamemode = $gm; $this->allowFlight = $this->isCreative(); @@ -2602,9 +2568,6 @@ public function sendTip($message){ * @param string $reason Reason showed in console */ public function close($message = "", $reason = "generic reason"){ - if ($this->closed) { - return; - } if ($this->isTransfered) { $reason = 'transfered'; } @@ -2619,20 +2582,11 @@ public function close($message = "", $reason = "generic reason"){ $task->cancel(); } $this->tasks = []; - if($this->connected){ - if (!$this->closeFromProxy) { - if ($this->interface instanceof ProxyInterface) { - $pk = new ProxyDisconnectPacket(); - $pk->reason = $reason; - $this->dataPacket($pk); - $this->connected = false; - } else { - $pk = new DisconnectPacket; - $pk->message = $reason; - $this->directDataPacket($pk); - $this->connected = false; - } - } + if($this->connected and !$this->closed){ + $pk = new DisconnectPacket; + $pk->message = $reason; + $this->directDataPacket($pk); + $this->connected = false; if($this->username != ""){ $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message, $reason)); if($this->server->getSavePlayerData() and $this->loggedIn === true){ @@ -2652,27 +2606,29 @@ public function close($message = "", $reason = "generic reason"){ if (!is_null($this->currentWindow)) { $this->removeWindow($this->currentWindow); } - - $this->freeChunks(); - parent::close(); - $this->server->removeOnlinePlayer($this); - if ($this->closeFromProxy) { - $this->removeAllEffects(); - $this->clearFullPlayerList(); - foreach ($this->entitiesPacketsQueue as $packets) { - $this->sendEntityPackets($packets); + + $this->interface->close($this, $reason); + + $chunkX = $chunkZ = null; + foreach($this->usedChunks as $index => $d){ + Level::getXZ($index, $chunkX, $chunkZ); + $this->level->freeChunk($chunkX, $chunkZ, $this); + unset($this->usedChunks[$index]); + foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ + $entity->removeClosedViewer($this); } - $this->sendPacketQueue(); - $pk = new DisconnectCompletePacket(); - $this->dataPacket($pk); } - $this->interface->close($this, $reason); + + parent::close(); + + $this->server->removeOnlinePlayer($this); + $this->loggedIn = false; // if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){ // $this->server->broadcastMessage($ev->getQuitMessage()); // } - + $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->spawned = false; $this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "/" . $this->ip . " logged out due to " . str_replace(["\n", "\r"], [" ", ""], $reason)); @@ -2690,8 +2646,7 @@ public function close($message = "", $reason = "generic reason"){ if (!is_null($this->scoreboard)) { $this->scoreboard->removePlayer($this); } - $this->connected = false; - } + } $this->perm->clearPermissions(); $this->server->removePlayer($this); } @@ -3129,10 +3084,8 @@ public function getLastMessageFrom() { return $this->lastMessageReceivedFrom; } - public function setIdentifier($identifier, $id = '', $sessionId = ''){ + public function setIdentifier($identifier){ $this->identifier = $identifier; - $this->proxyId = $id; - $this->proxySessionId = $sessionId; } public function getIdentifier(){ @@ -3148,7 +3101,7 @@ public function kickOnFullServer() { } public function processLogin() { - if (!($this->interface instanceof ProxyInterface) && $this->server->isUseEncrypt() && $this->needEncrypt()) { + if ($this->server->isUseEncrypt() && $this->needEncrypt()) { $privateKey = $this->server->getServerPrivateKey(); $token = $this->server->getServerToken(); $pk = new ServerToClientHandshakePacket(); @@ -3164,11 +3117,9 @@ public function processLogin() { } public function continueLoginProcess() { - if (!($this->interface instanceof ProxyInterface)) { - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::LOGIN_SUCCESS; - $this->dataPacket($pk); - } + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_SUCCESS; + $this->dataPacket($pk); $modsManager = $this->server->getModsManager(); $pk = new ResourcePacksInfoPacket(); @@ -3313,29 +3264,24 @@ public function completeLogin() { $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $spawnPosition)); $this->setPosition($ev->getRespawnPosition()); - if ($this->isFirstConnect) { - $pk = new StartGamePacket(); - $pk->seed = -1; - $pk->dimension = 0; - $pk->x = $this->x; - $pk->y = $this->y + $this->getEyeHeight(); - $pk->z = $this->z; - $pk->spawnX = (int) $spawnPosition->x; - $pk->spawnY = (int) ($spawnPosition->y + $this->getEyeHeight()); - $pk->spawnZ = (int) $spawnPosition->z; - $pk->generator = 1; //0 old, 1 infinite, 2 flat - $pk->gamemode = $this->gamemode & 0x01; - $pk->eid = $this->id; - $pk->stringClientVersion = $this->clientVersion; - $pk->multiplayerCorrelationId = $this->uuid->toString(); - $this->directDataPacket($pk); - if ($this->protocol >= ProtocolInfo::PROTOCOL_331) { - $this->directDataPacket(new AvailableEntityIdentifiersPacket()); - $this->directDataPacket(new BiomeDefinitionListPacket()); - } - } else { - $this->sendPosition($this); - $this->setGamemode($this->gamemode, true); + $pk = new StartGamePacket(); + $pk->seed = -1; + $pk->dimension = 0; + $pk->x = $this->x; + $pk->y = $this->y + $this->getEyeHeight(); + $pk->z = $this->z; + $pk->spawnX = (int) $spawnPosition->x; + $pk->spawnY = (int) ($spawnPosition->y + $this->getEyeHeight()); + $pk->spawnZ = (int) $spawnPosition->z; + $pk->generator = 1; //0 old, 1 infinite, 2 flat + $pk->gamemode = $this->gamemode == 3 ? 1 : $this->gamemode; + $pk->eid = $this->id; + $pk->stringClientVersion = $this->clientVersion; + $pk->multiplayerCorrelationId = $this->uuid->toString(); + $this->directDataPacket($pk); + if ($this->protocol >= ProtocolInfo::PROTOCOL_331) { + $this->directDataPacket(new AvailableEntityIdentifiersPacket()); + $this->directDataPacket(new BiomeDefinitionListPacket()); } $pk = new SetTimePacket(); @@ -3382,92 +3328,12 @@ public function completeLogin() { // $this->getInventory()->addItem(Item::get(Item::ENCHANTMENT_TABLE), Item::get(Item::DYE, 4, 64), Item::get(Item::IRON_AXE), Item::get(Item::IRON_SWORD)); } - public function handleProxyDataPacket($packet) { - if ($packet->pid() === ProtocolProxyInfo::CONNECT_PACKET) { - if ($this->loggedIn === true) { - return; - } - $this->protocol = $packet->protocol; - if ($packet->isValidProtocol === false) { - $this->close("", TextFormat::RED . "Please switch to Minecraft: PE " . TextFormat::GREEN . $this->getServer()->getVersion() . TextFormat::RED . " to join."); - return; - } - - $this->username = TextFormat::clean($packet->username); - $this->xblName = $this->username; - $this->displayName = $this->username; - $this->setNameTag($this->username); - $this->iusername = strtolower($this->username); - - $this->randomClientId = $packet->clientId; - $this->loginData = ["clientId" => $packet->clientId, "loginData" => null]; - $this->uuid = $packet->clientUUID; - $this->rawUUID = $this->uuid->toBinary(); - $this->clientSecret = $packet->clientSecret; - $this->setSkin($packet->skin, $packet->skinName, $packet->skinGeometryName, $packet->skinGeometryData, $packet->capeData, $packet->premiunSkin); - if ($packet->viewRadius > 12) { - $packet->viewRadius = 12; - } elseif ($packet->viewRadius < 3) { - $packet->viewRadius = 3; - } - $this->setViewRadius($packet->viewRadius); - $this->ip = $packet->ip; - $this->port = $packet->port; - $this->isFirstConnect = $packet->isFirst; - $this->deviceType = $packet->deviceOSType; - $this->inventoryType = $packet->inventoryType; - $this->xuid = $packet->XUID; - $this->originalProtocol = $packet->originalProtocol; - $this->languageCode = $packet->languageCode; - $this->serverAddress = $packet->serverAddress; - $this->clientVersion = $packet->clientVersion; - $this->identityPublicKey = $packet->identityPublicKey; - $this->platformChatId = $packet->platformChatId; - $this->forcedPlayerId = $packet->playerId; - $this->incomingTransferData = $packet->transferData; - $this->additionalSkinData = $packet->additionalSkinData; - if ($this->isFirstConnect) { - $this->processLogin(); - } else { - $this->completeLogin(); - $this->loggedIn = true; - $this->scheduleUpdate(); - $this->justCreated = false; - } - } elseif ($packet->pid() === ProtocolProxyInfo::DISCONNECT_PACKET) { - $this->closeFromProxy = true; - $this->close('', $packet->reason); - } elseif ($packet->pid() === ProtocolProxyInfo::PING_PACKET) { - $this->setPing($packet->ping); - } - } - - protected function generateId() { - if ($this->forcedPlayerId !== false) { - $this->id = $this->forcedPlayerId; - } else { - parent::generateId(); - } - } public function getInterface() { return $this->interface; } - public function transfer($address, $port = false, $transferData = '') { - if ($this->interface instanceof ProxyInterface) { - $pk = new RedirectPacket(); - $pk->ip = $address; - $pk->port = ($port === false ? 10305 : $port); - $pk->data = $transferData; - $this->dataPacket($pk); - $this->isTransfered = true; - } else { - $this->hardTransfer($address, $port); - } - } - - public function hardTransfer($address, $port = false) { + public function transfer($address, $port = false) { $pk = new TransferPacket(); $pk->ip = $address; $pk->port = ($port === false ? 19132 : $port); @@ -5140,17 +5006,7 @@ public function sendFullPlayerList() { } $this->playerListIsSent = true; } - - public function clearFullPlayerList() { - $players = $this->server->getOnlinePlayers(); - $pk = new PlayerListPacket(); - $pk->type = PlayerListPacket::TYPE_REMOVE; - foreach ($players as $player) { - $pk->entries[] = [$player->getUniqueId()]; - } - $this->dataPacket($pk); - } - + public function setInteractButtonText($text, $force = false) { if ($force || $this->interactButtonText != $text) { $this->interactButtonText = $text; diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index a131605d8..788f063d5 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -87,7 +87,6 @@ use pocketmine\network\protocol\PlayerListPacket; use pocketmine\network\query\QueryHandler; use pocketmine\network\RakLibInterface; -use pocketmine\network\ProxyInterface; use pocketmine\network\rcon\RCON; use pocketmine\network\SourceInterface; use pocketmine\network\upnp\UPnP; @@ -294,9 +293,6 @@ class Server{ private $isUseEncrypt = false; private $modsManager = null; - - private $raklibServer = null; - private $proxyServer = null; public function addSpawnedEntity($entity) { if ($entity instanceof Player) { @@ -308,7 +304,7 @@ public function addSpawnedEntity($entity) { public function removeSpawnedEntity($entity) { unset($this->spawnedEntity[$entity->getId()]); } - + public function isUseAnimal() { return $this->useAnimal; } @@ -401,14 +397,7 @@ public function getMaxPlayers(){ public function getPort(){ return $this->getConfigInt("server-port", 19132); } - - /** - * @return int - */ - public function getProxyPort(){ - return $this->getConfigInt("proxy-port", 10305); - } - + /** * @return int */ @@ -1524,7 +1513,6 @@ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $ $this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, [ "motd" => "Minecraft: PE Server", "server-port" => 19132, - "proxy-port" => 10305, "memory-limit" => "256M", "white-list" => false, "spawn-protection" => 16, @@ -1549,8 +1537,6 @@ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $ "auto-save" => true, "auto-generate" => false, "save-player-data" => false, - "use-proxy" => false, - "use-raklib" => true, "time-update" => true, "use-encrypt" => false ]); @@ -1621,22 +1607,8 @@ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $ $this->logger->info("Starting Minecraft PE server on " . ($this->getIp() === "" ? "*" : $this->getIp()) . ":" . $this->getPort()); define("BOOTUP_RANDOM", @Utils::getRandomBytes(16)); $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort()); - - - - $useRaklib = $this->getConfigBoolean("use-raklib", true); - $useProxy = $this->getConfigBoolean("use-proxy", false); - if ($useRaklib) { - $this->addInterface($this->mainInterface = new RakLibInterface($this)); - $this->raklibServer = $this->mainInterface->getRaklib(); - } - if ($useProxy) { - $this->addInterface($proxyInterface = new ProxyInterface($this)); - $this->proxyServer = $proxyInterface->getRaklib(); - if (!$useRaklib) { - $this->mainInterface = $proxyInterface; - } - } + + $this->addInterface($this->mainInterface = new RakLibInterface($this)); $this->logger->info("This server is running " . $this->getName() . " version " . ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE . " \"" . $this->getCodename() . "\" (API " . $this->getApiVersion() . ")"); $this->logger->info($this->getName() . " is distributed under the LGPL License"); @@ -2147,7 +2119,7 @@ public function start(){ $this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"'); - $this->packetMaker = new PacketMaker($this->getLoader(), $this->getRaklibServer(), $this->getProxyServer()); + $this->packetMaker = new PacketMaker($this->getLoader(), $this->mainInterface->getRakLib()); $this->tickAverage = array(); $this->useAverage = array(); @@ -2625,14 +2597,6 @@ public function getServerToken() { return $this->serverToken; } - public function getRaklibServer() { - return $this->raklibServer; - } - - public function getProxyServer() { - return $this->proxyServer; - } - public function addLevel($level) { $this->levels[$level->getId()] = $level; } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 73db8bc9f..639f97fb3 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -174,7 +174,7 @@ abstract class Entity extends Location implements Metadatable{ const DATA_PLAYER_FLAG_SLEEP = 1; const DATA_PLAYER_FLAG_DEAD = 2; - public static $entityCount = 10000000; + public static $entityCount = 2; /** @var Entity[] */ private static $knownEntities = []; private static $shortNames = []; @@ -291,7 +291,7 @@ public function __construct(FullChunk $chunk, Compound $nbt){ if($this->eyeHeight === null){ $this->eyeHeight = $this->height / 2 + 0.1; } - $this->generateId(); + $this->id = Entity::$entityCount++; $this->justCreated = true; $this->namedtag = $nbt; @@ -353,10 +353,6 @@ public function __construct(FullChunk $chunk, Compound $nbt){ $this->scheduleUpdate(); } - - protected function generateId() { - $this->id = Entity::$entityCount++; - } /** * @return string diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index ecbe32fd2..2d3521fc5 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -322,7 +322,7 @@ public function __construct(Server $server, $name, $path, $provider){ $this->timings = new LevelTimings($this); $this->temporalPosition = new Position(0, 0, 0, $this); $this->temporalVector = new Vector3(0, 0, 0); - $this->chunkMaker = new ChunkMaker($this->server->getLoader(), $this->server->getRaklibServer(), $this->server->getProxyServer()); + $this->chunkMaker = new ChunkMaker($this->server->getLoader(), $this->server->getMainInterface()->getRakLib()); if ($this->server->getAutoGenerate()) { $this->generator = Generator::getGenerator($this->provider->getGenerator()); } @@ -1847,8 +1847,6 @@ public function requestChunk($x, $z, $player) { $data['subClientId'] = $subClientId; $data['protocol'] = $protocol; $data['identifier'] = $playerIdentifier; - $data['proxySessionId'] = $player->proxySessionId; - $data['proxyId'] = $player->proxyId; $this->chunkMaker->pushMainToThreadPacket(serialize($data)); } @@ -2338,8 +2336,6 @@ public function addEntityMovement($viewers, $entityId, $x, $y, $z, $yaw, $pitch, if (!isset($this->moveToSend['player'][$playerIdentifier])) { $this->moveToSend['player'][$playerIdentifier] = [ 'playerProtocol' => $p->getPlayerProtocol(), - 'proxySessionId' => $p->proxySessionId, - 'proxyId' => $p->proxyId, 'subIds' => [] ]; } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index db1021212..ec28e442f 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -99,11 +99,6 @@ use pocketmine\network\protocol\v310\AvailableEntityIdentifiersPacket; use pocketmine\network\protocol\v310\NetworkChunkPublisherUpdatePacket; use pocketmine\network\protocol\v310\SpawnParticleEffectPacket; -use pocketmine\utils\Binary; -use pocketmine\network\proxy\ConnectPacket; -use pocketmine\network\proxy\DisconnectPacket as ProxyDisconnectPacket; -use pocketmine\network\proxy\Info as ProtocolProxyInfo; -use pocketmine\network\proxy\PingPacket; class Network { @@ -115,9 +110,6 @@ class Network { private $packetPool310; /** @var \SplFixedArray */ private $packetPool331; - /** @var \SplFixedArray */ - private $proxyPacketPool; - /** @var Server */ private $server; @@ -137,7 +129,6 @@ public function __construct(Server $server){ $this->registerPackets120(); $this->registerPackets310(); $this->registerPackets331(); - $this->registerProxyPackets(); $this->server = $server; } @@ -253,15 +244,7 @@ public function registerPacket310($id, $class){ public function registerPacket331($id, $class){ $this->packetPool331[$id] = new $class; } - - /** - * @param int $id 0-255 - * @param DataPacket $class - */ - public function registerProxyPacket($id, $class){ - $this->proxyPacketPool[$id] = new $class; - } - + public function getServer(){ return $this->server; } @@ -286,7 +269,6 @@ public function getPacket($id, $playerProtocol){ case Info::PROTOCOL_370: case Info::PROTOCOL_385: case Info::PROTOCOL_386: - case Info::PROTOCOL_390: case Info::PROTOCOL_389: case Info::PROTOCOL_392: case Info::PROTOCOL_393: @@ -307,27 +289,12 @@ public function getPacket($id, $playerProtocol){ } return null; } - - /** - * @param $id - * - * @return DataPacket - */ - public function getProxyPacket($id){ - /** @var DataPacket $class */ - $class = $this->proxyPacketPool[$id]; - if($class !== null){ - return clone $class; - } - return null; - } - + public static function getChunkPacketProtocol($playerProtocol){ switch ($playerProtocol) { case Info::PROTOCOL_400: case Info::PROTOCOL_393: case Info::PROTOCOL_392: - case Info::PROTOCOL_390: case Info::PROTOCOL_389: case Info::PROTOCOL_386: case Info::PROTOCOL_385: @@ -585,12 +552,4 @@ private function registerPackets331() { $this->registerPacket331(ProtocolInfo331::SPAWN_PARTICLE_EFFECT_PACKET, SpawnParticleEffectPacket::class); $this->registerPacket331(ProtocolInfo331::SPAWN_EXPERIENCE_ORB_PACKET, SpawnExperienceOrbPacket::class); } - - private function registerProxyPackets(){ - $this->proxyPacketPool = new \SplFixedArray(256); - $this->registerProxyPacket(ProtocolProxyInfo::CONNECT_PACKET, ConnectPacket::class); - $this->registerProxyPacket(ProtocolProxyInfo::DISCONNECT_PACKET, ProxyDisconnectPacket::class); - $this->registerProxyPacket(ProtocolProxyInfo::PING_PACKET, PingPacket::class); - } - } diff --git a/src/pocketmine/network/ProxyInterface.php b/src/pocketmine/network/ProxyInterface.php deleted file mode 100644 index 694df907e..000000000 --- a/src/pocketmine/network/ProxyInterface.php +++ /dev/null @@ -1,204 +0,0 @@ -server = $server; - $this->identifiers = new \SplObjectStorage(); - $this->proxyServer = new ProxyServer($this->server->getLogger(), $this->server->getLoader(), $this->server->getProxyPort(), $this->server->getIp() === "" ? "127.0.0.1" : $this->server->getIp()); - } - - public function emergencyShutdown() { - - } - - public function setName($name) { - if (strlen($name) > 1) { - $this->name = $name; - } - } - - public function shutdown() { - $this->proxyServer->shutdown(); - } - - public function setCount($count, $maxcount) { - $this->count = $count; - $this->maxcount = $maxcount; - } - - public function process() { - $packets = []; - while ($info = $this->proxyServer->readFromProxyServer()) { - $packets[] = $info; - } - foreach ($packets as $packet) { - $idlen = ord($packet{0}); - $dataIdentifier = substr($packet, 1, $idlen); - $data = substr($packet, 1 + $idlen); - $this->checkPacketData($dataIdentifier, $data); - } - } - - private function checkPacketData($dataIdentifier, $data) { - if ($data == 'close') { - foreach ($this->session as $sessionId => $session) { - if (strpos($sessionId, $dataIdentifier) === 0) { - $session->close('', 'Proxy disconnect'); - } - } - return; - } - $sessionId = unpack('N', substr($data, 0, 4)); - $sessionId = $sessionId[1]; - $buffer = substr($data, 4); - $identifier = $dataIdentifier . $sessionId; - if (!isset($this->session[$identifier])) { - if(ord($buffer{0}) == self::PROXY_PACKET_ID && ord($buffer{1}) == ProtocolProxyInfo::CONNECT_PACKET) { - $this->openSession($dataIdentifier, $sessionId); - } - } - if (isset($this->session[$identifier])) { - $player = $this->session[$identifier]; - $type = ord($buffer{0}); - $buffer = substr($buffer, 1); - if ($type == self::STANDART_PACKET_ID) { - $pk = $this->getPacket($buffer, $player); - if ($pk === false) { - return; - } - if (!is_null($pk)) { - try { - $pk->decode($player->getPlayerProtocol()); - $player->handleDataPacket($pk); - } catch (\Exception $e) { - echo "DECODE ERROR: " . $e->getMessage() . ", PACKET ID: " . $pk->pid(); - } - } - } elseif ($type == self::PROXY_PACKET_ID) { - $pk = $this->getProxyPacket($buffer); - if ($pk === false) { - return; - } - if (!is_null($pk)) { - try { - $pk->decode($player->getPlayerProtocol()); - $player->handleProxyDataPacket($pk); - } catch (\Exception $e) { - echo "DECODE ERROR: " . $e->getMessage() . ", PROXY PACKET ID: " . $pk->pid(); - } - } - } - } - } - - public function openSession($id, $sessionId) { - $data = explode(':', $id); - $address = $data[0]; - $port = $data[1]; - $identifier = $id . $sessionId; - $ev = new PlayerCreationEvent($this, Player::class, Player::class, null, $address, $port); - $this->server->getPluginManager()->callEvent($ev); - $class = $ev->getPlayerClass(); - - $player = new $class($this, $ev->getClientId(), $ev->getAddress(), $ev->getPort()); - $this->session[$identifier] = $player; - $player->setIdentifier($identifier, $id, $sessionId); - $this->server->addPlayer($identifier, $player); - } - - public function putPacket(Player $player, $buffer, $isProxyPacket = false) { - if (isset($this->session[$player->getIdentifier()])) { - if ($isProxyPacket) { - $infoData = pack('N', $player->proxySessionId) . chr(self::PROXY_PACKET_ID | RemoteProxyServer::FLAG_NEED_ZLIB) . $buffer; - } else { - $infoData = pack('N', $player->proxySessionId) . chr(self::STANDART_PACKET_ID | RemoteProxyServer::FLAG_NEED_ZLIB) . $buffer; - } - $info = chr(strlen($player->proxyId)) . $player->proxyId . $infoData; - - $this->proxyServer->writeToProxyServer($info); - } - } - - public function close(Player $player, $reason = "unknown reason") { - unset($this->session[$player->getIdentifier()]); - } - - public function putReadyPacket($player, $buffer) { - if (isset($this->session[$player->getIdentifier()])) { - $infoData = pack('N', $player->proxySessionId) . chr(self::STANDART_PACKET_ID) . $buffer; - $info = chr(strlen($player->proxyId)) . $player->proxyId . $infoData; - $this->proxyServer->writeToProxyServer($info); - } - } - - private function getPacket($buffer, $player) { - $pid = ord($buffer{0}); - if ($pid == 0x13) { //speed hack - $player->setLastMovePacket($buffer); - return null; - } - - if (($data = $this->server->getNetwork()->getPacket($pid, $player->getPlayerProtocol())) === null) { - return null; - } - - $data->setBuffer($buffer); - - return $data; - } - - private function getProxyPacket($buffer) { - if (empty($buffer)) { - return false; - } - $pid = ord($buffer{0}); - - if (($data = $this->server->getNetwork()->getProxyPacket($pid)) === null) { - return null; - } - - $data->setBuffer($buffer, 1); - - return $data; - } - - public function blockAddress($address, $timeout = 300) {} - - public function setNetwork(Network $network) { - $this->network = $network; - } - - public function sendRawPacket($address, $port, $payload) {} - - public function getRaklib(){ - return $this->proxyServer; - } -} diff --git a/src/pocketmine/network/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/protocol/AvailableCommandsPacket.php index 0b0b1d2f5..42c91cf8d 100644 --- a/src/pocketmine/network/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/protocol/AvailableCommandsPacket.php @@ -84,7 +84,6 @@ public static function prepareCommands($commands) { Info::PROTOCOL_385 => new BinaryStream(), Info::PROTOCOL_386 => new BinaryStream(), Info::PROTOCOL_389 => new BinaryStream(), - Info::PROTOCOL_390 => new BinaryStream(), Info::PROTOCOL_392 => new BinaryStream(), Info::PROTOCOL_393 => new BinaryStream(), Info::PROTOCOL_400 => new BinaryStream(), diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index dd71f2d00..a65729ed9 100755 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -115,7 +115,6 @@ public static function initPackets() { self::$packetsIds[Info::PROTOCOL_385] = $oClass->getConstants(); self::$packetsIds[Info::PROTOCOL_386] = $oClass->getConstants(); self::$packetsIds[Info::PROTOCOL_389] = $oClass->getConstants(); - self::$packetsIds[Info::PROTOCOL_390] = $oClass->getConstants(); self::$packetsIds[Info::PROTOCOL_392] = $oClass->getConstants(); self::$packetsIds[Info::PROTOCOL_393] = $oClass->getConstants(); self::$packetsIds[Info::PROTOCOL_400] = $oClass->getConstants(); diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index a9e25c93b..af18b4523 100755 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -80,8 +80,8 @@ interface Info{ const PROTOCOL_386 = 386; // 1.13.0.12 const PROTOCOL_387 = 387; // 1.13.0.15 const PROTOCOL_388 = 388; // 1.13.0.25 - const PROTOCOL_389 = 389; // 1.14.x.x - const PROTOCOL_390 = 390; // 1.14.60 + const PROTOCOL_389 = 389; // 1.13.0.18 + const PROTOCOL_390 = 390; // 1.14.0.1 const PROTOCOL_392 = 392; // 1.15.0.51 const PROTOCOL_393 = 393; // 1.15.0.53 const PROTOCOL_394 = 394; // 1.15.0.54 diff --git a/src/pocketmine/network/protocol/PEPacket.php b/src/pocketmine/network/protocol/PEPacket.php index 7358e7416..173728899 100644 --- a/src/pocketmine/network/protocol/PEPacket.php +++ b/src/pocketmine/network/protocol/PEPacket.php @@ -69,7 +69,6 @@ public final static function convertProtocol($protocol) { case Info::PROTOCOL_392: return Info::PROTOCOL_392; case Info::PROTOCOL_390: - return Info::PROTOCOL_390; case Info::PROTOCOL_389: case Info::PROTOCOL_388: return Info::PROTOCOL_389; diff --git a/src/pocketmine/network/proxy/ConnectPacket.php b/src/pocketmine/network/proxy/ConnectPacket.php deleted file mode 100644 index 2b44e7575..000000000 --- a/src/pocketmine/network/proxy/ConnectPacket.php +++ /dev/null @@ -1,93 +0,0 @@ -identifier = $this->getString(); - $this->protocol = $this->getInt(); - $acceptedProtocols = ProtocolInfo::ACCEPTED_PROTOCOLS; - if (!in_array($this->protocol, $acceptedProtocols)) { - $this->isValidProtocol = false; - return; - } - $this->clientId = $this->getString(); - $this->clientUUID = UUID::fromString($this->clientId); - $this->clientSecret = $this->getString(); - $this->username = $this->getString(); - $this->skinName = $this->getString(); - $this->skin = $this->getString(); - $this->viewRadius = $this->getInt(); - $this->ip = $this->getString(); - $this->port = $this->getInt(); - $this->isFirst = (bool) $this->getByte(); - $this->deviceOSType = $this->getInt(); - $this->inventoryType = $this->getInt(); - $this->XUID = $this->getString(); - $this->originalProtocol = $this->protocol; - $this->protocol = PEPacket::convertProtocol($this->protocol); - $this->capeData = $this->getString(); - $this->premiunSkin = $this->getString(); - $this->languageCode = $this->getString(); - $this->serverAddress = $this->getString(); - $this->clientVersion = $this->getString(); - $this->platformChatId = $this->getString(); - $this->identityPublicKey = $this->getString(); - $this->playerId = $this->getInt(); - $this->transferData = $this->getString(); - $this->skinGeometryName = $this->getString(); - $this->skinGeometryData = $this->getString(); - if (!$this->feof()) { - $this->additionalSkinData = json_decode($this->getString(), true); - if (isset($this->additionalSkinData['AnimatedImageData'])) { - foreach ($this->additionalSkinData['AnimatedImageData'] as &$animation) { - $animation['Image'] = base64_decode($animation['Image']); - } - } - } - $this->checkSkinData($this->skin, $this->skinGeometryName, $this->skinGeometryData, $this->additionalSkinData); - } - - public function encode() { - - } - -} diff --git a/src/pocketmine/network/proxy/DisconnectCompletePacket.php b/src/pocketmine/network/proxy/DisconnectCompletePacket.php deleted file mode 100644 index 7299f4856..000000000 --- a/src/pocketmine/network/proxy/DisconnectCompletePacket.php +++ /dev/null @@ -1,19 +0,0 @@ -reset(); - } - -} diff --git a/src/pocketmine/network/proxy/DisconnectPacket.php b/src/pocketmine/network/proxy/DisconnectPacket.php deleted file mode 100644 index 90fe02456..000000000 --- a/src/pocketmine/network/proxy/DisconnectPacket.php +++ /dev/null @@ -1,22 +0,0 @@ -reason = $this->getString(); - } - - public function encode() { - $this->reset(); - $this->putString($this->reason); - } - -} diff --git a/src/pocketmine/network/proxy/Info.php b/src/pocketmine/network/proxy/Info.php deleted file mode 100644 index 626b29827..000000000 --- a/src/pocketmine/network/proxy/Info.php +++ /dev/null @@ -1,13 +0,0 @@ -ping = $this->getVarInt(); - } - - public function encode() { - $this->reset(); - $this->putVarInt($this->ping); - } - -} diff --git a/src/pocketmine/network/proxy/ProxyPacket.php b/src/pocketmine/network/proxy/ProxyPacket.php deleted file mode 100644 index 1171a95c3..000000000 --- a/src/pocketmine/network/proxy/ProxyPacket.php +++ /dev/null @@ -1,23 +0,0 @@ -putByte($this::NETWORK_ID); - } -} diff --git a/src/pocketmine/network/proxy/RedirectPacket.php b/src/pocketmine/network/proxy/RedirectPacket.php deleted file mode 100644 index 24e8c85d1..000000000 --- a/src/pocketmine/network/proxy/RedirectPacket.php +++ /dev/null @@ -1,28 +0,0 @@ -ip = $this->getString(); - $this->port = $this->getInt(); - $this->data = $this->getString(); - } - - public function encode() { - $this->reset(); - $this->putString($this->ip); - $this->putInt($this->port); - $this->putString($this->data); - } - -} diff --git a/src/pocketmine/network/proxylib/ProxyServer.php b/src/pocketmine/network/proxylib/ProxyServer.php deleted file mode 100644 index 0704af02d..000000000 --- a/src/pocketmine/network/proxylib/ProxyServer.php +++ /dev/null @@ -1,169 +0,0 @@ -logger = $logger; - $this->interface = $interface; - $this->port = (int) $port; - $this->shutdown = false; - $this->setClassLoader($loader); - $this->externalQueue = new \Threaded; - $this->internalQueue = new \Threaded; - $this->start(); - } - - public function run() { - $this->registerClassLoader(); - gc_enable(); - ini_set("memory_limit", -1); - ini_set("display_errors", 1); - ini_set("display_startup_errors", 1); - - set_error_handler([$this, "errorHandler"], E_ALL); - register_shutdown_function([$this, "shutdownHandler"]); - - - $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - if (socket_bind($this->socket, $this->interface, $this->port) !== true) { - $this->logger->critical("FAILED TO BIND TO " . $this->interface . ":" . $this->port . "!"); - exit(1); - } - socket_set_option($this->socket, SOL_SOCKET, SO_SNDBUF, 1024 * 1024 * 64); - socket_set_option($this->socket, SOL_SOCKET, SO_RCVBUF, 1024 * 1024 * 64); - socket_set_option($this->socket, SOL_SOCKET, SO_LINGER, ["l_onoff" => 1, "l_linger" => 0]); - socket_listen($this->socket, 20); - $this->logger->info("ProxyServer is running on $this->interface:$this->port"); - socket_set_nonblock($this->socket); - $this->remoteProxyServerManager = new RemoteProxyServerManager($this); - $this->remoteProxyServerManager->tickProcessor(); - socket_close($this->socket); - $this->closed = true; - } - - public function getNewServer() { - return socket_accept($this->socket); - } - - public function readFromProxyServer() { - return $this->externalQueue->shift(); - } - - public function pushToExternalQueue($data) { - $this->externalQueue[] = $data; - } - - public function writeToProxyServer($str) { - $this->internalQueue->synchronized(function($queue, $str) { - $queue[] = $str; - }, $this->internalQueue, $str); - } - - public function readFromInternaQueue() { - return $this->internalQueue->shift(); - } - - public function getLogger() { - return $this->logger; - } - - public function isShutdown() { - return $this->shutdown; - } - - public function shutdown() { - $this->shutdown = true; - } - - public function errorHandler($errno, $errstr, $errfile, $errline, $context, $trace = null) { - if (error_reporting() == 0) { - return; - } - $errorConversion = [ - E_ERROR => "E_ERROR", - E_WARNING => "E_WARNING", - E_PARSE => "E_PARSE", - E_NOTICE => "E_NOTICE", - E_CORE_ERROR => "E_CORE_ERROR", - E_CORE_WARNING => "E_CORE_WARNING", - E_COMPILE_ERROR => "E_COMPILE_ERROR", - E_COMPILE_WARNING => "E_COMPILE_WARNING", - E_USER_ERROR => "E_USER_ERROR", - E_USER_WARNING => "E_USER_WARNING", - E_USER_NOTICE => "E_USER_NOTICE", - E_STRICT => "E_STRICT", - E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", - E_DEPRECATED => "E_DEPRECATED", - E_USER_DEPRECATED => "E_USER_DEPRECATED", - ]; - - $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno; - if (($pos = strpos($errstr, "\n")) !== false) { - $errstr = substr($errstr, 0, $pos); - } - - var_dump("An $errno error happened: \"$errstr\" in \"$errfile\" at line $errline"); -// @file_put_contents('logs/' .date('Y.m.d') . '_debug.log', "An $errno error happened: \"$errstr\" in \"$errfile\" at line $errline\n", FILE_APPEND | LOCK_EX); - - foreach (($trace = $this->getTrace($trace === null ? 3 : 0, $trace)) as $i => $line) { - var_dump($line); -// @file_put_contents('logs/' .date('Y.m.d') . '_debug.log', $line."\n", FILE_APPEND | LOCK_EX); - } - - return true; - } - - public function getTrace($start = 1, $trace = null) { - if ($trace === null) { - if (function_exists("xdebug_get_function_stack")) { - $trace = array_reverse(xdebug_get_function_stack()); - } else { - $e = new \Exception(); - $trace = $e->getTrace(); - } - } - - $messages = []; - $j = 0; - for ($i = (int) $start; isset($trace[$i]); ++$i, ++$j) { - $params = ""; - if (isset($trace[$i]["args"]) or isset($trace[$i]["params"])) { - if (isset($trace[$i]["args"])) { - $args = $trace[$i]["args"]; - } else { - $args = $trace[$i]["params"]; - } - foreach ($args as $name => $value) { - $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", "; - } - } - $messages[] = "#$j " . (isset($trace[$i]["file"]) ? ($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")"; - } - - return $messages; - } - - public function shutdownHandler() { - if ($this->shutdown !== true) { - var_dump("ProxyServer thread crashed!"); - } - if (!$this->closed) { - socket_close($this->socket); - } - } - -} diff --git a/src/pocketmine/network/proxylib/RemoteProxyServer.php b/src/pocketmine/network/proxylib/RemoteProxyServer.php deleted file mode 100644 index 876fc36bc..000000000 --- a/src/pocketmine/network/proxylib/RemoteProxyServer.php +++ /dev/null @@ -1,154 +0,0 @@ -proxyManager = $proxyManager; - $this->socket = $socket; - socket_set_nonblock($this->socket); - socket_getpeername($this->socket, $address, $port); - $this->ip = $address; - $this->port = $port; - $this->proxyManager->getLogger()->notice("RemoteProxyServer [$address:$port] has connected."); - } - - public function getIdentifier() { - return $this->ip . ':' . $this->port; - } - - public function close() { - $this->proxyManager->getLogger()->notice("RemoteProxyServer [$this->ip:$this->port] has disconnected."); - $info = chr(strlen($this->getIdentifier())) . $this->getIdentifier() . 'close'; - $this->proxyManager->getProxyServer()->pushToExternalQueue($info); - socket_clear_error($this->socket); - socket_close($this->socket); - if (get_resource_type($this->socket) == 'Socket') { - $err = socket_last_error($this->socket); - var_dump('Close error :' . $err); - return $err == 0; - } else { - return true; - } - } - - public function update() { - $err = socket_last_error($this->socket); - if ($err !== 0 && $err !== 35 && $err !== 11) { - return false; - } else { - $this->checkReadQueue(); - $this->checkWriteQueue(); - return true; - } - } - - public function checkPacket($data) { - $data = zlib_decode($data); - if ($data === false) { - return false; - } - $info = chr(strlen($this->getIdentifier())) . $this->getIdentifier() . $data; - $this->proxyManager->getProxyServer()->pushToExternalQueue($info); - return true; - } - - public function putPacket($buffer) { - $flags = ord($buffer{4}); - if (($flags & self::FLAG_NEED_ZLIB) > 0) { - $flags = $flags ^ self::FLAG_NEED_ZLIB; - $buff = substr($buffer, 5); - if (strlen($buffer) > 512) { - $data = zlib_encode($buff, ZLIB_ENCODING_DEFLATE, -1); - } else { - $data = $this->fakeZlib($buff); - } - $data = substr($buffer, 0, 4) . chr($flags) . $data; - $this->writeQueue[] = pack('N', strlen($data)) . $data; - } else { - $this->writeQueue[] = pack('N', strlen($buffer)) . $buffer; - } - } - - private function fakeZlib($buffer) { - static $startBytes = "\x78\x01\x01"; - $len = strlen($buffer); - return $startBytes . Binary::writeLShort($len) . Binary::writeLShort($len ^ 0xffff) . $buffer . hex2bin(hash('adler32', $buffer, false)); - } - - private function checkWriteQueue() { - foreach ($this->writeQueue as $key => $data) { - $dataLength = strlen($data); - socket_clear_error($this->socket); - while (true) { - $sentBytes = socket_write($this->socket, $data); - if ($sentBytes === false) { - $errno = socket_last_error($this->socket); - echo 'SOCKET WRITE ERROR: ' . $errno . ' - ' . socket_strerror($errno) . PHP_EOL; - $this->writeQueue[$key] = $data; - return; - } else if ($sentBytes < $dataLength) { - $data = substr($data, $sentBytes); - $dataLength -= $sentBytes; - } else { - break; - } - } - unset($this->writeQueue[$key]); - } - } - - private function checkReadQueue() { - $data = $this->lastBuffer; - $atLeastOneRecived = false; - while (strlen($buffer = @socket_read($this->socket, 65535, PHP_BINARY_READ)) > 0) { - $data .= $buffer; - $atLeastOneRecived = true; - } - - if (!$atLeastOneRecived) { - $errno = socket_last_error($this->socket); - if ($errno !== 11) { - echo 'SOCKET READ ERROR: ' . $errno . ' - ' . socket_strerror($errno) . PHP_EOL; - } - return; - } - - $this->lastBuffer = ''; - if (($dataLen = strlen($data)) > 0) { - $offset = 0; - while ($offset < $dataLen) { - if ($offset + 4 > $dataLen) { - $this->lastBuffer = substr($data, $offset); - break; - } - $len = unpack('N', substr($data, $offset, 4)); - $len = $len[1]; - if ($offset + $len + 4 > $dataLen) { - $this->lastBuffer = substr($data, $offset); - break; - } - $offset += 4; - $msg = substr($data, $offset, $len); - $res = $this->checkPacket($msg); - if (!$res) { - var_dump('FATAL: Not zlib packet'); - } - $offset += $len; - } - } - } - -} diff --git a/src/pocketmine/network/proxylib/RemoteProxyServerManager.php b/src/pocketmine/network/proxylib/RemoteProxyServerManager.php deleted file mode 100644 index 5717cf7c3..000000000 --- a/src/pocketmine/network/proxylib/RemoteProxyServerManager.php +++ /dev/null @@ -1,68 +0,0 @@ -proxyServer = $proxyServer; - } - - public function tickProcessor() { - while (!$this->proxyServer->isShutdown()) { - $start = microtime(true); - $this->tick(); - $time = microtime(true) - $start; - if ($time < 0.025) { - @time_sleep_until(microtime(true) + 0.025 - $time); - } - } - foreach ($this->remoteProxyServer as $remoteServer) { - $remoteServer->close(); - } - $this->remoteProxyServer = []; - } - - private function tick() { - while (($socket = $this->proxyServer->getNewServer())) { - $remoteProxy = new RemoteProxyServer($this, $socket); - $this->remoteProxyServer[$remoteProxy->getIdentifier()] = $remoteProxy; - } - - foreach ($this->remoteProxyServer as $remoteServer) { - $remoteId = $remoteServer->getIdentifier(); - if (!$remoteServer->update()) { - $isClosed = $remoteServer->close(); - if ($isClosed) { - unset($this->remoteProxyServer[$remoteId]); - } else { - var_dump($remoteServer->getIdentifier().' is not close yet'); - } - } - } - $this->getNewPacket(); - } - - public function getLogger() { - return $this->proxyServer->getLogger(); - } - - public function getProxyServer() { - return $this->proxyServer; - } - - public function getNewPacket() { - while (($info = $this->proxyServer->readFromInternaQueue())) { - $idlen = ord($info{0}); - $dataIdentifier = substr($info, 1, $idlen); - $data = substr($info, 1 + $idlen); - if (isset($this->remoteProxyServer[$dataIdentifier])) { - $this->remoteProxyServer[$dataIdentifier]->putPacket($data); - } - } - } - -} diff --git a/src/pocketmine/utils/BinaryStream.php b/src/pocketmine/utils/BinaryStream.php index 1eaa653ba..718d20623 100755 --- a/src/pocketmine/utils/BinaryStream.php +++ b/src/pocketmine/utils/BinaryStream.php @@ -392,13 +392,7 @@ public function putSerializedSkin($playerProtocol, $skinId, $skinData, $skinGeom $this->putString(isset($additionalSkinData['CapeId']) ? $additionalSkinData['CapeId'] : ''); $uniqId = $skinId . $skinGeomtryName . "-" . microtime(true); - $this->putString($uniqId); // Full Skin ID - if ($playerProtocol == Info::PROTOCOL_390) { // Right now this only applies for proto 390 - $this->putString(''); //ArmSize - $this->putString(''); //SkinColor - $this->putLInt(0); //Persona Pieces -> more info to come - $this->putLInt(0); //PieceTintColors -> more info to come - } + $this->putString($uniqId); // Full Skin ID } public function getSerializedSkin($playerProtocol, &$skinId, &$skinData, &$skinGeomtryName, &$skinGeomtryData, &$capeData, &$additionalSkinData) { diff --git a/src/pocketmine/utils/MetadataConvertor.php b/src/pocketmine/utils/MetadataConvertor.php index 44ab1c9a0..70fdb874e 100644 --- a/src/pocketmine/utils/MetadataConvertor.php +++ b/src/pocketmine/utils/MetadataConvertor.php @@ -220,7 +220,6 @@ private static function updateMetaIds($meta, $protocol) { case Info::PROTOCOL_400: case Info::PROTOCOL_393: case Info::PROTOCOL_392: - case Info::PROTOCOL_390: case Info::PROTOCOL_389: case Info::PROTOCOL_386: case Info::PROTOCOL_385: @@ -283,7 +282,6 @@ private static function updateEntityFlags($meta, $protocol) { case Info::PROTOCOL_400: case Info::PROTOCOL_393: case Info::PROTOCOL_392: - case Info::PROTOCOL_390: case Info::PROTOCOL_389: case Info::PROTOCOL_386: case Info::PROTOCOL_385: