diff --git a/src/pocketmine/command/defaults/TimingsCommand.php b/src/pocketmine/command/defaults/TimingsCommand.php index 3ca5d920fc6..29be494226c 100644 --- a/src/pocketmine/command/defaults/TimingsCommand.php +++ b/src/pocketmine/command/defaults/TimingsCommand.php @@ -98,21 +98,33 @@ public function execute(CommandSender $sender, string $commandLabel, array $args if($paste){ fseek($fileTimings, 0); $data = [ - "syntax" => "text", - "poster" => $sender->getServer()->getName(), - "content" => stream_get_contents($fileTimings) + "browser" => $agent = $sender->getServer()->getName() . " " . $sender->getServer()->getPocketMineVersion(), + "data" => $content = stream_get_contents($fileTimings) ]; fclose($fileTimings); + $host = $sender->getServer()->getProperty("timings.host", "timings.pmmp.io"); + $sender->getServer()->getAsyncPool()->submitTask(new class([ - ["page" => "http://paste.ubuntu.com", "extraOpts" => [ - CURLOPT_HTTPHEADER => ["User-Agent: " . $sender->getServer()->getName() . " " . $sender->getServer()->getPocketMineVersion()], - CURLOPT_POST => 1, - CURLOPT_POSTFIELDS => $data, + ["page" => "https://$host?upload=true", "extraOpts" => [ + CURLOPT_HTTPHEADER => [ + "User-Agent: $agent", + "Content-Type: application/x-www-form-urlencoded" + ], + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => http_build_query($data), CURLOPT_AUTOREFERER => false, CURLOPT_FOLLOWLOCATION => false ]] - ], $sender) extends BulkCurlTask{ + ], $sender, $host) extends BulkCurlTask{ + /** @var string */ + private $host; + + public function __construct(array $operations, $complexData = null, string $host){ + parent::__construct($operations, $complexData); + $this->host = $host; + } + public function onCompletion(Server $server){ $sender = $this->fetchLocal(); if($sender instanceof Player and !$sender->isOnline()){ // TODO replace with a more generic API method for checking availability of CommandSender @@ -123,17 +135,12 @@ public function onCompletion(Server $server){ $server->getLogger()->logException($result); return; } - list(, $headers) = $result; - foreach($headers as $headerGroup){ - if(isset($headerGroup["location"]) and preg_match('#^http://paste\\.ubuntu\\.com/([A-Za-z0-9+\/=]+)/#', trim($headerGroup["location"]), $match)){ - $pasteId = $match[1]; - break; - } + if(isset($result[0]) && is_array($response = json_decode($result[0], true)) && isset($response["id"])){ + $pasteId = $response["id"]; } if(isset($pasteId)){ - $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsUpload", ["http://paste.ubuntu.com/" . $pasteId . "/"])); $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead", - ["http://" . $sender->getServer()->getProperty("timings.host", "timings.pmmp.io") . "/?url=" . urlencode($pasteId)])); + ["https://" . $this->host . "/?id=" . $pasteId])); }else{ $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.pasteError")); }