Limited RCON threads to one and added a auth timeout

This commit is contained in:
Shoghi Cervantes Pueyo 2013-04-22 23:33:46 +02:00
parent f466e1f791
commit e428b4cfc4
4 changed files with 29 additions and 18 deletions

View File

@ -99,7 +99,7 @@ class BanAPI{
if($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->iusername)){
return true;
}
}elseif($data["issuer"] === "console"){
}elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
return true;
}
return false;

View File

@ -34,6 +34,7 @@ class ChatAPI{
public function init(){
$this->server->api->console->register("tell", "<player> <private message ...>", array($this, "commandHandler"));
$this->server->api->console->register("me", "<action ...>", array($this, "commandHandler"));
$this->server->api->console->register("say", "<message ...>", array($this, "commandHandler"));
$this->server->api->ban->cmdWhitelist("tell");
$this->server->api->ban->cmdWhitelist("me");
}
@ -41,9 +42,22 @@ class ChatAPI{
public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){
case "say":
$s = implode(" ", $params);
if(trim($s) == ""){
$output .= "Usage: /say <message>\n";
break;
}
$sender = ($issuer instanceof Player) ? "Server":ucfirst($issuer);
$this->server->api->chat->broadcast("[$sender] ".$s);
break;
case "me":
if(!($issuer instanceof Player)){
$sender = "Console";
if($issuer === "rcon"){
$sender = "Rcon";
}else{
$sender = "Console";
}
}else{
$sender = $issuer->username;
}
@ -55,7 +69,7 @@ class ChatAPI{
break;
}
if(!($issuer instanceof Player)){
$sender = "Console";
$sender = ucfirst($issuer);
}else{
$sender = $issuer->username;
}
@ -65,7 +79,7 @@ class ChatAPI{
$target = $target->username;
}else{
$target = strtolower($n);
if($target === "server" or $target === "console"){
if($target === "server" or $target === "console" or $target === "rcon"){
$target = "Console";
}else{
$output .= "Usage: /$cmd <player> <message>\n";
@ -74,7 +88,7 @@ class ChatAPI{
}
$mes = implode(" ", $params);
$output .= "[me -> ".$target."] ".$mes."\n";
if($target !== "Console"){
if($target !== "Console" and $target !== "Rcon"){
$this->sendTo(false, "[".$sender." -> me] ".$mes, $target);
}
console("[INFO] [".$sender." -> ".$target."] ".$mes);

View File

@ -42,7 +42,6 @@ class ConsoleAPI{
$this->register("status", "", array($this, "defaultCommands"));
$this->register("difficulty", "<0|1>", array($this, "defaultCommands"));
$this->register("invisible", "<on|off>", array($this, "defaultCommands"));
$this->register("say", "<message ...>", array($this, "defaultCommands"));
$this->register("save-all", "", array($this, "defaultCommands"));
$this->register("stop", "", array($this, "defaultCommands"));
$this->register("defaultgamemode", "<mode>", array($this, "defaultCommands"));
@ -128,20 +127,12 @@ class ConsoleAPI{
$this->server->api->setProperty("difficulty", (int) $s);
$output .= "Difficulty changed to ".$this->server->difficulty."\n";
break;
case "say":
$s = implode(" ", $params);
if(trim($s) == ""){
$output .= "Usage: /say <message>\n";
break;
}
$this->server->api->chat->broadcast("[Server] ".$s);
break;
case "save-all":
$this->server->save();
break;
case "?":
if($issuer !== "console"){
if($issuer !== "console" and $issuer !== "rcon"){
break;
}
case "help":

View File

@ -30,7 +30,7 @@ the Free Software Foundation, either version 3 of the License, or
class RCON{
private $socket, $password, $workers, $threads;
public function __construct($password, $port = 19132, $interface = "0.0.0.0", $threads = 4, $clientsPerThread = 25){
public function __construct($password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
$this->workers = array();
$this->password = (string) $password;
console("[INFO] Starting remote control listener");
@ -72,7 +72,7 @@ class RCON{
console($this->workers[$n]->response);
$this->workers[$n]->notify();
}else{
$this->workers[$n]->response = ServerAPI::request()->api->console->run($this->workers[$n]->cmd, "console");
$this->workers[$n]->response = ServerAPI::request()->api->console->run($this->workers[$n]->cmd, "rcon");
$this->workers[$n]->notify();
}
}
@ -90,7 +90,7 @@ class RCONInstance extends Thread{
private $status;
private $maxClients;
public function __construct($socket, $password, $maxClients = 5){
public function __construct($socket, $password, $maxClients = 50){
$this->stop = false;
$this->cmd = "";
$this->response = "";
@ -100,6 +100,7 @@ class RCONInstance extends Thread{
for($n = 0; $n < $this->maxClients; ++$n){
$this->{"client".$n} = null;
$this->{"status".$n} = 0;
$this->{"timeout".$n} = 0;
}
$this->status = array();
$this->start();
@ -145,6 +146,7 @@ class RCONInstance extends Thread{
if($this->{"client".$n} === null){
$this->{"client".$n} = $client;
$this->{"status".$n} = 0;
$this->{"timeout".$n} = microtime(true) + 5;
$done = true;
break;
}
@ -158,6 +160,10 @@ class RCONInstance extends Thread{
$client = &$this->{"client".$n};
if($client !== null){
if($this->{"status".$n} !== -1 and $this->stop !== true){
if($this->{"status".$n} === 0 and $this->{"timeout".$n} < microtime(true)){ //Timeout
$this->{"status".$n} = -1;
continue;
}
$p = $this->readPacket($client, $size, $requestID, $packetType, $payload);
if($p === false){
$this->{"status".$n} = -1;