◆ __construct()
Network constructor.
- Parameters
-
147 $this->registerPackets();
149 $this->server = $server;
◆ addStatistics()
addStatistics |
( |
|
$upload, |
|
|
|
$download |
|
) |
| |
- Parameters
-
157 $this->upload += $upload;
158 $this->download += $download;
◆ blockAddress()
blockAddress |
( |
|
$address, |
|
|
|
$timeout = 300 |
|
) |
| |
Blocks an IP address from the main interface. Setting timeout to -1 will block it forever
- Parameters
-
string | $address | |
int | $timeout | |
341 foreach($this->advancedInterfaces as $interface){
342 $interface->blockAddress($address, $timeout);
◆ getDownload()
- Returns
- int
172 return $this->download;
◆ getInterfaces()
◆ getName()
◆ getServer()
- Returns
- Server
260 return $this->server;
◆ getUpload()
- Returns
- int
165 return $this->upload;
◆ processBatch()
- Parameters
-
269 if(strlen($packet->payload) === 0){
271 throw new \InvalidArgumentException(
"BatchPacket payload is empty or packet decode error");
274 $str = zlib_decode($packet->payload, 1024 * 1024 * 64);
278 throw new \InvalidStateException(
"Decoded BatchPacket payload is empty");
281 $stream =
new BinaryStream($str);
283 while($stream->offset < $len){
284 $buf = $stream->getString();
285 if(($pk = $this->getPacket(ord($buf{0}))) !== null){
286 if($pk::NETWORK_ID === 0xfe){
287 throw new \InvalidStateException(
"Invalid BatchPacket inside BatchPacket");
290 $pk->setBuffer($buf, 1);
293 assert($pk->feof(),
"Still " . strlen(substr($pk->buffer, $pk->offset)) .
" bytes unread in " . get_class($pk));
294 $p->handleDataPacket($pk);
297 }
catch(\Throwable $e){
299 $logger = $this->server->getLogger();
300 if(
$logger instanceof MainLogger){
301 $logger->debug(
"BatchPacket " .
" 0x" . bin2hex($packet->payload));
◆ processInterfaces()
188 foreach($this->interfaces as $interface){
190 $interface->process();
191 }
catch(\Throwable $e){
192 $logger = $this->server->getLogger();
194 if(
$logger instanceof MainLogger){
199 $interface->emergencyShutdown();
201 $logger->critical($this->server->getLanguage()->translateString(
"pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
◆ registerInterface()
- Parameters
-
210 $this->interfaces[$hash = spl_object_hash($interface)] = $interface;
211 if($interface instanceof AdvancedSourceInterface){
212 $this->advancedInterfaces[$hash] = $interface;
213 $interface->setNetwork($this);
215 $interface->setName($this->name);
◆ registerPacket()
registerPacket |
( |
|
$id, |
|
|
|
$class |
|
) |
| |
- Parameters
-
int | $id | 0-255 |
DataPacket | $class | |
253 $this->packetPool[$id] =
new $class;
◆ resetStatistics()
◆ sendPacket()
sendPacket |
( |
|
$address, |
|
|
|
$port, |
|
|
|
$payload |
|
) |
| |
- Parameters
-
string | $address | |
int | $port | |
string | $payload | |
329 foreach($this->advancedInterfaces as $interface){
330 $interface->sendRawPacket($address, $port, $payload);
◆ setName()
Sets the server name shown on each interface Query
- Parameters
-
232 $this->name = (string) $name;
233 foreach($this->interfaces as $interface){
234 $interface->setName($this->name);
◆ unblockAddress()
unblockAddress |
( |
|
$address | ) |
|
Unblocks an IP address from the main interface.
- Parameters
-
352 foreach($this->advancedInterfaces as $interface){
353 $interface->unblockAddress($address);
◆ unregisterInterface()
- Parameters
-
222 unset($this->interfaces[$hash = spl_object_hash($interface)],
223 $this->advancedInterfaces[$hash]);
◆ updateName()
243 foreach($this->interfaces as $interface){
244 $interface->setName($this->name);
◆ $BATCH_THRESHOLD
The documentation for this class was generated from the following file:
- src/pocketmine/network/Network.php