From b2f2cd31bc4df1ded9101b2fa5bb01073e9b35f6 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Wed, 1 Feb 2017 12:07:54 +0100 Subject: [PATCH 01/10] Joinable (damn i left MapItem shit in) --- src/pocketmine/Player.php | 4 ++ src/pocketmine/network/protocol/Info.php | 7 ++-- .../network/protocol/StartGamePacket.php | 2 +- .../network/protocol/TransferPacket.php | 42 +++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/pocketmine/network/protocol/TransferPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8b12b57243e..cc0f5ec88d3 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1847,6 +1847,7 @@ public function handleDataPacket(DataPacket $packet){ switch($packet::NETWORK_ID){ case ProtocolInfo::LOGIN_PACKET: + case ProtocolInfo::TRANSFER_PACKET: if($this->loggedIn){ break; } @@ -1924,6 +1925,9 @@ public function handleDataPacket(DataPacket $packet){ $this->onPlayerPreLogin(); + break; + case ProtocolInfo::MAP_INFO_REQUEST_PACKET: + var_dump($packet); break; case ProtocolInfo::MOVE_PLAYER_PACKET: $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z); diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 75c6fdda9e3..227432767f0 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -30,9 +30,9 @@ interface Info{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 100; - const MINECRAFT_VERSION = "v1.0.0.16"; - const MINECRAFT_VERSION_NETWORK = "1.0.0.16"; + const CURRENT_PROTOCOL = 101; + const MINECRAFT_VERSION = "v1.0.3.0"; + const MINECRAFT_VERSION_NETWORK = "1.0.3.0"; const LOGIN_PACKET = 0x01; const PLAY_STATUS_PACKET = 0x02; @@ -115,5 +115,6 @@ interface Info{ const RESOURCE_PACK_DATA_INFO_PACKET = 0x4f; const RESOURCE_PACK_CHUNK_DATA_PACKET = 0x50; const RESOURCE_PACK_CHUNK_REQUEST_PACKET = 0x51; + const TRANSFER_PACKET = 0x52; } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/protocol/StartGamePacket.php index 83080aa6973..4f069892a58 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/protocol/StartGamePacket.php @@ -60,7 +60,7 @@ public function encode(){ $this->putEntityId($this->entityRuntimeId); //EntityRuntimeID $this->putVector3f($this->x, $this->y, $this->z); $this->putLFloat(0); //TODO: find out what these are (yaw/pitch?) - $this->putLFloat(0); + $this->putLFloat(0); // Those are a Vector2 $this->putVarInt($this->seed); $this->putVarInt($this->dimension); $this->putVarInt($this->generator); diff --git a/src/pocketmine/network/protocol/TransferPacket.php b/src/pocketmine/network/protocol/TransferPacket.php new file mode 100644 index 00000000000..bed5ab3cc7c --- /dev/null +++ b/src/pocketmine/network/protocol/TransferPacket.php @@ -0,0 +1,42 @@ +address = $this->getString(); + $this->port = $this->getShort(); + } + + public function encode() { + $this->reset(); + $this->putString($this->address); + $this->putShort($this->eid); + //Here the xbox settings would follow. We already ignore those in the @link StartPacket + } + +} From 95e66f6def9bc114a0d9cba4cc946a157f3ba2fa Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Wed, 1 Feb 2017 12:22:57 +0100 Subject: [PATCH 02/10] Remove wrong constant --- src/pocketmine/Player.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index cc0f5ec88d3..a86a69d4168 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1847,7 +1847,6 @@ public function handleDataPacket(DataPacket $packet){ switch($packet::NETWORK_ID){ case ProtocolInfo::LOGIN_PACKET: - case ProtocolInfo::TRANSFER_PACKET: if($this->loggedIn){ break; } From c741319cff84515540540b3463ff524a8703e223 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Wed, 1 Feb 2017 13:16:50 +0100 Subject: [PATCH 03/10] Fix autocomplete mistake Thx @MrPowerGamerBR --- src/pocketmine/network/protocol/TransferPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/network/protocol/TransferPacket.php b/src/pocketmine/network/protocol/TransferPacket.php index bed5ab3cc7c..5bfe0b62752 100644 --- a/src/pocketmine/network/protocol/TransferPacket.php +++ b/src/pocketmine/network/protocol/TransferPacket.php @@ -35,7 +35,7 @@ public function decode() { public function encode() { $this->reset(); $this->putString($this->address); - $this->putShort($this->eid); + $this->putShort($this->port); //Here the xbox settings would follow. We already ignore those in the @link StartPacket } From 416e07ac17ec77e89916208d0a55f34961c11d34 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Wed, 1 Feb 2017 14:09:24 +0100 Subject: [PATCH 04/10] Simple command, disconnects client --- src/pocketmine/command/SimpleCommandMap.php | 3 + .../defaults/TransferserverCommand.php | 65 +++++++++++++++++++ .../network/protocol/TransferPacket.php | 1 + 3 files changed, 69 insertions(+) create mode 100644 src/pocketmine/command/defaults/TransferserverCommand.php diff --git a/src/pocketmine/command/SimpleCommandMap.php b/src/pocketmine/command/SimpleCommandMap.php index 6d356ea2d01..deff576baa9 100644 --- a/src/pocketmine/command/SimpleCommandMap.php +++ b/src/pocketmine/command/SimpleCommandMap.php @@ -57,6 +57,8 @@ use pocketmine\command\defaults\TellCommand; use pocketmine\command\defaults\TimeCommand; use pocketmine\command\defaults\TimingsCommand; +use pocketmine\command\defaults\TransferCommand; +use pocketmine\command\defaults\TransferserverCommand; use pocketmine\command\defaults\VanillaCommand; use pocketmine\command\defaults\VersionCommand; use pocketmine\command\defaults\WhitelistCommand; @@ -114,6 +116,7 @@ private function setDefaultCommands(){ $this->register("pocketmine", new TeleportCommand("tp")); $this->register("pocketmine", new TimeCommand("time")); $this->register("pocketmine", new TimingsCommand("timings")); + $this->register("pocketmine", new TransferserverCommand("transferserver")); $this->register("pocketmine", new ReloadCommand("reload")); if($this->server->getProperty("debug.commands", false)){ diff --git a/src/pocketmine/command/defaults/TransferserverCommand.php b/src/pocketmine/command/defaults/TransferserverCommand.php new file mode 100644 index 00000000000..ce2a3367140 --- /dev/null +++ b/src/pocketmine/command/defaults/TransferserverCommand.php @@ -0,0 +1,65 @@ +setPermission("pocketmine.command.transferserver"); + } + + public function execute(CommandSender $sender, $currentAlias, array $args) { + if (!$this->testPermission($sender) || $sender instanceof ConsoleCommandSender) { + return true; + } + + /** @var string $address + * @var $port + */ + if (count($args) < 2 || !is_string(($address = $args[0])) || !is_numeric(($port = $args[1]))) { + $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); + + return false; + } + + $pk = new TransferPacket(); + $pk->port = intval($port); + $pk->address = $address; + /** @var Player $sender */ + $sender->dataPacket($pk); + $sender->getServer()->broadcastMessage('Player ' . $sender->getName() . ' used the /transferserver command and tries to connect to ' . $address . ':' . $port); + + return true; + } +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/TransferPacket.php b/src/pocketmine/network/protocol/TransferPacket.php index 5bfe0b62752..37c02aee94c 100644 --- a/src/pocketmine/network/protocol/TransferPacket.php +++ b/src/pocketmine/network/protocol/TransferPacket.php @@ -30,6 +30,7 @@ class TransferPacket extends DataPacket { public function decode() { $this->address = $this->getString(); $this->port = $this->getShort(); + print 'Client tries to join from Server ' . $this->address . ':' . $this->port . PHP_EOL; } public function encode() { From 25810f2668bc2d6f796c414158d710ad6a299e3a Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Wed, 1 Feb 2017 14:27:36 +0100 Subject: [PATCH 05/10] Working Transfer! Thanks to @MrPowerGamerBR for reminding me to check the signed --- src/pocketmine/network/protocol/TransferPacket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/protocol/TransferPacket.php b/src/pocketmine/network/protocol/TransferPacket.php index 37c02aee94c..cc01f37808b 100644 --- a/src/pocketmine/network/protocol/TransferPacket.php +++ b/src/pocketmine/network/protocol/TransferPacket.php @@ -29,14 +29,14 @@ class TransferPacket extends DataPacket { public function decode() { $this->address = $this->getString(); - $this->port = $this->getShort(); + $this->port = $this->getLShort(); print 'Client tries to join from Server ' . $this->address . ':' . $this->port . PHP_EOL; } public function encode() { $this->reset(); $this->putString($this->address); - $this->putShort($this->port); + $this->putLShort($this->port); //Here the xbox settings would follow. We already ignore those in the @link StartPacket } From e87e2700b59a74963d0857247811faa3f91ea722 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Wed, 1 Feb 2017 14:46:28 +0100 Subject: [PATCH 06/10] Cleanup The decode only happens client side. Port is an "integer" in the command --- .../command/defaults/TransferserverCommand.php | 13 +++++++++---- src/pocketmine/network/protocol/TransferPacket.php | 7 +------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pocketmine/command/defaults/TransferserverCommand.php b/src/pocketmine/command/defaults/TransferserverCommand.php index ce2a3367140..aa497a4e462 100644 --- a/src/pocketmine/command/defaults/TransferserverCommand.php +++ b/src/pocketmine/command/defaults/TransferserverCommand.php @@ -26,6 +26,7 @@ use pocketmine\event\TranslationContainer; use pocketmine\network\protocol\TransferPacket; use pocketmine\Player; +use pocketmine\utils\TextFormat; class TransferserverCommand extends VanillaCommand { @@ -40,25 +41,29 @@ public function __construct($name) { } public function execute(CommandSender $sender, $currentAlias, array $args) { - if (!$this->testPermission($sender) || $sender instanceof ConsoleCommandSender) { + if (!$this->testPermission($sender)) { + return true; + } + if ($sender instanceof ConsoleCommandSender) { + $sender->sendMessage(TextFormat::RED . 'A console can not be transferred!'); return true; } /** @var string $address * @var $port */ - if (count($args) < 2 || !is_string(($address = $args[0])) || !is_numeric(($port = $args[1]))) { + if (count($args) < 2 || !is_string(($address = $args[0])) || !is_int(($port = $args[1]))) { $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return false; } $pk = new TransferPacket(); - $pk->port = intval($port); + $pk->port = (int)$port; $pk->address = $address; /** @var Player $sender */ $sender->dataPacket($pk); - $sender->getServer()->broadcastMessage('Player ' . $sender->getName() . ' used the /transferserver command and tries to connect to ' . $address . ':' . $port); + $sender->getServer()->getLogger()->info('Transferring player "' . $sender->getName() . '" to ' . $address . ':' . $port); return true; } diff --git a/src/pocketmine/network/protocol/TransferPacket.php b/src/pocketmine/network/protocol/TransferPacket.php index cc01f37808b..de45a5e8281 100644 --- a/src/pocketmine/network/protocol/TransferPacket.php +++ b/src/pocketmine/network/protocol/TransferPacket.php @@ -27,17 +27,12 @@ class TransferPacket extends DataPacket { public $address; public $port; - public function decode() { - $this->address = $this->getString(); - $this->port = $this->getLShort(); - print 'Client tries to join from Server ' . $this->address . ':' . $this->port . PHP_EOL; - } + public function decode() { } public function encode() { $this->reset(); $this->putString($this->address); $this->putLShort($this->port); - //Here the xbox settings would follow. We already ignore those in the @link StartPacket } } From 2128133e9a219984cc0331a4b1e9fd6d469a3f77 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Wed, 1 Feb 2017 15:02:47 +0100 Subject: [PATCH 07/10] Add transferTo function to Player.php, Add PlayerTransferEvent --- src/pocketmine/Player.php | 21 ++++++ .../defaults/TransferserverCommand.php | 9 +-- .../event/player/PlayerTransferEvent.php | 71 +++++++++++++++++++ 3 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 src/pocketmine/event/player/PlayerTransferEvent.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index a86a69d4168..6d4025f5629 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -37,6 +37,7 @@ use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityShootBowEvent; +use pocketmine\event\entity\PlayerTransferEvent; use pocketmine\event\entity\ProjectileLaunchEvent; use pocketmine\event\inventory\CraftItemEvent; use pocketmine\event\inventory\InventoryCloseEvent; @@ -132,6 +133,7 @@ use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\TakeItemEntityPacket; use pocketmine\network\protocol\TextPacket; +use pocketmine\network\protocol\TransferPacket; use pocketmine\network\protocol\UpdateAttributesPacket; use pocketmine\network\protocol\UpdateBlockPacket; use pocketmine\network\SourceInterface; @@ -1024,6 +1026,25 @@ public function directDataPacket(DataPacket $packet, $needACK = false){ return true; } + /** + * @param string $address + * @param int $port + * @return bool transferred + */ + public function transferTo(string $address, int $port) { + $this->server->getPluginManager()->callEvent($ev = new PlayerTransferEvent($this, $address, $port)); + if ($ev->isCancelled()) { + return false; + } + $pk = new TransferPacket(); + $pk->address = $ev->getAddress(); + $pk->port = $ev->getPort(); + $this->dataPacket($pk); + $this->getServer()->getLogger()->info('Transferring player "' . $this->getName() . '" to ' . $ev->getAddress() . ':' . $ev->getPort()); + + return true; + } + /** * @param Vector3 $pos * diff --git a/src/pocketmine/command/defaults/TransferserverCommand.php b/src/pocketmine/command/defaults/TransferserverCommand.php index aa497a4e462..80711564378 100644 --- a/src/pocketmine/command/defaults/TransferserverCommand.php +++ b/src/pocketmine/command/defaults/TransferserverCommand.php @@ -24,7 +24,6 @@ use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; use pocketmine\event\TranslationContainer; -use pocketmine\network\protocol\TransferPacket; use pocketmine\Player; use pocketmine\utils\TextFormat; @@ -58,13 +57,9 @@ public function execute(CommandSender $sender, $currentAlias, array $args) { return false; } - $pk = new TransferPacket(); - $pk->port = (int)$port; - $pk->address = $address; /** @var Player $sender */ - $sender->dataPacket($pk); - $sender->getServer()->getLogger()->info('Transferring player "' . $sender->getName() . '" to ' . $address . ':' . $port); + $success = $sender->transferTo($address, $port); - return true; + return $success; } } \ No newline at end of file diff --git a/src/pocketmine/event/player/PlayerTransferEvent.php b/src/pocketmine/event/player/PlayerTransferEvent.php new file mode 100644 index 00000000000..0e4aced74eb --- /dev/null +++ b/src/pocketmine/event/player/PlayerTransferEvent.php @@ -0,0 +1,71 @@ +player = $player; + $this->address = $address; + $this->port = $port; + } + + /** + * @return string + */ + public function getAddress() { + return $this->address; + } + + /** + * @param string $address + */ + public function setAddress(string $address) { + $this->address = $address; + } + + /** + * @return int + */ + public function getPort() { + return $this->port; + } + + /** + * @param int $port + */ + public function setPort(int $port) { + $this->port = $port; + } + + +} \ No newline at end of file From ac537880f79853cee8bc58d640b5aee661441604 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Thu, 2 Feb 2017 17:25:14 +0100 Subject: [PATCH 08/10] Fix PlayerTransferEvent (lazy coding mistake, was in Entity events before' --- src/pocketmine/Player.php | 4 ++-- src/pocketmine/command/defaults/TransferserverCommand.php | 4 ++-- src/pocketmine/event/player/PlayerTransferEvent.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 6d4025f5629..07f8031369d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -37,7 +37,7 @@ use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityShootBowEvent; -use pocketmine\event\entity\PlayerTransferEvent; +use pocketmine\event\player\PlayerTransferEvent; use pocketmine\event\entity\ProjectileLaunchEvent; use pocketmine\event\inventory\CraftItemEvent; use pocketmine\event\inventory\InventoryCloseEvent; @@ -1031,7 +1031,7 @@ public function directDataPacket(DataPacket $packet, $needACK = false){ * @param int $port * @return bool transferred */ - public function transferTo(string $address, int $port) { + public function transferTo(string $address, int $port = 19132) { $this->server->getPluginManager()->callEvent($ev = new PlayerTransferEvent($this, $address, $port)); if ($ev->isCancelled()) { return false; diff --git a/src/pocketmine/command/defaults/TransferserverCommand.php b/src/pocketmine/command/defaults/TransferserverCommand.php index 80711564378..bcd408645df 100644 --- a/src/pocketmine/command/defaults/TransferserverCommand.php +++ b/src/pocketmine/command/defaults/TransferserverCommand.php @@ -49,9 +49,9 @@ public function execute(CommandSender $sender, $currentAlias, array $args) { } /** @var string $address - * @var $port + * @var int $port */ - if (count($args) < 2 || !is_string(($address = $args[0])) || !is_int(($port = $args[1]))) { + if (count($args) < 2 || !is_string(($address = $args[0])) || !is_numeric(($port = $args[1]))) { $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return false; diff --git a/src/pocketmine/event/player/PlayerTransferEvent.php b/src/pocketmine/event/player/PlayerTransferEvent.php index 0e4aced74eb..29341fe3b89 100644 --- a/src/pocketmine/event/player/PlayerTransferEvent.php +++ b/src/pocketmine/event/player/PlayerTransferEvent.php @@ -19,7 +19,7 @@ * */ -namespace pocketmine\event\entity; +namespace pocketmine\event\player; use pocketmine\event\Cancellable; use pocketmine\event\player\PlayerEvent; From b3d22188ef3ff66c16e44ee9082b78c7779bec78 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Sat, 11 Feb 2017 12:19:17 +0100 Subject: [PATCH 09/10] Submodule update --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index 989ad8198cb..f4bfcb8e6b7 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 989ad8198cb5dd9b463a03831c1332e4cea60858 +Subproject commit f4bfcb8e6b7cf93f3961dd8fc9c5ba44ce068763 From 333c106ac168d0c2622da6d35c0fe71f825851a5 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Sat, 11 Feb 2017 12:55:37 +0100 Subject: [PATCH 10/10] Remove Map stuff --- src/pocketmine/Player.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 07f8031369d..96f1643a531 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1040,7 +1040,7 @@ public function transferTo(string $address, int $port = 19132) { $pk->address = $ev->getAddress(); $pk->port = $ev->getPort(); $this->dataPacket($pk); - $this->getServer()->getLogger()->info('Transferring player "' . $this->getName() . '" to ' . $ev->getAddress() . ':' . $ev->getPort()); + Command::broadcastCommandMessage($this, new TranslationContainer("Transferred to {%0}:{%1}", [$ev->getAddress(), $ev->getPort()])); return true; } @@ -1945,9 +1945,6 @@ public function handleDataPacket(DataPacket $packet){ $this->onPlayerPreLogin(); - break; - case ProtocolInfo::MAP_INFO_REQUEST_PACKET: - var_dump($packet); break; case ProtocolInfo::MOVE_PLAYER_PACKET: $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);