Skip to content

Commit 0ced272

Browse files
author
Falkirks
committed
Temp fix to BuyCraft API issues
1 parent 58aa675 commit 0ced272

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: BuyCraft
22
main: buycraft\BuyCraft
3-
version: 1.1
3+
version: 1.2
44
author: Falk
55
api: [1.0.0]
66
load: POSTWORLD

src/buycraft/api/ApiAsyncTask.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace buycraft\api;
33

44
use buycraft\BuyCraft;
5+
use buycraft\util\HTTPUtils;
56
use pocketmine\command\CommandSender;
67
use pocketmine\command\ConsoleCommandSender;
78
use pocketmine\Player;
@@ -64,7 +65,7 @@ public function setData(array $data){
6465
public function send(){
6566
$data = $this->getData();
6667
if($this->isAuthenticated || $data["action"] === Actions::AUTHENTICATE){
67-
$this->output = serialize(json_decode(Utils::getURL($this->apiUrl . "?" . http_build_query($data)), true));
68+
$this->output = serialize(json_decode(HTTPUtils::getURL($this->apiUrl . "?" . http_build_query($data)), true));
6869
}
6970
else{
7071
$this->output = false;

src/buycraft/api/ApiTask.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace buycraft\api;
33
use buycraft\BuyCraft;
4+
use buycraft\util\HTTPUtils;
45
use pocketmine\Player;
56
use pocketmine\scheduler\PluginTask;
67
use pocketmine\utils\Utils;
@@ -39,7 +40,7 @@ public function send(){
3940
if($this->getOwner()->isAuthenticated()){
4041
$this->data["secret"] = $this->getOwner()->getConfig()->get('secret');
4142
$this->data["playersOnline"] = count($this->getOwner()->getServer()->getOnlinePlayers());
42-
return json_decode(Utils::getURL($this->apiUrl . "?" . http_build_query($this->getData())), true);
43+
return json_decode(HTTPUtils::getURL($this->apiUrl . "?" . http_build_query($this->getData())), true);
4344
}
4445
else{
4546
return false;

src/buycraft/commands/BuyCraftCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function execute(CommandSender $sender, $label, array $args){
6363
break;
6464
case 'report':
6565
$sender->sendMessage("BuyCraft for PocketMine does not support report generation. If the plugin crashes just alert me on GitHub or the PocketMine forums with a link to the crash report.");
66+
6667
break;
6768
default:
6869
$sender->sendMessage($this->getUsage());

src/buycraft/util/HTTPUtils.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace buycraft\util;
3+
4+
use pocketmine\utils\Utils;
5+
6+
class HTTPUtils{
7+
public static function getURL($page, $timeout = 10){
8+
if(Utils::$online === false){
9+
return false;
10+
}
11+
12+
$ch = curl_init($page);
13+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
14+
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP",
15+
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
16+
"Accept-Language: en-us",
17+
"Accept-Encoding: gzip, deflate"
18+
]);
19+
curl_setopt($ch, CURLOPT_COOKIESESSION, true );
20+
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
21+
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
22+
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
23+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
24+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
25+
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
26+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
27+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
28+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout);
30+
$ret = curl_exec($ch);
31+
curl_close($ch);
32+
33+
return $ret;
34+
}
35+
}

src/buycraft/util/ReportFile.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace buycraft\util;
3+
4+
5+
use pocketmine\Server;
6+
7+
class ReportFile{
8+
protected $content;
9+
protected $path;
10+
public function __construct($path){
11+
$this->path = $path;
12+
$this->content = [];
13+
}
14+
public function generate(){
15+
$server = Server::getInstance();
16+
$this->content["pocketmine"] = ["version" => $server->getPocketMineVersion(), "api" => $server->getApiVersion()];
17+
}
18+
public function save() {
19+
file_put_contents($this->path, json_encode($this->content));
20+
}
21+
}

0 commit comments

Comments
 (0)