pocketmine\network\upnp\UPnP::RemovePortForward PHP Метод

RemovePortForward() публичный статический Метод

public static RemovePortForward ( $port )
    public static function RemovePortForward($port)
    {
        if (Utils::$online === false) {
            return false;
        }
        if (Utils::getOS() != "win" or !class_exists("COM")) {
            return false;
        }
        $port = (int) $port;
        try {
            $com = new \COM("HNetCfg.NATUPnP") or false;
            if ($com === false or !is_object($com->StaticPortMappingCollection)) {
                return false;
            }
            $com->StaticPortMappingCollection->Remove($port, "UDP");
        } catch (Throwable $e) {
            return false;
        }
        return true;
    }

Usage Example

Пример #1
0
 public function forceShutdown()
 {
     if ($this->hasStopped) {
         return;
     }
     try {
         $this->hasStopped = true;
         $this->shutdown();
         if ($this->rcon instanceof RCON) {
             $this->rcon->stop();
         }
         if ($this->getProperty("settings.upnp-forwarding", false) === true) {
             $this->logger->info("[UPnP] Removing port forward...");
             UPnP::RemovePortForward($this->getPort());
         }
         $this->pluginManager->disablePlugins();
         foreach ($this->players as $player) {
             $player->close(TextFormat::YELLOW . $player->getName() . " has left the game", $this->getProperty("settings.shutdown-message", "Server closed"));
         }
         foreach ($this->getLevels() as $level) {
             $this->unloadLevel($level, true);
         }
         if ($this->generationManager instanceof GenerationRequestManager) {
             $this->generationManager->shutdown();
         }
         HandlerList::unregisterAll();
         $this->scheduler->cancelAllTasks();
         $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX);
         $this->properties->save();
         $this->console->kill();
         foreach ($this->network->getInterfaces() as $interface) {
             $interface->shutdown();
             $this->network->unregisterInterface($interface);
         }
     } catch (\Exception $e) {
         $this->logger->emergency("Crashed while crashing, killing process");
         @kill(getmypid());
     }
 }
All Usage Examples Of pocketmine\network\upnp\UPnP::RemovePortForward