PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
QueryRegenerateEvent.php
1 <?php
2 
22 namespace pocketmine\event\server;
23 
24 use pocketmine\event;
27 
29  public static $handlerList = null;
30  public static $eventPool = [];
31  public static $nextEvent = 0;
32 
33  const GAME_ID = "MINECRAFTPE";
34 
35  private $timeout;
36  private $serverName;
37  private $listPlugins;
39  private $plugins;
41  private $players;
42 
43  private $gametype;
44  private $version;
45  private $server_engine;
46  private $map;
47  private $numPlayers;
48  private $maxPlayers;
49  private $whitelist;
50  private $port;
51  private $ip;
52 
53  private $extraData = [];
54 
55 
56  public function __construct(Server $server, $timeout = 5){
57  $this->timeout = $timeout;
58  $this->serverName = $server->getServerName();
59  $this->listPlugins = $server->getProperty("settings.query-plugins", true);
60  $this->plugins = $server->getPluginManager()->getPlugins();
61  $this->players = [];
62  foreach($server->getOnlinePlayers() as $player){
63  if($player->getName() != "" and $player->isConnected()){
64  $this->players[] = $player;
65  }
66  }
67 
68  $this->gametype = ($server->getGamemode() & 0x01) === 0 ? "SMP" : "CMP";
69  $this->version = $server->getVersion();
70  $this->server_engine = $server->getName() . " " . $server->getPocketMineVersion();
71  $this->map = $server->getDefaultLevel() === null ? "unknown" : $server->getDefaultLevel()->getName();
72  $this->numPlayers = count($this->players);
73  $this->maxPlayers = $server->getMaxPlayers();
74  $this->whitelist = $server->hasWhitelist() ? "on" : "off";
75  $this->port = $server->getPort();
76  $this->ip = $server->getIp();
77 
78  }
79 
85  public function getTimeout(){
86  return $this->timeout;
87  }
88 
89  public function setTimeout($timeout){
90  $this->timeout = $timeout;
91  }
92 
93  public function getServerName(){
94  return $this->serverName;
95  }
96 
97  public function setServerName($serverName){
98  $this->serverName = $serverName;
99  }
100 
101  public function canListPlugins(){
102  return $this->listPlugins;
103  }
104 
105  public function setListPlugins($value){
106  $this->listPlugins = (bool) $value;
107  }
108 
112  public function getPlugins(){
113  return $this->plugins;
114  }
115 
119  public function setPlugins(array $plugins){
120  $this->plugins = $plugins;
121  }
122 
126  public function getPlayerList(){
127  return $this->players;
128  }
129 
133  public function setPlayerList(array $players){
134  $this->players = $players;
135  }
136 
137  public function getPlayerCount(){
138  return $this->numPlayers;
139  }
140 
141  public function setPlayerCount($count){
142  $this->numPlayers = (int) $count;
143  }
144 
145  public function getMaxPlayerCount(){
146  return $this->maxPlayers;
147  }
148 
149  public function setMaxPlayerCount($count){
150  $this->maxPlayers = (int) $count;
151  }
152 
153  public function getWorld(){
154  return $this->map;
155  }
156 
157  public function setWorld($world){
158  $this->map = (string) $world;
159  }
160 
166  public function getExtraData(){
167  return $this->extraData;
168  }
169 
170  public function setExtraData(array $extraData){
171  $this->extraData = $extraData;
172  }
173 
174  public function getLongQuery(){
175  $query = "";
176 
177  $plist = $this->server_engine;
178  if(count($this->plugins) > 0 and $this->listPlugins){
179  $plist .= ":";
180  foreach($this->plugins as $p){
181  $d = $p->getDescription();
182  $plist .= " " . str_replace([";", ":", " "], ["", "", "_"], $d->getName()) . " " . str_replace([";", ":", " "], ["", "", "_"], $d->getVersion()) . ";";
183  }
184  $plist = substr($plist, 0, -1);
185  }
186 
187  $KVdata = [
188  "splitnum" => chr(128),
189  "hostname" => $this->serverName,
190  "gametype" => $this->gametype,
191  "game_id" => self::GAME_ID,
192  "version" => $this->version,
193  "server_engine" => $this->server_engine,
194  "plugins" => $plist,
195  "map" => $this->map,
196  "numplayers" => $this->numPlayers,
197  "maxplayers" => $this->maxPlayers,
198  "whitelist" => $this->whitelist,
199  "hostip" => $this->ip,
200  "hostport" => $this->port
201  ];
202 
203  foreach($KVdata as $key => $value){
204  $query .= $key . "\x00" . $value . "\x00";
205  }
206 
207  foreach($this->extraData as $key => $value){
208  $query .= $key . "\x00" . $value . "\x00";
209  }
210 
211  $query .= "\x00\x01player_\x00\x00";
212  foreach($this->players as $player){
213  $query .= $player->getName() . "\x00";
214  }
215  $query .= "\x00";
216 
217  return $query;
218  }
219 
220  public function getShortQuery(){
221  return $this->serverName . "\x00" . $this->gametype . "\x00" . $this->map . "\x00" . $this->numPlayers . "\x00" . $this->maxPlayers . "\x00" . Binary::writeLShort($this->port) . $this->ip . "\x00";
222  }
223 
224 }
static writeLShort($value)
Definition: Binary.php:322
getProperty($variable, $defaultValue=null)
Definition: Server.php:1243