Allow binding to an specific IP

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-04 22:37:56 +01:00
parent 6839001dc3
commit ac6c3c7e69
4 changed files with 11 additions and 9 deletions

View File

@ -86,6 +86,7 @@ class ServerAPI{
"description" => "Server made using PocketMine-MP", "description" => "Server made using PocketMine-MP",
"motd" => "Welcome @username to this server!", "motd" => "Welcome @username to this server!",
"invisible" => false, "invisible" => false,
"server-ip" => "0.0.0.0",
"port" => 19132, "port" => 19132,
"memory-limit" => "256M", "memory-limit" => "256M",
"last-update" => false, "last-update" => false,
@ -106,7 +107,7 @@ class ServerAPI{
)); ));
$this->parseProperties(); $this->parseProperties();
define("DEBUG", $this->getProperty("debug")); define("DEBUG", $this->getProperty("debug"));
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id")); $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, $this->getProperty("port"), $this->getProperty("server-id"), $this->getProperty("server-ip"));
$this->setProperty("server-id", $this->server->serverID); $this->setProperty("server-id", $this->server->serverID);
$this->server->api = $this; $this->server->api = $this;
if($this->getProperty("upnp-forwarding") === true){ if($this->getProperty("upnp-forwarding") === true){

View File

@ -28,7 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class PocketMinecraftServer{ class PocketMinecraftServer{
public $tCnt; public $tCnt;
var $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $spawn, $entities, $mapDir, $mapName, $map, $levelData, $tileEntities; var $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $spawn, $entities, $mapDir, $mapName, $map, $levelData, $tileEntities;
private $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticker; private $serverip, $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticker;
private function load(){ private function load(){
$this->version = new VersionString(); $this->version = new VersionString();
@ -37,7 +37,7 @@ class PocketMinecraftServer{
if($this->version->isDev()){ if($this->version->isDev()){
console("[INFO] \x1b[31;1mThis is a Development version"); console("[INFO] \x1b[31;1mThis is a Development version");
} }
console("[INFO] Starting Minecraft PE Server at *:".$this->port); console("[INFO] Starting Minecraft PE Server at ".$this->serverip.":".$this->port);
if($this->port < 19132 or $this->port > 19135){ if($this->port < 19132 or $this->port > 19135){
console("[WARNING] You've selected a not-standard port. Normal port range is from 19132 to 19135 included"); console("[WARNING] You've selected a not-standard port. Normal port range is from 19132 to 19135 included");
} }
@ -81,13 +81,14 @@ class PocketMinecraftServer{
$this->stop = false; $this->stop = false;
} }
function __construct($name, $gamemode = 1, $seed = false, $port = 19132, $serverID = false){ function __construct($name, $gamemode = 1, $seed = false, $port = 19132, $serverID = false, $serverip = "0.0.0.0"){
$this->port = (int) $port; //19132 - 19135 $this->port = (int) $port; //19132 - 19135
$this->gamemode = (int) $gamemode; $this->gamemode = (int) $gamemode;
$this->name = $name; $this->name = $name;
$this->motd = "Welcome to ".$name; $this->motd = "Welcome to ".$name;
$this->serverID = $serverID; $this->serverID = $serverID;
$this->seed = $seed; $this->seed = $seed;
$this->serverip = $serverip;
$this->load(); $this->load();
} }

View File

@ -32,8 +32,8 @@ class MinecraftInterface{
var $dataName; var $dataName;
private $socket; private $socket;
private $data; private $data;
function __construct($server, $port = 25565, $listen = false, $client = true){ function __construct($server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){
$this->socket = new UDPSocket($server, $port, (bool) $listen); $this->socket = new UDPSocket($server, $port, (bool) $listen, $serverip);
require("protocol/RakNet.php"); require("protocol/RakNet.php");
require("protocol/packetName.php"); require("protocol/packetName.php");
require("protocol/current.php"); require("protocol/current.php");

View File

@ -30,7 +30,7 @@ the Free Software Foundation, either version 3 of the License, or
class UDPSocket{ class UDPSocket{
private $encrypt; private $encrypt;
var $buffer, $connected, $errors, $sock, $server; var $buffer, $connected, $errors, $sock, $server;
function __construct($server, $port, $listen = false){ function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){
$this->errors = array_fill(88,(125 - 88) + 1, true); $this->errors = array_fill(88,(125 - 88) + 1, true);
$this->server = $server; $this->server = $server;
$this->port = $port; $this->port = $port;
@ -41,10 +41,10 @@ class UDPSocket{
$this->buffer = array(); $this->buffer = array();
$this->unblock(); $this->unblock();
}else{ }else{
if(socket_bind($this->sock, "0.0.0.0", $port) === true){ if(socket_bind($this->sock, $serverip, $port) === true){
$this->unblock(); $this->unblock();
}else{ }else{
console("[ERROR] Couldn't bind to 0.0.0.0:".$port, true, true, 0); console("[ERROR] Couldn't bind to $serverip:".$port, true, true, 0);
die(); die();
} }
} }