Network->unregisterInterface() is now less useless

Interfaces are now automatically shut down when unregistered.
This commit is contained in:
Dylan K. Taylor 2019-02-10 17:07:58 +00:00
parent 9ebd559907
commit b6bcb47deb
2 changed files with 7 additions and 2 deletions

View File

@ -1683,7 +1683,6 @@ class Server{
$this->getLogger()->debug("Stopping network interfaces");
foreach($this->network->getInterfaces() as $interface){
$this->getLogger()->debug("Stopping network interface " . get_class($interface));
$interface->shutdown();
$this->network->unregisterInterface($interface);
}
}

View File

@ -30,6 +30,7 @@ use pocketmine\event\server\NetworkInterfaceRegisterEvent;
use pocketmine\event\server\NetworkInterfaceUnregisterEvent;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\PacketPool;
use function get_class;
use function spl_object_id;
class Network{
@ -116,10 +117,15 @@ class Network{
/**
* @param NetworkInterface $interface
* @throws \InvalidArgumentException
*/
public function unregisterInterface(NetworkInterface $interface) : void{
if(!isset($this->interfaces[$hash = spl_object_id($interface)])){
throw new \InvalidArgumentException("Interface " . get_class($interface) . " is not registered on this network");
}
(new NetworkInterfaceUnregisterEvent($interface))->call();
unset($this->interfaces[$hash = spl_object_id($interface)], $this->advancedInterfaces[$hash]);
unset($this->interfaces[$hash], $this->advancedInterfaces[$hash]);
$interface->shutdown();
}
/**