public function __construct($IP, $Port = 25565, $Timeout = 2) { require "MinecraftServerPing.php"; $Query = null; try { $Query = new MinecraftPing($IP, $Port, $Timeout); $this->Info = $Query->Query(); if ($this->Info === false) { $Query->Close(); $Query->Connect(); $this->Info = $Query->QueryOldPre17(); $this->New = false; } } catch (MinecraftPingException $e) { $this->Online = false; } if ($Query !== null) { $Query->Close(); } if ($this->New) { $this->OnlinePlayers = $this->Info['players']['online']; $this->MaxPlayers = $this->Info['players']['max']; $this->Version = $this->Info['version']['name']; $this->Description = $this->Description['description']['text']; } else { $this->OnlinePlayers = $this->Info['Players']; $this->MaxPlayers = $this->Info['MaxPlayers']; $this->Version = $this->Info['Version']; } $this->Online = true; }
public function serverPlay($server_ip, $server_port, $server_name, $pre17) { $Info = false; $Query = null; try { $Query = new MinecraftPing($server_ip, $server_port, MQ_TIMEOUT); if ($pre17 == 0) { $Info = $Query->Query(); } else { $Info = $Query->QueryOldPre17(); } } catch (MinecraftPingException $e) { $Exception = $e; } if ($Query !== null) { $Query->Close(); } if ($pre17 == 0) { function startsWith($haystack, $needle) { return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; } if (startsWith($Info['version']['name'], 'BungeeCord')) { if ($Info['players']['online'] == 0) { echo '<div class="alert alert-warning">There are no players online!</div>'; } else { echo '<div class="alert alert-warning">There are ' . $Info['players']['online'] . ' players online!</div>'; } } else { if ($Info['players']['online'] == 0) { echo '<div class="alert alert-warning">There are no players online!</div>'; } else { if ($Info['players']['online'] > 12) { $extra = $Info['players']['online'] - 12; $max = 12; } else { $max = $Info['players']['online']; } for ($row = 0; $row < $max; $row++) { echo '<span rel="tooltip" data-trigger="hover" data-original-title="' . $Info['players']['sample'][$row]['name'] . '"><a href="/profile/' . $Info['players']['sample'][$row]['name'] . '"><img src="https://cravatar.eu/avatar/' . $Info['players']['sample'][$row]['name'] . '/50.png" style="width: 40px; height: 40px; margin-bottom: 5px; margin-left: 5px; border-radius: 3px;" /></a></span>'; } if (isset($extra)) { echo ' <span class="label label-info">And ' . $extra . ' more</span>'; } } } } else { if ($Info['Players'] == 0) { echo '<div class="alert alert-warning">There are no players online!</div>'; } else { echo '<div class="alert alert-warning">There are ' . $Info['Players'] . ' players online!</div>'; } } }
$Query = null; try { $Query = new MinecraftPing(MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT); $Info = $Query->Query(); if ($Info === false) { /* * If this server is older than 1.7, we can try querying it again using older protocol * This function returns data in a different format, you will have to manually map * things yourself if you want to match 1.7's output * * If you know for sure that this server is using an older version, * you then can directly call QueryOldPre17 and avoid Query() and then reconnection part */ $Query->Close(); $Query->Connect(); $Info = $Query->QueryOldPre17(); } } catch (MinecraftPingException $e) { $Exception = $e; } if ($Query !== null) { $Query->Close(); } $Timer = Number_Format(MicroTime(true) - $Timer, 4, '.', ''); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Minecraft Ping PHP Class</title>
public function serverPlay($server_ip, $server_port, $server_name, $pre17, $general_language) { $return = ''; $Info = false; $Query = null; try { $Query = new MinecraftPing($server_ip, $server_port, MQ_TIMEOUT); if ($pre17 == 0) { $Info = $Query->Query(); } else { $Info = $Query->QueryOldPre17(); } } catch (MinecraftPingException $e) { // Error, insert into database if (!$this->_db->insert('query_errors', array('date' => date('U'), 'error' => htmlspecialchars($e->getMessage()), 'ip' => $server_ip, 'port' => $server_port))) { throw new Exception('Unknown error querying the server.'); } //$Exception = $e; } if ($Query !== null) { $Query->Close(); } if ($pre17 == 0) { if (!function_exists('startsWith')) { function startsWith($haystack, $needle) { return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; } } if (startsWith($Info['version']['name'], 'BungeeCord')) { if ($Info['players']['online'] == 0) { $return .= '<div class="alert alert-warning">' . $general_language['no_players_online'] . '</div>'; } else { $return .= '<div class="alert alert-warning">' . str_replace('{x}', $Info['players']['online'], $general_language['x_players_online']) . '</div>'; } } else { if ($Info['players']['online'] == 0) { $return .= '<div class="alert alert-warning">' . $general_language['no_players_online'] . '</div>'; } else { if ($Info['players']['online'] > 12) { $extra = $Info['players']['online'] - 12; $max = 12; } else { $max = $Info['players']['online']; } for ($row = 0; $row < $max; $row++) { $return .= '<span rel="tooltip" data-trigger="hover" data-original-title="' . $Info['players']['sample'][$row]['name'] . '"><a href="/profile/' . $Info['players']['sample'][$row]['name'] . '"><img src="https://cravatar.eu/avatar/' . $Info['players']['sample'][$row]['name'] . '/50.png" style="width: 40px; height: 40px; margin-bottom: 5px; margin-left: 5px; border-radius: 3px;" /></a></span> '; } if (isset($extra)) { $return .= ' <span class="label label-info">And ' . $extra . ' more</span>'; } } } } else { if ($Info['Players'] == 0) { $return .= '<div class="alert alert-warning">' . $general_language['no_players_online'] . '</div>'; } else { $return .= '<div class="alert alert-warning">' . str_replace('{x}', $Info['Players'], $general_language['x_players_online']) . '</div>'; } } return $return; }
public function getQuery() { $input = Input::only('ip', 'port', 'version'); $server = false; if (!$input['version']) { $input['version'] = '1.7.10'; } try { $query = new MinecraftPing($input['ip'], $input['port']); if ($input['version'] > '1.7') { $server = $query->Query(); } else { $server = $query->QueryOldPre17(); } } catch (xPaw\MinecraftPingException $e) { } return View::make('servers.query', ['server' => $server]); }