UPnP: catch InternetException when attempting portforward

we might fail to get the internal IP for some reason, which shouldn't crash the server.
This commit is contained in:
Dylan K. Taylor 2021-10-02 00:52:14 +01:00
parent 81d5598e96
commit f26f063164
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -25,6 +25,7 @@ namespace pocketmine\network\upnp;
use pocketmine\network\NetworkInterface;
use pocketmine\utils\Internet;
use pocketmine\utils\InternetException;
final class UPnPNetworkInterface implements NetworkInterface{
@ -55,7 +56,7 @@ final class UPnPNetworkInterface implements NetworkInterface{
$this->serviceURL = UPnP::getServiceUrl();
UPnP::portForward($this->serviceURL, Internet::getInternalIP(), $this->port, $this->port);
$this->logger->info("Forwarded $this->ip:$this->port to external port $this->port");
}catch(UPnPException $e){
}catch(UPnPException | InternetException $e){
$this->logger->error("UPnP portforward failed: " . $e->getMessage());
}
}