mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
Apply typehints to more general pocketmine\network namespace
This commit is contained in:
parent
950465d283
commit
2907de81ad
@ -32,23 +32,23 @@ interface AdvancedSourceInterface extends SourceInterface{
|
|||||||
* @param string $address
|
* @param string $address
|
||||||
* @param int $timeout Seconds
|
* @param int $timeout Seconds
|
||||||
*/
|
*/
|
||||||
public function blockAddress(string $address, int $timeout = 300);
|
public function blockAddress(string $address, int $timeout = 300) : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $address
|
* @param string $address
|
||||||
*/
|
*/
|
||||||
public function unblockAddress(string $address);
|
public function unblockAddress(string $address) : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Network $network
|
* @param Network $network
|
||||||
*/
|
*/
|
||||||
public function setNetwork(Network $network);
|
public function setNetwork(Network $network) : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $address
|
* @param string $address
|
||||||
* @param int $port
|
* @param int $port
|
||||||
* @param string $payload
|
* @param string $payload
|
||||||
*/
|
*/
|
||||||
public function sendRawPacket(string $address, int $port, string $payload);
|
public function sendRawPacket(string $address, int $port, string $payload) : void;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class CompressBatchedTask extends AsyncTask{
|
|||||||
$this->storeLocal($targets);
|
$this->storeLocal($targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onRun(){
|
public function onRun() : void{
|
||||||
$batch = new BatchPacket();
|
$batch = new BatchPacket();
|
||||||
$batch->payload = $this->data;
|
$batch->payload = $this->data;
|
||||||
$this->data = null;
|
$this->data = null;
|
||||||
@ -54,7 +54,7 @@ class CompressBatchedTask extends AsyncTask{
|
|||||||
$this->setResult($batch->buffer, false);
|
$this->setResult($batch->buffer, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCompletion(Server $server){
|
public function onCompletion(Server $server) : void{
|
||||||
$pk = new BatchPacket($this->getResult());
|
$pk = new BatchPacket($this->getResult());
|
||||||
$pk->isEncoded = true;
|
$pk->isEncoded = true;
|
||||||
|
|
||||||
|
@ -58,20 +58,20 @@ class Network{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addStatistics($upload, $download){
|
public function addStatistics(float $upload, float $download) : void{
|
||||||
$this->upload += $upload;
|
$this->upload += $upload;
|
||||||
$this->download += $download;
|
$this->download += $download;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUpload(){
|
public function getUpload() : float{
|
||||||
return $this->upload;
|
return $this->upload;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDownload(){
|
public function getDownload() : float{
|
||||||
return $this->download;
|
return $this->download;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetStatistics(){
|
public function resetStatistics() : void{
|
||||||
$this->upload = 0;
|
$this->upload = 0;
|
||||||
$this->download = 0;
|
$this->download = 0;
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ class Network{
|
|||||||
return $this->interfaces;
|
return $this->interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processInterfaces(){
|
public function processInterfaces() : void{
|
||||||
foreach($this->interfaces as $interface){
|
foreach($this->interfaces as $interface){
|
||||||
$this->processInterface($interface);
|
$this->processInterface($interface);
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ class Network{
|
|||||||
/**
|
/**
|
||||||
* @param SourceInterface $interface
|
* @param SourceInterface $interface
|
||||||
*/
|
*/
|
||||||
public function registerInterface(SourceInterface $interface){
|
public function registerInterface(SourceInterface $interface) : void{
|
||||||
$this->server->getPluginManager()->callEvent($ev = new NetworkInterfaceRegisterEvent($interface));
|
$this->server->getPluginManager()->callEvent($ev = new NetworkInterfaceRegisterEvent($interface));
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$interface->start();
|
$interface->start();
|
||||||
@ -125,7 +125,7 @@ class Network{
|
|||||||
/**
|
/**
|
||||||
* @param SourceInterface $interface
|
* @param SourceInterface $interface
|
||||||
*/
|
*/
|
||||||
public function unregisterInterface(SourceInterface $interface){
|
public function unregisterInterface(SourceInterface $interface) : void{
|
||||||
$this->server->getPluginManager()->callEvent(new NetworkInterfaceUnregisterEvent($interface));
|
$this->server->getPluginManager()->callEvent(new NetworkInterfaceUnregisterEvent($interface));
|
||||||
unset($this->interfaces[$hash = spl_object_hash($interface)], $this->advancedInterfaces[$hash]);
|
unset($this->interfaces[$hash = spl_object_hash($interface)], $this->advancedInterfaces[$hash]);
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ class Network{
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function setName(string $name){
|
public function setName(string $name) : void{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
foreach($this->interfaces as $interface){
|
foreach($this->interfaces as $interface){
|
||||||
$interface->setName($this->name);
|
$interface->setName($this->name);
|
||||||
@ -149,7 +149,7 @@ class Network{
|
|||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateName(){
|
public function updateName() : void{
|
||||||
foreach($this->interfaces as $interface){
|
foreach($this->interfaces as $interface){
|
||||||
$interface->setName($this->name);
|
$interface->setName($this->name);
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ class Network{
|
|||||||
* @param int $port
|
* @param int $port
|
||||||
* @param string $payload
|
* @param string $payload
|
||||||
*/
|
*/
|
||||||
public function sendPacket(string $address, int $port, string $payload){
|
public function sendPacket(string $address, int $port, string $payload) : void{
|
||||||
foreach($this->advancedInterfaces as $interface){
|
foreach($this->advancedInterfaces as $interface){
|
||||||
$interface->sendRawPacket($address, $port, $payload);
|
$interface->sendRawPacket($address, $port, $payload);
|
||||||
}
|
}
|
||||||
@ -179,13 +179,13 @@ class Network{
|
|||||||
* @param string $address
|
* @param string $address
|
||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
*/
|
*/
|
||||||
public function blockAddress(string $address, int $timeout = 300){
|
public function blockAddress(string $address, int $timeout = 300) : void{
|
||||||
foreach($this->advancedInterfaces as $interface){
|
foreach($this->advancedInterfaces as $interface){
|
||||||
$interface->blockAddress($address, $timeout);
|
$interface->blockAddress($address, $timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unblockAddress(string $address){
|
public function unblockAddress(string $address) : void{
|
||||||
foreach($this->advancedInterfaces as $interface){
|
foreach($this->advancedInterfaces as $interface){
|
||||||
$interface->unblockAddress($address);
|
$interface->unblockAddress($address);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ interface SourceInterface{
|
|||||||
/**
|
/**
|
||||||
* Performs actions needed to start the interface after it is registered.
|
* Performs actions needed to start the interface after it is registered.
|
||||||
*/
|
*/
|
||||||
public function start();
|
public function start() : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a DataPacket to the interface, returns an unique identifier for the packet if $needACK is true
|
* Sends a DataPacket to the interface, returns an unique identifier for the packet if $needACK is true
|
||||||
@ -49,7 +49,7 @@ interface SourceInterface{
|
|||||||
*
|
*
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true);
|
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true) : ?int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminates the connection
|
* Terminates the connection
|
||||||
@ -57,20 +57,20 @@ interface SourceInterface{
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param string $reason
|
* @param string $reason
|
||||||
*/
|
*/
|
||||||
public function close(Player $player, string $reason = "unknown reason");
|
public function close(Player $player, string $reason = "unknown reason") : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function setName(string $name);
|
public function setName(string $name) : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called every tick to process events on the interface.
|
* Called every tick to process events on the interface.
|
||||||
*/
|
*/
|
||||||
public function process() : void;
|
public function process() : void;
|
||||||
|
|
||||||
public function shutdown();
|
public function shutdown() : void;
|
||||||
|
|
||||||
public function emergencyShutdown();
|
public function emergencyShutdown() : void;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
|
|||||||
$this->player = $player;
|
$this->player = $player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleDataPacket(DataPacket $packet){
|
public function handleDataPacket(DataPacket $packet) : void{
|
||||||
$timings = Timings::getReceiveDataPacketTimings($packet);
|
$timings = Timings::getReceiveDataPacketTimings($packet);
|
||||||
$timings->startTiming();
|
$timings->startTiming();
|
||||||
|
|
||||||
|
@ -91,11 +91,11 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
$this->interface = new ServerHandler($this->rakLib, $this);
|
$this->interface = new ServerHandler($this->rakLib, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start(){
|
public function start() : void{
|
||||||
$this->rakLib->start(PTHREADS_INHERIT_CONSTANTS | PTHREADS_INHERIT_INI); //HACK: MainLogger needs INI and constants
|
$this->rakLib->start(PTHREADS_INHERIT_CONSTANTS | PTHREADS_INHERIT_INI); //HACK: MainLogger needs INI and constants
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setNetwork(Network $network){
|
public function setNetwork(Network $network) : void{
|
||||||
$this->network = $network;
|
$this->network = $network;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(Player $player, string $reason = "unknown reason"){
|
public function close(Player $player, string $reason = "unknown reason") : void{
|
||||||
if(isset($this->identifiers[$h = spl_object_hash($player)])){
|
if(isset($this->identifiers[$h = spl_object_hash($player)])){
|
||||||
unset($this->players[$this->identifiers[$h]]);
|
unset($this->players[$this->identifiers[$h]]);
|
||||||
unset($this->identifiersACK[$this->identifiers[$h]]);
|
unset($this->identifiersACK[$this->identifiers[$h]]);
|
||||||
@ -126,12 +126,12 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shutdown(){
|
public function shutdown() : void{
|
||||||
$this->server->getTickSleeper()->removeNotifier($this->sleeper);
|
$this->server->getTickSleeper()->removeNotifier($this->sleeper);
|
||||||
$this->interface->shutdown();
|
$this->interface->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emergencyShutdown(){
|
public function emergencyShutdown() : void{
|
||||||
$this->server->getTickSleeper()->removeNotifier($this->sleeper);
|
$this->server->getTickSleeper()->removeNotifier($this->sleeper);
|
||||||
$this->interface->emergencyShutdown();
|
$this->interface->emergencyShutdown();
|
||||||
}
|
}
|
||||||
@ -167,11 +167,11 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function blockAddress(string $address, int $timeout = 300){
|
public function blockAddress(string $address, int $timeout = 300) : void{
|
||||||
$this->interface->blockAddress($address, $timeout);
|
$this->interface->blockAddress($address, $timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unblockAddress(string $address){
|
public function unblockAddress(string $address) : void{
|
||||||
$this->interface->unblockAddress($address);
|
$this->interface->unblockAddress($address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
$this->server->handlePacket($this, $address, $port, $payload);
|
$this->server->handlePacket($this, $address, $port, $payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendRawPacket(string $address, int $port, string $payload){
|
public function sendRawPacket(string $address, int $port, string $payload) : void{
|
||||||
$this->interface->sendRaw($address, $port, $payload);
|
$this->interface->sendRaw($address, $port, $payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setName(string $name){
|
public function setName(string $name) : void{
|
||||||
$info = $this->server->getQueryInformation();
|
$info = $this->server->getQueryInformation();
|
||||||
|
|
||||||
$this->interface->sendOption("name", implode(";",
|
$this->interface->sendOption("name", implode(";",
|
||||||
@ -205,8 +205,8 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPortCheck($name){
|
public function setPortCheck(bool $name) : void{
|
||||||
$this->interface->sendOption("portChecking", (bool) $name);
|
$this->interface->sendOption("portChecking", $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleOption(string $option, string $value) : void{
|
public function handleOption(string $option, string $value) : void{
|
||||||
@ -216,7 +216,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true){
|
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true) : ?int{
|
||||||
if(isset($this->identifiers[$h = spl_object_hash($player)])){
|
if(isset($this->identifiers[$h = spl_object_hash($player)])){
|
||||||
$identifier = $this->identifiers[$h];
|
$identifier = $this->identifiers[$h];
|
||||||
if(!$packet->isEncoded){
|
if(!$packet->isEncoded){
|
||||||
|
@ -55,7 +55,7 @@ class VerifyLoginTask extends AsyncTask{
|
|||||||
$this->packet = $packet;
|
$this->packet = $packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onRun(){
|
public function onRun() : void{
|
||||||
$packet = $this->packet; //Get it in a local variable to make sure it stays unserialized
|
$packet = $this->packet; //Get it in a local variable to make sure it stays unserialized
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -142,7 +142,7 @@ class VerifyLoginTask extends AsyncTask{
|
|||||||
$currentPublicKey = $claims["identityPublicKey"] ?? null; //if there are further links, the next link should be signed with this
|
$currentPublicKey = $claims["identityPublicKey"] ?? null; //if there are further links, the next link should be signed with this
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCompletion(Server $server){
|
public function onCompletion(Server $server) : void{
|
||||||
/** @var Player $player */
|
/** @var Player $player */
|
||||||
$player = $this->fetchLocal();
|
$player = $this->fetchLocal();
|
||||||
if($player->isClosed()){
|
if($player->isClosed()){
|
||||||
|
@ -58,14 +58,14 @@ class QueryHandler{
|
|||||||
$this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.server.query.running", [$addr, $port]));
|
$this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.server.query.running", [$addr, $port]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function regenerateInfo(){
|
public function regenerateInfo() : void{
|
||||||
$ev = $this->server->getQueryInformation();
|
$ev = $this->server->getQueryInformation();
|
||||||
$this->longData = $ev->getLongQuery();
|
$this->longData = $ev->getLongQuery();
|
||||||
$this->shortData = $ev->getShortQuery();
|
$this->shortData = $ev->getShortQuery();
|
||||||
$this->timeout = microtime(true) + $ev->getTimeout();
|
$this->timeout = microtime(true) + $ev->getTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function regenerateToken(){
|
public function regenerateToken() : void{
|
||||||
$this->lastToken = $this->token;
|
$this->lastToken = $this->token;
|
||||||
$this->token = random_bytes(16);
|
$this->token = random_bytes(16);
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ class QueryHandler{
|
|||||||
return Binary::readInt(substr(hash("sha512", $salt . ":" . $token, true), 7, 4));
|
return Binary::readInt(substr(hash("sha512", $salt . ":" . $token, true), 7, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(AdvancedSourceInterface $interface, string $address, int $port, string $packet){
|
public function handle(AdvancedSourceInterface $interface, string $address, int $port, string $packet) : void{
|
||||||
$offset = 2;
|
$offset = 2;
|
||||||
$packetType = ord($packet{$offset++});
|
$packetType = ord($packet{$offset++});
|
||||||
$sessionID = Binary::readInt(substr($packet, $offset, 4));
|
$sessionID = Binary::readInt(substr($packet, $offset, 4));
|
||||||
|
@ -82,7 +82,7 @@ class RCON{
|
|||||||
$this->server->getLogger()->info("RCON running on $addr:$port");
|
$this->server->getLogger()->info("RCON running on $addr:$port");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stop(){
|
public function stop() : void{
|
||||||
$this->instance->close();
|
$this->instance->close();
|
||||||
socket_write($this->ipcMainSocket, "\x00"); //make select() return
|
socket_write($this->ipcMainSocket, "\x00"); //make select() return
|
||||||
Server::microSleep(50000);
|
Server::microSleep(50000);
|
||||||
@ -93,7 +93,7 @@ class RCON{
|
|||||||
@socket_close($this->ipcThreadSocket);
|
@socket_close($this->ipcThreadSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check(){
|
public function check() : void{
|
||||||
$response = new RemoteConsoleCommandSender();
|
$response = new RemoteConsoleCommandSender();
|
||||||
$command = $this->instance->cmd;
|
$command = $this->instance->cmd;
|
||||||
|
|
||||||
|
@ -102,11 +102,11 @@ class RCONInstance extends Thread{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(){
|
public function close() : void{
|
||||||
$this->stop = true;
|
$this->stop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(){
|
public function run() : void{
|
||||||
$this->registerClassLoader();
|
$this->registerClassLoader();
|
||||||
|
|
||||||
/** @var resource[] $clients */
|
/** @var resource[] $clients */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user