GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Network Class Reference

Public Member Functions

 __construct (Server $server)
 
 addStatistics ($upload, $download)
 
 getUpload ()
 
 getDownload ()
 
 resetStatistics ()
 
 getInterfaces ()
 
 processInterfaces ()
 
 registerInterface (SourceInterface $interface)
 
 unregisterInterface (SourceInterface $interface)
 
 setName ($name)
 
 getName ()
 
 updateName ()
 
 registerPacket ($id, $class)
 
 getServer ()
 
 processBatch (BatchPacket $packet, Player $p)
 
 sendPacket ($address, $port, $payload)
 
 blockAddress ($address, $timeout=300)
 
 unblockAddress ($address)
 

Static Public Attributes

static $BATCH_THRESHOLD = 512
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Server  $server)

Network constructor.

Parameters
Server$server
145  {
146 
147  $this->registerPackets();
148 
149  $this->server = $server;
150  }

Member Function Documentation

◆ addStatistics()

addStatistics (   $upload,
  $download 
)
Parameters
$upload
$download
156  {
157  $this->upload += $upload;
158  $this->download += $download;
159  }

◆ 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
340  {
341  foreach($this->advancedInterfaces as $interface){
342  $interface->blockAddress($address, $timeout);
343  }
344  }

◆ getDownload()

getDownload ( )
Returns
int
171  {
172  return $this->download;
173  }

◆ getInterfaces()

getInterfaces ( )
Returns
SourceInterface[]
183  {
184  return $this->interfaces;
185  }

◆ getName()

getName ( )
238  {
239  return $this->name;
240  }

◆ getServer()

getServer ( )
Returns
Server
259  {
260  return $this->server;
261  }

◆ getUpload()

getUpload ( )
Returns
int
164  {
165  return $this->upload;
166  }

◆ processBatch()

processBatch ( BatchPacket  $packet,
Player  $p 
)
Parameters
BatchPacket$packet
Player$p
267  {
268  try{
269  if(strlen($packet->payload) === 0){
270  //prevent zlib_decode errors for incorrectly-decoded packets
271  throw new \InvalidArgumentException("BatchPacket payload is empty or packet decode error");
272  }
273 
274  $str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB
275  $len = strlen($str);
276 
277  if($len === 0){
278  throw new \InvalidStateException("Decoded BatchPacket payload is empty");
279  }
280 
281  $stream = new BinaryStream($str);
282 
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");
288  }
289 
290  $pk->setBuffer($buf, 1);
291 
292  $pk->decode();
293  assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk));
294  $p->handleDataPacket($pk);
295  }
296  }
297  }catch(\Throwable $e){
298  if(\pocketmine\DEBUG > 1){
299  $logger = $this->server->getLogger();
300  if($logger instanceof MainLogger){
301  $logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
302  $logger->logException($e);
303  }
304  }
305  }
306  }

◆ processInterfaces()

processInterfaces ( )
187  {
188  foreach($this->interfaces as $interface){
189  try{
190  $interface->process();
191  }catch(\Throwable $e){
192  $logger = $this->server->getLogger();
193  if(\pocketmine\DEBUG > 1){
194  if($logger instanceof MainLogger){
195  $logger->logException($e);
196  }
197  }
198 
199  $interface->emergencyShutdown();
200  $this->unregisterInterface($interface);
201  $logger->critical($this->server->getLanguage()->translateString("pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
202  }
203  }
204  }

◆ registerInterface()

registerInterface ( SourceInterface  $interface)
Parameters
SourceInterface$interface
209  {
210  $this->interfaces[$hash = spl_object_hash($interface)] = $interface;
211  if($interface instanceof AdvancedSourceInterface){
212  $this->advancedInterfaces[$hash] = $interface;
213  $interface->setNetwork($this);
214  }
215  $interface->setName($this->name);
216  }

◆ registerPacket()

registerPacket (   $id,
  $class 
)
Parameters
int$id0-255
DataPacket$class
252  {
253  $this->packetPool[$id] = new $class;
254  }

◆ resetStatistics()

resetStatistics ( )
175  {
176  $this->upload = 0;
177  $this->download = 0;
178  }

◆ sendPacket()

sendPacket (   $address,
  $port,
  $payload 
)
Parameters
string$address
int$port
string$payload
328  {
329  foreach($this->advancedInterfaces as $interface){
330  $interface->sendRawPacket($address, $port, $payload);
331  }
332  }

◆ setName()

setName (   $name)

Sets the server name shown on each interface Query

Parameters
string$name
231  {
232  $this->name = (string) $name;
233  foreach($this->interfaces as $interface){
234  $interface->setName($this->name);
235  }
236  }

◆ unblockAddress()

unblockAddress (   $address)

Unblocks an IP address from the main interface.

Parameters
string$address
351  {
352  foreach($this->advancedInterfaces as $interface){
353  $interface->unblockAddress($address);
354  }
355  }

◆ unregisterInterface()

unregisterInterface ( SourceInterface  $interface)
Parameters
SourceInterface$interface
221  {
222  unset($this->interfaces[$hash = spl_object_hash($interface)],
223  $this->advancedInterfaces[$hash]);
224  }

◆ updateName()

updateName ( )
242  {
243  foreach($this->interfaces as $interface){
244  $interface->setName($this->name);
245  }
246  }

Field Documentation

◆ $BATCH_THRESHOLD

$BATCH_THRESHOLD = 512
static

The documentation for this class was generated from the following file: