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

Public Member Functions

 __construct ()
 
 regenerateInfo ()
 
 regenerateToken ()
 
 handle ($address, $port, $packet)
 

Static Public Member Functions

static getTokenString ($token, $salt)
 

Data Fields

 $lastToken
 
 $token
 
 $longData
 
 $shortData
 
 $timeout
 
const HANDSHAKE = 9
 
const STATISTICS = 0
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

QueryHandler constructor.

41  {
42  $this->server = Server::getInstance();
43  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.server.query.start"));
44  $addr = ($ip = $this->server->getIp()) != "" ? $ip : "0.0.0.0";
45  $port = $this->server->getPort();
46  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.server.query.info", [$port]));
47  /*
48  The Query protocol is built on top of the existing Minecraft PE UDP network stack.
49  Because the 0xFE packet does not exist in the MCPE protocol,
50  we can identify Query packets and remove them from the packet queue.
51 
52  Then, the Query class handles itself sending the packets in raw form, because
53  packets can conflict with the MCPE ones.
54  */
55 
56  $this->regenerateToken();
57  $this->lastToken = $this->token;
58  $this->regenerateInfo();
59  $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.server.query.running", [$addr, $port]));
60  }

Member Function Documentation

◆ getTokenString()

static getTokenString (   $token,
  $salt 
)
static
Parameters
$token
$salt
Returns
int
80  {
81  return Binary::readInt(substr(hash("sha512", $salt . ":" . $token, true), 7, 4));
82  }

◆ handle()

handle (   $address,
  $port,
  $packet 
)
Parameters
$address
$port
$packet
89  {
90  $offset = 2;
91  $packetType = ord($packet{$offset++});
92  $sessionID = Binary::readInt(substr($packet, $offset, 4));
93  $offset += 4;
94  $payload = substr($packet, $offset);
95 
96  switch($packetType){
97  case self::HANDSHAKE: //Handshake
98  $reply = chr(self::HANDSHAKE);
99  $reply .= Binary::writeInt($sessionID);
100  $reply .= self::getTokenString($this->token, $address) . "\x00";
101 
102  $this->server->getNetwork()->sendPacket($address, $port, $reply);
103  break;
104  case self::STATISTICS: //Stat
105  $token = Binary::readInt(substr($payload, 0, 4));
106  if($token !== self::getTokenString($this->token, $address) and $token !== self::getTokenString($this->lastToken, $address)){
107  break;
108  }
109  $reply = chr(self::STATISTICS);
110  $reply .= Binary::writeInt($sessionID);
111 
112  if($this->timeout < microtime(true)){
113  $this->regenerateInfo();
114  }
115 
116  if(strlen($payload) === 8){
117  $reply .= $this->longData;
118  }else{
119  $reply .= $this->shortData;
120  }
121  $this->server->getNetwork()->sendPacket($address, $port, $reply);
122  break;
123  }
124  }

◆ regenerateInfo()

regenerateInfo ( )
62  {
63  $ev = $this->server->getQueryInformation();
64  $this->longData = $ev->getLongQuery();
65  $this->shortData = $ev->getShortQuery();
66  $this->timeout = microtime(true) + $ev->getTimeout();
67  }

◆ regenerateToken()

regenerateToken ( )
69  {
70  $this->lastToken = $this->token;
71  $this->token = random_bytes(16);
72  }

Field Documentation

◆ $lastToken

$lastToken

◆ $longData

$longData

◆ $shortData

$shortData

◆ $timeout

$timeout

◆ $token

$token

◆ HANDSHAKE

const HANDSHAKE = 9

◆ STATISTICS

const STATISTICS = 0

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