mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
More typehints, documentation fixes and static analysis cleanup
This commit is contained in:
@ -32,7 +32,7 @@ interface AdvancedSourceInterface extends SourceInterface{
|
||||
* @param string $address
|
||||
* @param int $timeout Seconds
|
||||
*/
|
||||
public function blockAddress($address, $timeout = 300);
|
||||
public function blockAddress(string $address, int $timeout = 300);
|
||||
|
||||
/**
|
||||
* @param Network $network
|
||||
@ -44,6 +44,6 @@ interface AdvancedSourceInterface extends SourceInterface{
|
||||
* @param int $port
|
||||
* @param string $payload
|
||||
*/
|
||||
public function sendRawPacket($address, $port, $payload);
|
||||
public function sendRawPacket(string $address, int $port, string $payload);
|
||||
|
||||
}
|
@ -45,6 +45,7 @@ class Network{
|
||||
private $upload = 0;
|
||||
private $download = 0;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
public function __construct(Server $server){
|
||||
@ -75,7 +76,7 @@ class Network{
|
||||
/**
|
||||
* @return SourceInterface[]
|
||||
*/
|
||||
public function getInterfaces(){
|
||||
public function getInterfaces() : array{
|
||||
return $this->interfaces;
|
||||
}
|
||||
|
||||
@ -121,14 +122,17 @@ class Network{
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name){
|
||||
$this->name = (string) $name;
|
||||
public function setName(string $name){
|
||||
$this->name = $name;
|
||||
foreach($this->interfaces as $interface){
|
||||
$interface->setName($this->name);
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName() : string{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
@ -138,7 +142,10 @@ class Network{
|
||||
}
|
||||
}
|
||||
|
||||
public function getServer(){
|
||||
/**
|
||||
* @return Server
|
||||
*/
|
||||
public function getServer() : Server{
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
@ -147,7 +154,7 @@ class Network{
|
||||
* @param int $port
|
||||
* @param string $payload
|
||||
*/
|
||||
public function sendPacket($address, $port, $payload){
|
||||
public function sendPacket(string $address, int $port, string $payload){
|
||||
foreach($this->advancedInterfaces as $interface){
|
||||
$interface->sendRawPacket($address, $port, $payload);
|
||||
}
|
||||
@ -159,7 +166,7 @@ class Network{
|
||||
* @param string $address
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function blockAddress($address, $timeout = 300){
|
||||
public function blockAddress(string $address, int $timeout = 300){
|
||||
foreach($this->advancedInterfaces as $interface){
|
||||
$interface->blockAddress($address, $timeout);
|
||||
}
|
||||
|
@ -44,16 +44,15 @@ interface SourceInterface{
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = true);
|
||||
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true);
|
||||
|
||||
/**
|
||||
* Terminates the connection
|
||||
*
|
||||
* @param Player $player
|
||||
* @param string $reason
|
||||
*
|
||||
*/
|
||||
public function close(Player $player, $reason = "unknown reason");
|
||||
public function close(Player $player, string $reason = "unknown reason");
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
@ -63,7 +62,7 @@ interface SourceInterface{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function process();
|
||||
public function process() : bool;
|
||||
|
||||
public function shutdown();
|
||||
|
||||
|
@ -75,7 +75,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
||||
$this->network = $network;
|
||||
}
|
||||
|
||||
public function process(){
|
||||
public function process() : bool{
|
||||
$work = false;
|
||||
if($this->interface->handlePacket()){
|
||||
$work = true;
|
||||
@ -102,7 +102,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
||||
}
|
||||
}
|
||||
|
||||
public function close(Player $player, $reason = "unknown reason"){
|
||||
public function close(Player $player, string $reason = "unknown reason"){
|
||||
if(isset($this->identifiers[$h = spl_object_hash($player)])){
|
||||
unset($this->players[$this->identifiers[$h]]);
|
||||
unset($this->identifiersACK[$this->identifiers[$h]]);
|
||||
@ -148,7 +148,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
||||
}
|
||||
}
|
||||
|
||||
public function blockAddress($address, $timeout = 300){
|
||||
public function blockAddress(string $address, int $timeout = 300){
|
||||
$this->interface->blockAddress($address, $timeout);
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
||||
$this->server->handlePacket($address, $port, $payload);
|
||||
}
|
||||
|
||||
public function sendRawPacket($address, $port, $payload){
|
||||
public function sendRawPacket(string $address, int $port, string $payload){
|
||||
$this->interface->sendRaw($address, $port, $payload);
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
||||
}
|
||||
}
|
||||
|
||||
public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = false){
|
||||
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true){
|
||||
if(isset($this->identifiers[$h = spl_object_hash($player)])){
|
||||
$identifier = $this->identifiers[$h];
|
||||
if(!$packet->isEncoded){
|
||||
|
@ -41,10 +41,9 @@ class RCON{
|
||||
private $workers = [];
|
||||
private $clientsPerThread;
|
||||
|
||||
public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
|
||||
public function __construct(Server $server, string $password, int $port = 19132, string $interface = "0.0.0.0", int $threads = 1, int $clientsPerThread = 50){
|
||||
$this->server = $server;
|
||||
$this->workers = [];
|
||||
$this->password = (string) $password;
|
||||
$this->password = $password;
|
||||
$this->server->getLogger()->info("Starting remote control listener");
|
||||
if($this->password === ""){
|
||||
throw new \InvalidArgumentException("Empty password");
|
||||
@ -54,7 +53,7 @@ class RCON{
|
||||
$this->clientsPerThread = (int) max(1, $clientsPerThread);
|
||||
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
|
||||
if($this->socket === false or !@socket_bind($this->socket, $interface, (int) $port) or !@socket_listen($this->socket)){
|
||||
if($this->socket === false or !@socket_bind($this->socket, $interface, $port) or !@socket_listen($this->socket)){
|
||||
throw new \RuntimeException(trim(socket_strerror(socket_last_error())));
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ class RCONInstance extends Thread{
|
||||
public $stop;
|
||||
public $cmd;
|
||||
public $response;
|
||||
/** @var resource */
|
||||
private $socket;
|
||||
private $password;
|
||||
private $maxClients;
|
||||
@ -39,14 +40,18 @@ class RCONInstance extends Thread{
|
||||
return $this->waiting === true;
|
||||
}
|
||||
|
||||
|
||||
public function __construct($socket, $password, $maxClients = 50){
|
||||
/**
|
||||
* @param resource $socket
|
||||
* @param string $password
|
||||
* @param int $maxClients
|
||||
*/
|
||||
public function __construct($socket, string $password, int $maxClients = 50){
|
||||
$this->stop = false;
|
||||
$this->cmd = "";
|
||||
$this->response = "";
|
||||
$this->socket = $socket;
|
||||
$this->password = $password;
|
||||
$this->maxClients = (int) $maxClients;
|
||||
$this->maxClients = $maxClients;
|
||||
for($n = 0; $n < $this->maxClients; ++$n){
|
||||
$this->{"client" . $n} = null;
|
||||
$this->{"status" . $n} = 0;
|
||||
@ -192,7 +197,7 @@ class RCONInstance extends Thread{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
public function getThreadName(){
|
||||
public function getThreadName() : string{
|
||||
return "RCON";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user