forked from ugamer333/PocketMine-Realms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPMRealms.php
70 lines (65 loc) · 3 KB
/
PMRealms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
__PocketMine Plugin__
name=PocketMine Realms
description=Automatic server listing on PocketMine Realms and more features.
version=0.1
author=shoghicp
class=PMRealms
apiversion=9
*/
class PMRealms implements Plugin{
private $api, $server, $config;
public function __construct(ServerAPI $api, $server = false){
$this->api = $api;
$this->server = ServerAPI::request();
}
public function init(){
$this->config = new Config($this->api->plugin->configPath($this)."config.yml", CONFIG_YAML, array(
"ownerName" => "",
));
$error = 0;
if($this->config->get("ownerName") == ""){
console("[ERROR] [Realms] Please set your ownerName to your Realms name.");
++$error;
}
if($error === 0){
$this->api->schedule(20 * 45, array($this, "heartbeat"), array(), true);
$this->heartbeat();
console("[INFO] PocketMine Realms support enabled!");
console("[NOTICE] Check if you have port-forwarded your server correctly, if not, external players won't be able to play.");
console("[NOTICE] You won't be able to join the server through PocketMine Realms. Join it on the Play menu (like Local servers).");
}else{
console("[ERROR] PocketMine Realms not enabled. Please configure the plugin properly.");
}
}
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
}
return $output;
}
public function getIP(){
$this->ip = Utils::curl_get("http://ifconfig.me/ip");
$repl = array("\r", "\n", " ");
return str_replace($repl, "", $this->ip);
}
public function heartbeat(){
$this->api->asyncOperation(ASYNC_CURL_POST, array(
"url" => "http://peoapi.pocketmine.net/server/heartbeat",
"data" => array(
"ip" => $this->getIP(),
"port" => (int) $this->server->api->getProperty("server-port"),
"ownerName" => $this->config->get("ownerName"),
"name" => $this->server->name,
"maxNrPlayers" => $this->server->maxClients,
"nrPlayers" => count($this->api->player->getAll()),
"type" => ($this->server->api->getProperty("gamemode") & 0x01) === 1 ? "creative":"survival",
"whitelist" => $this->server->api->getProperty("white-list"),
),
));
}
public function __destruct(){
$this->config->save();
}
}