upload += $upload; $this->download += $download; } public function getUpload() : float{ return $this->upload; } public function getDownload() : float{ return $this->download; } public function resetStatistics() : void{ $this->upload = 0; $this->download = 0; } /** * @return NetworkInterface[] */ public function getInterfaces() : array{ return $this->interfaces; } public function getConnectionCount() : int{ $count = 0; foreach($this->interfaces as $interface){ $count += $interface->getConnectionCount(); } return $count; } public function tick() : void{ foreach($this->interfaces as $interface){ $interface->tick(); } foreach($this->updateSessions as $k => $session){ if(!$session->isConnected() or !$session->tick()){ unset($this->updateSessions[$k]); } } } /** * @param NetworkInterface $interface */ public function registerInterface(NetworkInterface $interface) : void{ $ev = new NetworkInterfaceRegisterEvent($interface); $ev->call(); if(!$ev->isCancelled()){ $interface->start(); $this->interfaces[$hash = spl_object_id($interface)] = $interface; if($interface instanceof AdvancedNetworkInterface){ $this->advancedInterfaces[$hash] = $interface; $interface->setNetwork($this); } $interface->setName($this->name); } } /** * @param NetworkInterface $interface */ public function unregisterInterface(NetworkInterface $interface) : void{ (new NetworkInterfaceUnregisterEvent($interface))->call(); unset($this->interfaces[$hash = spl_object_id($interface)], $this->advancedInterfaces[$hash]); } /** * Sets the server name shown on each interface Query * * @param string $name */ public function setName(string $name) : void{ $this->name = $name; foreach($this->interfaces as $interface){ $interface->setName($this->name); } } /** * @return string */ public function getName() : string{ return $this->name; } public function updateName() : void{ foreach($this->interfaces as $interface){ $interface->setName($this->name); } } /** * @param string $address * @param int $port * @param string $payload */ public function sendPacket(string $address, int $port, string $payload) : void{ foreach($this->advancedInterfaces as $interface){ $interface->sendRawPacket($address, $port, $payload); } } /** * Blocks an IP address from the main interface. Setting timeout to -1 will block it forever * * @param string $address * @param int $timeout */ public function blockAddress(string $address, int $timeout = 300) : void{ foreach($this->advancedInterfaces as $interface){ $interface->blockAddress($address, $timeout); } } public function unblockAddress(string $address) : void{ foreach($this->advancedInterfaces as $interface){ $interface->unblockAddress($address); } } public function addRawPacketFilter(string $regex) : void{ foreach($this->advancedInterfaces as $interface){ $interface->addRawPacketFilter($regex); } } public function scheduleSessionTick(NetworkSession $session) : void{ $this->updateSessions[spl_object_id($session)] = $session; } }