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

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

public static PortForward ( $port )
    public static function PortForward($port)
    {
        if (Utils::$online === false) {
            return false;
        }
        if (Utils::getOS() != "win" or !class_exists("COM")) {
            return false;
        }
        $port = (int) $port;
        $myLocalIP = gethostbyname(trim(`hostname`));
        try {
            $com = new \COM("HNetCfg.NATUPnP");
            if ($com === false or !is_object($com->StaticPortMappingCollection)) {
                return false;
            }
            $com->StaticPortMappingCollection->Add($port, "UDP", $port, $myLocalIP, true, "PocketMine-MP");
        } catch (Throwable $e) {
            return false;
        }
        return true;
    }

Usage Example

Пример #1
0
 /**
  * Starts the PocketMine-MP server and starts processing ticks and packets
  */
 public function start()
 {
     if ($this->getConfigBoolean("enable-query", true) === true) {
         $this->queryHandler = new QueryHandler();
     }
     foreach ($this->getIPBans()->getEntries() as $entry) {
         $this->network->blockAddress($entry->getName(), -1);
     }
     if ($this->getProperty("settings.send-usage", true) !== false) {
         $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "sendUsage"]), 6000, 6000);
         $this->sendUsage();
     }
     if ($this->getProperty("settings.upnp-forwarding", false) == true) {
         $this->logger->info("[UPnP] Trying to port forward...");
         UPnP::PortForward($this->getPort());
     }
     $this->tickCounter = 0;
     if (function_exists("pcntl_signal")) {
         pcntl_signal(SIGTERM, [$this, "handleSignal"]);
         pcntl_signal(SIGINT, [$this, "handleSignal"]);
         pcntl_signal(SIGHUP, [$this, "handleSignal"]);
         $this->getScheduler()->scheduleRepeatingTask(new CallbackTask("pcntl_signal_dispatch"), 5);
     }
     $this->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "checkTicks"]), 20 * 5);
     $this->logger->info("Default game type: " . self::getGamemodeString($this->getGamemode()));
     Effect::init();
     $this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"');
     $this->tickProcessor();
     $this->forceShutdown();
     \gc_collect_cycles();
 }
All Usage Examples Of pocketmine\network\upnp\UPnP::PortForward