Added optional Windows UPnP port forwading

This commit is contained in:
Shoghi Cervantes Pueyo
2013-01-06 21:19:39 +01:00
parent 21594d699d
commit 89c0702a47
2 changed files with 70 additions and 0 deletions

View File

@@ -90,6 +90,10 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
define("DEBUG", $this->config["debug"]);
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id"));
$this->server->api = $this;
if($this->getProperty("upnp-forwading") === true ){
console("[INFO] [UPnP] Trying to port forward...");
UPnP_PortForward($this->getProperty("port"));
}
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
console("[INFO] Checking for new server version");
console("[INFO] Last check: ".date("Y-m-d H:i:s", $this->getProperty("last-update")));
@@ -236,6 +240,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$config = $this->config;
$config["white-list"] = $config["white-list"] === true ? "true":"false";
$config["invisible"] = $config["invisible"] === true ? "true":"false";
$config["upnp-forwading"] = $config["upnp-forwading"] === true ? "true":"false";
$prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n";
foreach($config as $n => $v){
$prop .= $n."=".$v."\r\n";
@@ -297,6 +302,10 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
unregister_tick_function(array($this->server, "tick"));
$this->__destruct();
unset($this->server);
if($this->getProperty("upnp-forwading") === true ){
console("[INFO] [UPnP] Removing port forward...");
UPnP_RemovePortForward($this->getProperty("port"));
}
return $this->restart;
}