├── .gitignore ├── .poggit.yml ├── LICENSE ├── README.md ├── src └── SunProxy │ └── SunProxyAPI │ ├── Packets │ ├── AuthPacket.php │ ├── DisconnectPacket.php │ ├── PlanetTextPacket.php │ ├── PlanetTransferPacket.php │ ├── SunTextPacket.php │ ├── SunTransferPacket.php │ ├── TextResponsePacket.php │ ├── TransferResponsePacket.php │ └── Types │ │ ├── TextResponse.php │ │ └── TransferResponse.php │ ├── SockThread.php │ ├── SunProxyAPI.php │ └── TCPSocketException.php └── virion.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff 7 | .idea/**/workspace.xml 8 | .idea/**/tasks.xml 9 | .idea/**/usage.statistics.xml 10 | .idea/**/dictionaries 11 | .idea/**/shelf 12 | 13 | # Generated files 14 | .idea/**/contentModel.xml 15 | 16 | # Sensitive or high-churn files 17 | .idea/**/dataSources/ 18 | .idea/**/dataSources.ids 19 | .idea/**/dataSources.local.xml 20 | .idea/**/sqlDataSources.xml 21 | .idea/**/dynamic.xml 22 | .idea/**/uiDesigner.xml 23 | .idea/**/dbnavigator.xml 24 | 25 | # Gradle 26 | .idea/**/gradle.xml 27 | .idea/**/libraries 28 | 29 | # Gradle and Maven with auto-import 30 | # When using Gradle or Maven with auto-import, you should exclude module files, 31 | # since they will be recreated, and may cause churn. Uncomment if using 32 | # auto-import. 33 | # .idea/artifacts 34 | # .idea/compiler.xml 35 | # .idea/jarRepositories.xml 36 | # .idea/modules.xml 37 | # .idea/*.iml 38 | # .idea/modules 39 | # *.iml 40 | # *.ipr 41 | 42 | # CMake 43 | cmake-build-*/ 44 | 45 | # Mongo Explorer plugin 46 | .idea/**/mongoSettings.xml 47 | 48 | # File-based project format 49 | *.iws 50 | 51 | # IntelliJ 52 | out/ 53 | 54 | # mpeltonen/sbt-idea plugin 55 | .idea_modules/ 56 | 57 | # JIRA plugin 58 | atlassian-ide-plugin.xml 59 | 60 | # Cursive Clojure plugin 61 | .idea/replstate.xml 62 | 63 | # Crashlytics plugin (for Android Studio and IntelliJ) 64 | com_crashlytics_export_strings.xml 65 | crashlytics.properties 66 | crashlytics-build.properties 67 | fabric.properties 68 | 69 | # Editor-based Rest Client 70 | .idea/httpRequests 71 | 72 | # Android studio 3.1+ serialized cache file 73 | .idea/caches/build_file_checksums.ser 74 | 75 | .idea/ -------------------------------------------------------------------------------- /.poggit.yml: -------------------------------------------------------------------------------- 1 | --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/SunProxy/SunProxyAPI_PMMP 2 | build-by-default: true 3 | branches: 4 | - master 5 | projects: 6 | SunProxyAPI_PMMP: 7 | path: "" 8 | model: virion 9 | type: library 10 | ... 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ___ ___ ___ 2 | / /\ /__/\ /__/\ 3 | / /:/_ \ \:\ \ \:\ 4 | / /:/ /\ \ \:\ \ \:\ 5 | / /:/ /::\ ___ \ \:\ _____\__\:\ 6 | /__/:/ /:/\:\ /__/\ \__\:\ /__/::::::::\ 7 | \ \:\/:/~/:/ \ \:\ / /:/ \ \:\~~\~~\/ 8 | \ \::/ /:/ \ \:\ /:/ \ \:\ ~~~ 9 | \__\/ /:/ \ \:\/:/ \ \:\ 10 | /__/:/ \ \::/ \ \:\ 11 | \__\/ \__\/ \__\/ 12 | 13 | MIT License 14 | 15 | Copyright (c) 2020 Jviguy 16 | 17 | Permission is hereby granted, free of charge, to any person obtaining a copy 18 | of this software and associated documentation files (the "Software"), to deal 19 | in the Software without restriction, including without limitation the rights 20 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | copies of the Software, and to permit persons to whom the Software is 22 | furnished to do so, subject to the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be included in all 25 | copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #

2 | the pmmp virion for interacting with the sun proxy api 3 | 4 | # Downloading 5 | This project is connected to Poggit-CI so downloads are located [Here](https://poggit.pmmp.io/ci/SunProxy/SunProxyAPI_PMMP/~). 6 | 7 | # Usage 8 | This virion is meant to be used with a server using the [SunProxy](https://github.com/SunProxy/sun)
9 | ### Fast Transfer 10 | ```php 11 | //Use the class 12 | use SunProxy\SunProxyAPI\SunProxyAPI; 13 | 14 | class Main extends \pocketmine\plugin\PluginBase { 15 | public function onEnable() { 16 | //Is always needed to start up Packet usage 17 | SunProxyAPI::Register(); 18 | } 19 | 20 | public function onCommand(\pocketmine\command\CommandSender $sender,\pocketmine\command\Command $command,string $label, array $args) : bool { 21 | switch ($label) { 22 | case "transfer": 23 | if ($sender instanceof \pocketmine\Player) { 24 | //transfer players based on arg input 25 | SunProxyAPI::FastTransferPlayer($sender, $args[0], (int) $args[1]); 26 | } 27 | } 28 | return true; 29 | } 30 | 31 | } 32 | ``` 33 | ### Proxy Wide Chat 34 | ```php 35 | //Use the class 36 | use SunProxy\SunProxyAPI\SunProxyAPI; 37 | 38 | class Main extends \pocketmine\plugin\PluginBase implements \pocketmine\event\Listener { 39 | public function onEnable() { 40 | //Is always needed to start up Packet usage 41 | SunProxyAPI::Register(); 42 | $this->getServer()->getPluginManager()->registerEvents($this, $this); 43 | } 44 | 45 | public function onChat(\pocketmine\event\player\PlayerChatEvent $event) { 46 | SunProxyAPI::SendProxyWideChat($event->getPlayer(), $event->getFormat() . $event->getMessage()); 47 | $event->setCancelled(); 48 | } 49 | } 50 | ``` 51 | 52 | ### Proxy Chat To Certain Servers 53 | ```php 54 | //Use the class 55 | use SunProxy\SunProxyAPI\SunProxyAPI; 56 | 57 | class Main extends \pocketmine\plugin\PluginBase implements \pocketmine\event\Listener { 58 | public function onEnable() { 59 | //Is always needed to start up Packet usage 60 | SunProxyAPI::Register(); 61 | $this->getServer()->getPluginManager()->registerEvents($this, $this); 62 | } 63 | 64 | public function onChat(\pocketmine\event\player\PlayerChatEvent $event) { 65 | SunProxyAPI::SendChatToServers($event->getPlayer(), $event->getFormat() . $event->getMessage(), ["ip:port","velvetpractice.live:19132"]); 66 | $event->setCancelled(); 67 | } 68 | } 69 | ``` 70 | 71 | ### Anti Direct connect 72 | ```php 73 | //Use the class 74 | use SunProxy\SunProxyAPI\SunProxyAPI; 75 | 76 | class Main extends \pocketmine\plugin\PluginBase { 77 | 78 | public function onEnable(){ 79 | $this->getServer()->getPluginManager()->registerEvents($this, $this); 80 | } 81 | 82 | public function onPreLogin(\pocketmine\event\player\PlayerPreLoginEvent $event) { 83 | //Check if player isn't sending packets from the local addr 84 | if ($event->getPlayer()->getAddress() !== "0.0.0.0:19132") { 85 | $event->setKickMessage("You must join from the lobby!"); 86 | $event->setCancelled(); 87 | } 88 | } 89 | 90 | } 91 | ``` 92 | 93 | # License 94 | ``` 95 | ___ ___ ___ 96 | / /\ /__/\ /__/\ 97 | / /:/_ \ \:\ \ \:\ 98 | / /:/ /\ \ \:\ \ \:\ 99 | / /:/ /::\ ___ \ \:\ _____\__\:\ 100 | /__/:/ /:/\:\ /__/\ \__\:\ /__/::::::::\ 101 | \ \:\/:/~/:/ \ \:\ / /:/ \ \:\~~\~~\/ 102 | \ \::/ /:/ \ \:\ /:/ \ \:\ ~~~ 103 | \__\/ /:/ \ \:\/:/ \ \:\ 104 | /__/:/ \ \::/ \ \:\ 105 | \__\/ \__\/ \__\/ 106 | 107 | MIT License 108 | 109 | Copyright (c) 2020 Jviguy 110 | 111 | Permission is hereby granted, free of charge, to any person obtaining a copy 112 | of this software and associated documentation files (the "Software"), to deal 113 | in the Software without restriction, including without limitation the rights 114 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 115 | copies of the Software, and to permit persons to whom the Software is 116 | furnished to do so, subject to the following conditions: 117 | 118 | The above copyright notice and this permission notice shall be included in all 119 | copies or substantial portions of the Software. 120 | 121 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 122 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 123 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 124 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 125 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 126 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 127 | SOFTWARE.``` -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/AuthPacket.php: -------------------------------------------------------------------------------- 1 | putString($this->key); 27 | } 28 | 29 | /** 30 | * @inheritDoc 31 | */ 32 | public function decodePayload() 33 | { 34 | $this->key = $this->getString(); 35 | } 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | public function handle(NetworkSession $session): bool 41 | { 42 | return false; 43 | } 44 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/DisconnectPacket.php: -------------------------------------------------------------------------------- 1 | putString($this->message); 25 | } 26 | 27 | public function decodePayload() 28 | { 29 | $this->message = $this->getString(); 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | public function handle(NetworkSession $session): bool 36 | { 37 | return false; 38 | } 39 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/PlanetTextPacket.php: -------------------------------------------------------------------------------- 1 | message = $this->getString(); 25 | //Read the count 26 | $count = $this->getUnsignedVarInt(); 27 | //Read the servers 28 | for ($i = 0; $i < $count; $i++) { 29 | $this->message[] = $this->getString(); 30 | } 31 | } 32 | 33 | protected function encodePayload() { 34 | //Write Message 35 | $this->putString($this->message); 36 | //Put the count 37 | $this->putUnsignedVarInt(count($this->servers)); 38 | //Put all the servers 39 | foreach ($this->servers as $server) { 40 | $this->putString($server); 41 | } 42 | } 43 | 44 | /** 45 | * @inheritDoc 46 | */ 47 | public function handle(NetworkSession $session): bool 48 | { 49 | return false; 50 | } 51 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/PlanetTransferPacket.php: -------------------------------------------------------------------------------- 1 | address = $this->getString(); 27 | //read uint16 28 | $this->port = ((unpack("v", $this->get(2))[1])); 29 | //Read user 30 | $this->user = $this->getString(); 31 | } 32 | 33 | protected function encodePayload() { 34 | //Address 35 | $this->putString($this->address); 36 | //write uint16 to buffer 37 | ($this->buffer .= (pack("v", $this->port))); 38 | //write String into buffer 39 | $this->putString($this->user); 40 | } 41 | 42 | /** 43 | * @inheritDoc 44 | */ 45 | public function handle(NetworkSession $session): bool 46 | { 47 | return false; 48 | } 49 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/SunTextPacket.php: -------------------------------------------------------------------------------- 1 | message = $this->getString(); 60 | //Read the count 61 | $count = $this->getUnsignedVarInt(); 62 | //Read the servers 63 | for ($i = 0; $i < $count; $i++) { 64 | $this->message[] = $this->getString(); 65 | } 66 | } 67 | 68 | protected function encodePayload() { 69 | //Write Message 70 | $this->putString($this->message); 71 | //Put the count 72 | $this->putUnsignedVarInt(count($this->servers)); 73 | //Put all the servers 74 | foreach ($this->servers as $server) { 75 | $this->putString($server); 76 | } 77 | } 78 | 79 | 80 | /** 81 | * @inheritDoc 82 | */ 83 | public function handle(NetworkSession $session): bool 84 | { 85 | return false; 86 | } 87 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/SunTransferPacket.php: -------------------------------------------------------------------------------- 1 | address = $this->getString(); 63 | //read uint16 64 | $this->port = ((unpack("v", $this->get(2))[1])); 65 | } 66 | 67 | protected function encodePayload() { 68 | //Address 69 | $this->putString($this->address); 70 | //write uint16 to buffer 71 | ($this->buffer .= (pack("v", $this->port))); 72 | } 73 | 74 | /** 75 | * @inheritDoc 76 | */ 77 | public function handle(NetworkSession $session) : bool { 78 | //let client handle it as pmmp does this too 79 | return false; 80 | } 81 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/TextResponsePacket.php: -------------------------------------------------------------------------------- 1 | putByte($this->type); 29 | $this->putString($this->message); 30 | } 31 | 32 | public function decodePayload() 33 | { 34 | $this->type = $this->getByte(); 35 | $this->message = $this->getString(); 36 | } 37 | 38 | /** 39 | * @inheritDoc 40 | */ 41 | public function handle(NetworkSession $session): bool 42 | { 43 | return false; 44 | } 45 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/TransferResponsePacket.php: -------------------------------------------------------------------------------- 1 | putByte($this->type); 29 | $this->putString($this->message); 30 | } 31 | 32 | public function decodePayload() 33 | { 34 | $this->type = $this->getByte(); 35 | $this->message = $this->getString(); 36 | } 37 | 38 | /** 39 | * @inheritDoc 40 | */ 41 | public function handle(NetworkSession $session): bool 42 | { 43 | return false; 44 | } 45 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/Packets/Types/TextResponse.php: -------------------------------------------------------------------------------- 1 | $in - the buffer on the recieving side or into the client. 38 | */ 39 | private Threaded $in; 40 | 41 | /** 42 | * @var Threaded $out - the outwards buffer going out to the server. 43 | */ 44 | private Threaded $out; 45 | 46 | /** 47 | * @var bool $running - represents wether the thread / client is running. 48 | */ 49 | private bool $running; 50 | 51 | 52 | public function __construct(string $ip, int $port, string $key) 53 | { 54 | $this->ip = $ip; 55 | $this->port = $port; 56 | $this->key = $key; 57 | $this->in = new Threaded(); 58 | $this->out = new Threaded(); 59 | } 60 | 61 | public function run() 62 | { 63 | //Connect to socket. 64 | try { 65 | $fd = $this->connect(); 66 | while ($this->running) { 67 | while (($send = $this->out->shift()) !== null) { 68 | $length = strlen($send); 69 | $wrote = @socket_write($fd, Binary::writeLInt($length) . $send, 4 + $length); 70 | if ($wrote !== 4 + $length) { 71 | socket_close($fd); 72 | $fd = $this->connect(); 73 | } 74 | } 75 | } 76 | } catch (TCPSocketException $ex) { 77 | return; 78 | } 79 | } 80 | 81 | /** 82 | * @return false|resource|\Socket 83 | * @throws TCPSocketException 84 | */ 85 | public function connect() { 86 | $fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 87 | if (!$fd) { 88 | throw new TCPSocketException(socket_strerror(socket_last_error())); 89 | } 90 | $succ = socket_connect($fd, $this->ip, $this->port); 91 | if (!$succ) { 92 | throw new TCPSocketException(socket_strerror(socket_last_error())); 93 | } 94 | socket_set_nonblock($fd); 95 | return $fd; 96 | } 97 | 98 | public function start(int $options = PTHREADS_INHERIT_NONE): bool 99 | { 100 | $this->running = true; 101 | return parent::start($options); // TODO: Change the autogenerated stub 102 | } 103 | 104 | public function quit(): void 105 | { 106 | $this->running = false; 107 | parent::quit(); 108 | } 109 | 110 | public function SendPacket(DataPacket $pk) { 111 | //Encode packet 112 | $pk->encode(); 113 | $this->out[] = $pk->getBuffer(); 114 | } 115 | 116 | public function RecieveBuff(): ?string { 117 | return $this->out->shift(); 118 | } 119 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/SunProxyAPI.php: -------------------------------------------------------------------------------- 1 | address = $address; 126 | $pk->port = $port; 127 | $player->sendDataPacket($pk); 128 | } 129 | 130 | /** 131 | * @author Jviguy 132 | * 133 | * Sends a proxy wide chat through a single player node 134 | * 135 | * @param Player $player - the player to send the packet to 136 | * @param string $msg - the message to be sent 137 | */ 138 | public static function SendProxyWideChat(Player $player, string $msg) { 139 | $pk = new SunTextPacket(); 140 | $pk->message = $msg; 141 | $player->sendDataPacket($pk); 142 | } 143 | 144 | /** 145 | * @author Jviguy 146 | * 147 | * Sends a message to the said servers if there are players on it 148 | * 149 | * @param Player $player - the player to send the packet too 150 | * @param string $msg - the message to be sent 151 | * @param array $servers - an array of ips formatted like "IP:PORT" 152 | */ 153 | public static function SendChatToServers(Player $player, string $msg, array $servers) { 154 | $pk = new SunTextPacket(); 155 | $pk->message = $msg; 156 | $pk->servers = $servers; 157 | $player->sendDataPacket($pk); 158 | } 159 | } -------------------------------------------------------------------------------- /src/SunProxy/SunProxyAPI/TCPSocketException.php: -------------------------------------------------------------------------------- 1 |