mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Fix for timings
This commit is contained in:
parent
4a1ed21e52
commit
a97c7d3132
@ -98,21 +98,33 @@ class TimingsCommand extends VanillaCommand{
|
|||||||
if($paste){
|
if($paste){
|
||||||
fseek($fileTimings, 0);
|
fseek($fileTimings, 0);
|
||||||
$data = [
|
$data = [
|
||||||
"syntax" => "text",
|
"browser" => $agent = $sender->getServer()->getName() . " " . $sender->getServer()->getPocketMineVersion(),
|
||||||
"poster" => $sender->getServer()->getName(),
|
"data" => $content = stream_get_contents($fileTimings)
|
||||||
"content" => stream_get_contents($fileTimings)
|
|
||||||
];
|
];
|
||||||
fclose($fileTimings);
|
fclose($fileTimings);
|
||||||
|
|
||||||
|
$host = $sender->getServer()->getProperty("timings.host", "timings.pmmp.io");
|
||||||
|
|
||||||
$sender->getServer()->getAsyncPool()->submitTask(new class([
|
$sender->getServer()->getAsyncPool()->submitTask(new class([
|
||||||
["page" => "http://paste.ubuntu.com", "extraOpts" => [
|
["page" => "https://$host?upload=true", "extraOpts" => [
|
||||||
CURLOPT_HTTPHEADER => ["User-Agent: " . $sender->getServer()->getName() . " " . $sender->getServer()->getPocketMineVersion()],
|
CURLOPT_HTTPHEADER => [
|
||||||
CURLOPT_POST => 1,
|
"User-Agent: $agent",
|
||||||
CURLOPT_POSTFIELDS => $data,
|
"Content-Type: application/x-www-form-urlencoded"
|
||||||
|
],
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_POSTFIELDS => http_build_query($data),
|
||||||
CURLOPT_AUTOREFERER => false,
|
CURLOPT_AUTOREFERER => false,
|
||||||
CURLOPT_FOLLOWLOCATION => 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){
|
public function onCompletion(Server $server){
|
||||||
$sender = $this->fetchLocal();
|
$sender = $this->fetchLocal();
|
||||||
if($sender instanceof Player and !$sender->isOnline()){ // TODO replace with a more generic API method for checking availability of CommandSender
|
if($sender instanceof Player and !$sender->isOnline()){ // TODO replace with a more generic API method for checking availability of CommandSender
|
||||||
@ -123,17 +135,12 @@ class TimingsCommand extends VanillaCommand{
|
|||||||
$server->getLogger()->logException($result);
|
$server->getLogger()->logException($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list(, $headers) = $result;
|
if(isset($result[0]) && is_array($response = json_decode($result[0], true)) && isset($response["id"])){
|
||||||
foreach($headers as $headerGroup){
|
$pasteId = $response["id"];
|
||||||
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($pasteId)){
|
if(isset($pasteId)){
|
||||||
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsUpload", ["http://paste.ubuntu.com/" . $pasteId . "/"]));
|
|
||||||
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead",
|
$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{
|
}else{
|
||||||
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.pasteError"));
|
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.pasteError"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user