mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Whitelist, Banned IPs, more properties
This commit is contained in:
parent
46c7e7860e
commit
842e01ffac
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
*.log
|
||||
*.bat
|
||||
server.properties
|
||||
white-list.txt
|
||||
banned-ips.txt
|
||||
|
||||
#################
|
||||
## Eclipse
|
||||
|
@ -40,6 +40,8 @@ class PocketMinecraftServer{
|
||||
$this->eidCnt = 1;
|
||||
$this->maxClients = 20;
|
||||
$this->description = "";
|
||||
$this->whitelist = false;
|
||||
$this->bannedIPs = array();
|
||||
$this->motd = "Welcome to ".$name;
|
||||
$this->serverID = $serverID === false ? Utils::readLong(Utils::getRandomBytes(8)):$serverID;
|
||||
$this->seed = $seed === false ? Utils::readInt(Utils::getRandomBytes(4)):((int) $seed);
|
||||
@ -51,6 +53,7 @@ class PocketMinecraftServer{
|
||||
//$this->event("onTick", "onTick", true);
|
||||
$this->event("onChat", "eventHandler", true);
|
||||
$this->action(1000000, '$this->time += 10;$this->trigger("onTimeChange", $this->time);');
|
||||
$this->action(1000000 * 60, '$this->reloadConfig();');
|
||||
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
||||
$this->setType("normal");
|
||||
$this->interface = new MinecraftInterface("255.255.255.255", $this->protocol, $this->port, true, false);
|
||||
@ -58,6 +61,7 @@ class PocketMinecraftServer{
|
||||
$this->action(1000000 * 3 * 60, '$this->chat(false, "This server uses Pocket-Minecraft-PHP");');
|
||||
sleep(2);
|
||||
$this->action(1000000 * 3 * 60, '$this->chat(false, "Check it at http://bit.ly/RE7uaW");');
|
||||
$this->reloadConfig();
|
||||
console("[INFO] Server Name: ".$this->name);
|
||||
console("[INFO] Server GUID: ".$this->serverID);
|
||||
console("[INFO] Protocol Version: ".$this->protocol);
|
||||
@ -67,6 +71,13 @@ class PocketMinecraftServer{
|
||||
$this->stop = false;
|
||||
}
|
||||
|
||||
public function reloadConfig(){
|
||||
if($this->whitelist === true or is_array($this->whitelist)){
|
||||
$this->whitelist = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt")));
|
||||
}
|
||||
$this->bannedIPs = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."banned-ips.txt")));
|
||||
}
|
||||
|
||||
public function close($reason = "stop"){
|
||||
$this->chat(false, "Stopping server...");
|
||||
$this->stop = true;
|
||||
@ -139,6 +150,9 @@ class PocketMinecraftServer{
|
||||
}else{
|
||||
switch($packet["pid"]){
|
||||
case 0x02:
|
||||
if(in_array($packet["ip"], $this->bannedIPs)){
|
||||
break;
|
||||
}
|
||||
if(!isset($this->custom["times_".$CID])){
|
||||
$this->custom["times_".$CID] = 0;
|
||||
}
|
||||
@ -154,6 +168,9 @@ class PocketMinecraftServer{
|
||||
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
|
||||
break;
|
||||
case 0x05:
|
||||
if(in_array($packet["ip"], $this->bannedIPs)){
|
||||
break;
|
||||
}
|
||||
if(count($this->clients) >= $this->maxClients){
|
||||
break;
|
||||
}
|
||||
@ -175,6 +192,9 @@ class PocketMinecraftServer{
|
||||
}
|
||||
break;
|
||||
case 0x07:
|
||||
if(in_array($packet["ip"], $this->bannedIPs)){
|
||||
break;
|
||||
}
|
||||
if(count($this->clients) >= $this->maxClients){
|
||||
break;
|
||||
}
|
||||
|
@ -52,13 +52,15 @@ class Session{
|
||||
}
|
||||
}
|
||||
|
||||
public function close($reason = "server stop"){
|
||||
public function close($reason = "server stop", $msg = true){
|
||||
foreach($this->evid as $ev){
|
||||
$this->server->deleteEvent($ev[0], $ev[1]);
|
||||
}
|
||||
$this->connected = false;
|
||||
$this->server->trigger("onChat", $this->username." left the game");
|
||||
console("[DEBUG] Session with ".$this->ip.":".$this->port." closed due to ".$reason, true, true, 2);
|
||||
if($msg === true){
|
||||
$this->server->trigger("onChat", $this->username." left the game");
|
||||
}
|
||||
console("[INFO] Session with ".$this->ip.":".$this->port." closed due to ".$reason);
|
||||
unset($this->server->clients[$this->CID]);
|
||||
}
|
||||
|
||||
@ -132,6 +134,10 @@ class Session{
|
||||
break;
|
||||
case MC_LOGIN:
|
||||
$this->username = $data["username"];
|
||||
if($this->server->whitelist !== false and !in_array($this->username, $this->server->whitelist)){
|
||||
$this->close("\"".$this->username."\" not being on white-list", false);
|
||||
break;
|
||||
}
|
||||
console("[INFO] Player \"".$this->username."\" connected from ".$this->ip.":".$this->port);
|
||||
$this->evid[] = array("onTimeChange", $this->server->event("onTimeChange", array($this, "eventHandler")));
|
||||
$this->evid[] = array("onChat", $this->server->event("onChat", array($this, "eventHandler")));
|
||||
|
@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
require_once("common/dependencies.php");
|
||||
require_once("classes/PocketMinecraftClient.class.php");
|
||||
file_put_contents("packets.log", "");
|
||||
define("DEBUG", 2);
|
||||
|
||||
$client = new PocketMinecraftClient("shoghicp");
|
||||
console("[INFO] Searching servers...");
|
||||
|
@ -34,6 +34,5 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH . PATH_SEPARATO
|
||||
ini_set("memory_limit", "512M");
|
||||
define("CURRENT_PROTOCOL", 5);
|
||||
define("CURRENT_VERSION", 1);
|
||||
define("DEBUG", 2);
|
||||
define("LOG", true);
|
||||
define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78");
|
@ -9,5 +9,7 @@ seed=false
|
||||
server-id=false
|
||||
server-type=normal
|
||||
max-players=20
|
||||
white-list=false
|
||||
debug=1
|
||||
spawn=128.5;100;128.5
|
||||
regenerate-config=true
|
22
server.php
22
server.php
@ -30,12 +30,22 @@ require_once("classes/PocketMinecraftServer.class.php");
|
||||
file_put_contents("packets.log", "");
|
||||
file_put_contents("console.log", "");
|
||||
|
||||
$prop = @file_get_contents(FILE_PATH."server.properties");
|
||||
if(trim($prop) == ""){
|
||||
if(!file_exists(FILE_PATH."white-list.txt")){
|
||||
console("[WARNING] No white-list.txt found, creating blank file");
|
||||
file_put_contents(FILE_PATH."white-list.txt", "");
|
||||
}
|
||||
|
||||
if(!file_exists(FILE_PATH."banned-ips.txt")){
|
||||
console("[WARNING] No banned-ips.txt found, creating blank file");
|
||||
file_put_contents(FILE_PATH."banned-ips.txt", "");
|
||||
}
|
||||
|
||||
if(!file_exists(FILE_PATH."server.properties")){
|
||||
console("[WARNING] No server.properties found, using default settings");
|
||||
copy(FILE_PATH."common/default.properties", FILE_PATH."server.properties");
|
||||
$prop = file_get_contents(FILE_PATH."server.properties");
|
||||
|
||||
}
|
||||
$prop = file_get_contents(FILE_PATH."server.properties");
|
||||
$prop = explode("\n", str_replace("\r", "", $prop));
|
||||
$config = array();
|
||||
foreach($prop as $line){
|
||||
@ -54,6 +64,7 @@ foreach($prop as $line){
|
||||
case "gamemode":
|
||||
case "max-players":
|
||||
case "port":
|
||||
case "debug":
|
||||
$v = (int) $v;
|
||||
break;
|
||||
case "seed":
|
||||
@ -64,23 +75,28 @@ foreach($prop as $line){
|
||||
$v = explode(";", $v);
|
||||
$v = array("x" => floatval($v[0]), "y" => floatval($v[1]), "z" => floatval($v[2]));
|
||||
break;
|
||||
case "white-list":
|
||||
case "regenerate-config":
|
||||
$v = trim($v) == "true" ? true:false;
|
||||
break;
|
||||
}
|
||||
$config[$n] = $v;
|
||||
}
|
||||
define("DEBUG", $config["debug"]);
|
||||
|
||||
$server = new PocketMinecraftServer($config["server-name"], $config["gamemode"], $config["seed"], $config["protocol"], $config["port"], $config["server-id"]);
|
||||
$server->setType($config["type"]);
|
||||
$server->maxClients = $config["max-players"];
|
||||
$server->description = $config["description"];
|
||||
$server->motd = $config["motd"];
|
||||
$server->whitelist = $config["white-list"];
|
||||
$server->reloadConfig();
|
||||
|
||||
if($config["regenerate-config"] == true){
|
||||
$config["seed"] = $server->seed;
|
||||
$config["server-id"] = $server->serverID;
|
||||
$config["regenerate-config"] = "false";
|
||||
$config["white-list"] = $config["whitelist"] === true ? "true":"false";
|
||||
$config["spawn"] = implode(";", $config["spawn"]);
|
||||
$prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n";
|
||||
foreach($config as $n => $v){
|
||||
|
Loading…
x
Reference in New Issue
Block a user