Cain Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 Estou com esse erro, quero aprender php pra por status num site que estou fazendo, estou com o seguinte erro: Segui esse tutorial http://gamersboard.com.br/topic/289-status-do-seu-server-facil-e-r%C3%A1pido/?hl=%2Bstatus+%2Bminecraft O meu codigo no teste.php <style> .titulos{color:#00a4cc; font-weight:bold;} </style> <?php $ip = 'jogar.mysticcraft.com.br'; //Ip do servidor $versao = '1.5.*'; //Versão: 1.7.* ou 1.6.* ou 1.5.* $porta = 25565; //Porta do servidor include_once 'status.class.php'; //o arquivo que criamos anteriormente $status = new MinecraftServerStatus(); $resultado = $status->getStatus($ip, $versao, $porta); if(!$resultado) { echo '<span class="titulos">Servidor Offline!</span>';} else {?> <center> <? if($versao == '1.7.*'){ ?> <img width="64" height="64" src="<? echo $resultado['favicon']?>" /><br> <? } ?> <span class="titulos">Players Online/Total: <? echo $resultado['players'].'/'.$resultado['maxplayers'];?></span><br> <span class="titulos">Versão do Servidor: <? echo $resultado['version'];?></span><br> <span class="titulos">Ip do Servidor: <? echo $resultado['hostname'];?></span><br> <span class="titulos">Legenda do Servidor: <br> <? echo $resultado['motd'];?></span><br> <span class="titulos">Está com PING de: <? echo $resultado['ping'];?>ms</span><br> </center> <?php } ?> Link para o comentário Compartilhar em outros sites More sharing options...
Guest Dêemezeká Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 Não muda em nada. testei aki no meu pc e tb nao funcionou, mas fui pingar seu ip jogar.mysticcraft.com.br ele vi que ele ta redirecionando pra localhost acho que porisso nao ta funcionando Link para o comentário Compartilhar em outros sites More sharing options...
Guest Dêemezeká Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 ta faltando o arquivo status.class.php, ele nao ta na mesma pasta ou vc n upou ele Link para o comentário Compartilhar em outros sites More sharing options...
Cain Postado Junho 1, 2015 Autor Denunciar Compartilhar Postado Junho 1, 2015 (editado) Resolvi o problema, o file não tava att, agora só que esta dando sempre offline, e o servidor esta on... http://minecraft-mp.com/server-s47792 Editado Junho 1, 2015 por Cain Link para o comentário Compartilhar em outros sites More sharing options...
Guest Dêemezeká Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 me mostra o seu status.class.php Link para o comentário Compartilhar em outros sites More sharing options...
Cain Postado Junho 1, 2015 Autor Denunciar Compartilhar Postado Junho 1, 2015 (editado) <?php /** * Minecraft Server Status Query * @author Julian Spravil <[email protected]> https://github.com/FunnyItsElmo * @license Free to use but dont remove the author, license and copyright * @copyright © 2013 Julian Spravil */ class MinecraftServerStatus { private $timeout; public function __construct($timeout = 2) { $this->timeout = $timeout; } public function getStatus($host = 'jogar.mysticcraft.com.br', $port = 25565, $version = '1.5.*') { if (substr_count($host , '.') != 4) $host = gethostbyname($host); $serverdata = array(); $serverdata['hostname'] = $host; $serverdata['version'] = false; $serverdata['protocol'] = false; $serverdata['players'] = false; $serverdata['maxplayers'] = false; $serverdata['motd'] = false; $serverdata['motd_raw'] = false; $serverdata['favicon'] = false; $serverdata['ping'] = false; $socket = $this->connect($host, $port); if(!$socket) { return false; } if(preg_match('/1.5/',$version)) { $start = microtime(true); $handshake = pack('cccca*', hexdec(strlen($host)), 0, 0x04, strlen($host), $host).pack('nc', $port, 0x01); socket_send($socket, $handshake, strlen($handshake), 0); //give the server a high five socket_send($socket, "\x01\x00", 2, 0); socket_read( $socket, 1 ); $ping = round((microtime(true)-$start)*1000); //calculate the high five duration $packetlength = $this->read_packet_length($socket); if($packetlength < 10) { return false; } socket_read($socket, 1); $packetlength = $this->read_packet_length($socket); $data = socket_read($socket, $packetlength, PHP_NORMAL_READ); if(!$data) { return false; } $data = json_decode($data); $serverdata['version'] = $data->version->name; $serverdata['protocol'] = $data->version->protocol; $serverdata['players'] = $data->players->online; $serverdata['maxplayers'] = $data->players->max; $motd = $data->description; $motd = preg_replace("/(§.)/", "",$motd); $motd = preg_replace("/[^[:alnum:][:punct:] ]/", "", $motd); $serverdata['motd'] = $motd; $serverdata['motd_raw'] = $data->description; $serverdata['favicon'] = $data->favicon; $serverdata['ping'] = $ping; } else { $start = microtime(true); socket_send($socket, "\xFE\x01", 2, 0); $length = socket_recv($socket, $data, 512, 0); $ping = round((microtime(true)-$start)*1000);//calculate the high five duration if($length < 4 || $data[0] != "\xFF") { return false; } $motd = ""; $motdraw = ""; //Evaluate the received data if (substr((String)$data, 3, 5) == "\x00\xa7\x00\x31\x00"){ $result = explode("\x00", mb_convert_encoding(substr((String)$data, 15), 'UTF-8', 'UCS-2')); $motd = $result[1]; $motdraw = $motd; } else { $result = explode('§', mb_convert_encoding(substr((String)$data, 3), 'UTF-8', 'UCS-2')); foreach ($result as $key => $string) { if($key != sizeof($result)-1 && $key != sizeof($result)-2 && $key != 0) { $motd .= '§'.$string; } } $motdraw = $motd; } $motd = preg_replace("/(§.)/", "", $motd); $motd = preg_replace("/[^[:alnum:][:punct:] ]/", "", $motd); //Remove all special characters from a string $serverdata['version'] = $result[0]; $serverdata['players'] = $result[sizeof($result)-2]; $serverdata['maxplayers'] = $result[sizeof($result)-1]; $serverdata['motd'] = $motd; $serverdata['motd_raw'] = $motdraw; $serverdata['ping'] = $ping; } $this->disconnect($socket); return $serverdata; } private function connect($host, $port) { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!@socket_connect($socket, $host, $port)) { $this->disconnect($socket); return false; } return $socket; } private function disconnect($socket) { if($socket != null) { socket_close($socket); } } private function read_packet_length($socket) { $a = 0; $b = 0; while(true) { $c = socket_read($socket, 1); if(!$c) { return 0; } $c = Ord($c); $a |= ($c & 0x7F) << $b++ * 7; if( $b > 5 ) { return false; } if(($c & 0x80) != 128) { break; } } return $a; } } Editado Junho 1, 2015 por Cain Link para o comentário Compartilhar em outros sites More sharing options...
Guest Dêemezeká Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 adiciona essa li <?php /** * Minecraft Server Status Query * @author Julian Spravil <[email protected]> https://github.com/FunnyItsElmo * @license Free to use but dont remove the author, license and copyright * @copyright © 2013 Julian Spravil */ class MinecraftServerStatus { private $timeout; public function __construct($timeout = 2) { $this->timeout = $timeout; } public function getStatus($host = 'jogar.mysticcraft.com.br', $port = 25565, $version = '1.5.*') { if (substr_count($host , '.') != 4) $host = gethostbyname($host); $serverdata = array(); $serverdata['hostname'] = $host; $serverdata['version'] = false; $serverdata['protocol'] = false; $serverdata['players'] = false; $serverdata['maxplayers'] = false; $serverdata['motd'] = false; $serverdata['motd_raw'] = false; $serverdata['favicon'] = false; $serverdata['ping'] = false; $socket = $this->connect($host, $port); if(!$socket) { return false; } if(preg_match('/1.7|1.8/',$version)) { $start = microtime(true); $handshake = pack('cccca*', hexdec(strlen($host)), 0, 0x04, strlen($host), $host).pack('nc', $port, 0x01); socket_send($socket, $handshake, strlen($handshake), 0); //give the server a high five socket_send($socket, "\x01\x00", 2, 0); socket_read( $socket, 1 ); $ping = round((microtime(true)-$start)*1000); //calculate the high five duration $packetlength = $this->read_packet_length($socket); if($packetlength < 10) { return false; } socket_read($socket, 1); $packetlength = $this->read_packet_length($socket); $data = socket_read($socket, $packetlength, PHP_NORMAL_READ); if(!$data) { return false; } $data = json_decode($data); $serverdata['version'] = $data->version->name; $serverdata['protocol'] = $data->version->protocol; $serverdata['players'] = $data->players->online; $serverdata['maxplayers'] = $data->players->max; $motd = $data->description; $motd = preg_replace("/(§.)/", "",$motd); $motd = preg_replace("/[^[:alnum:][:punct:] ]/", "", $motd); $serverdata['motd'] = $motd; $serverdata['motd_raw'] = $data->description; $serverdata['favicon'] = $data->favicon; $serverdata['ping'] = $ping; } else { $start = microtime(true); socket_send($socket, "\xFE\x01", 2, 0); $length = socket_recv($socket, $data, 512, 0); $ping = round((microtime(true)-$start)*1000);//calculate the high five duration if($length < 4 || $data[0] != "\xFF") { return false; } $motd = ""; $motdraw = ""; //Evaluate the received data if (substr((String)$data, 3, 5) == "\x00\xa7\x00\x31\x00"){ $result = explode("\x00", mb_convert_encoding(substr((String)$data, 15), 'UTF-8', 'UCS-2')); $motd = $result[1]; $motdraw = $motd; } else { $result = explode('§', mb_convert_encoding(substr((String)$data, 3), 'UTF-8', 'UCS-2')); foreach ($result as $key => $string) { if($key != sizeof($result)-1 && $key != sizeof($result)-2 && $key != 0) { $motd .= '§'.$string; } } $motdraw = $motd; } $motd = preg_replace("/(§.)/", "", $motd); $motd = preg_replace("/[^[:alnum:][:punct:] ]/", "", $motd); //Remove all special characters from a string $serverdata['version'] = $result[0]; $serverdata['players'] = $result[sizeof($result)-2]; $serverdata['maxplayers'] = $result[sizeof($result)-1]; $serverdata['motd'] = $motd; $serverdata['motd_raw'] = $motdraw; $serverdata['ping'] = $ping; } $this->disconnect($socket); return $serverdata; } private function connect($host, $port) { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!@socket_connect($socket, $host, $port)) { $this->disconnect($socket); return false; } return $socket; } private function disconnect($socket) { if($socket != null) { socket_close($socket); } } private function read_packet_length($socket) { $a = 0; $b = 0; while(true) { $c = socket_read($socket, 1); if(!$c) { return 0; } $c = Ord($c); $a |= ($c & 0x7F) << $b++ * 7; if( $b > 5 ) { return false; } if(($c & 0x80) != 128) { break; } } return $a; } } adiciona essa linha no teste.php pra ver porque ta dando offline error_reporting(E_ALL); Link para o comentário Compartilhar em outros sites More sharing options...
Cain Postado Junho 1, 2015 Autor Denunciar Compartilhar Postado Junho 1, 2015 (editado) adiciona essa li adiciona essa linha no teste.php pra ver porque ta dando offline error_reporting(E_ALL); Assim? <style> .titulos{color:#00a4cc; font-weight:bold;} </style> <?php error_reporting(E_ALL); $ip = 'jogar.mysticcraft.com.br'; //Ip do servidor $versao = '1.5.*'; //Versão: 1.7.* ou 1.6.* ou 1.5.* $porta = 25565; //Porta do servidor include_once 'status.class.php'; //o arquivo que criamos anteriormente $status = new MinecraftServerStatus(); $resultado = $status->getStatus($ip, $versao, $porta); if(!$resultado) { echo '<span class="titulos">Servidor Offline!</span>';} else {?> <center> <? if($versao == '1.5.*'){ ?> <img width="64" height="64" src="<? echo $resultado['favicon']?>" /><br> <? } ?> <span class="titulos">Players Online/Total: <? echo $resultado['players'].'/'.$resultado['maxplayers'];?></span><br> <span class="titulos">Versão do Servidor: <? echo $resultado['version'];?></span><br> <span class="titulos">Ip do Servidor: <? echo $resultado['hostname'];?></span><br> <span class="titulos">Legenda do Servidor: <br> <? echo $resultado['motd'];?></span><br> <span class="titulos">Está com PING de: <? echo $resultado['ping'];?>ms</span><br> </center> <?php } ?> Editado Junho 1, 2015 por Cain Link para o comentário Compartilhar em outros sites More sharing options...
Guest Dêemezeká Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 Assim? <style> .titulos{color:#00a4cc; font-weight:bold;} </style> <?php error_reporting(E_ALL); $ip = 'jogar.mysticcraft.com.br'; //Ip do servidor $versao = '1.5.*'; //Versão: 1.7.* ou 1.6.* ou 1.5.* $porta = 25565; //Porta do servidor include_once 'status.class.php'; //o arquivo que criamos anteriormente $status = new MinecraftServerStatus(); $resultado = $status->getStatus($ip, $versao, $porta); if(!$resultado) { echo '<span class="titulos">Servidor Offline!</span>';} else {?> <center> <? if($versao == '1.5.*'){ ?> <img width="64" height="64" src="<? echo $resultado['favicon']?>" /><br> <? } ?> <span class="titulos">Players Online/Total: <? echo $resultado['players'].'/'.$resultado['maxplayers'];?></span><br> <span class="titulos">Versão do Servidor: <? echo $resultado['version'];?></span><br> <span class="titulos">Ip do Servidor: <? echo $resultado['hostname'];?></span><br> <span class="titulos">Legenda do Servidor: <br> <? echo $resultado['motd'];?></span><br> <span class="titulos">Está com PING de: <? echo $resultado['ping'];?>ms</span><br> </center> <?php } ?> isso Link para o comentário Compartilhar em outros sites More sharing options...
Cain Postado Junho 1, 2015 Autor Denunciar Compartilhar Postado Junho 1, 2015 isso Não muda em nada. Link para o comentário Compartilhar em outros sites More sharing options...
Cain Postado Junho 1, 2015 Autor Denunciar Compartilhar Postado Junho 1, 2015 Ah que pena, então vou fazer um espaço apenas pra status, dai ele coloca .-. Link para o comentário Compartilhar em outros sites More sharing options...
Guest Dêemezeká Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 tenta usar a script do leosc, nem precisa de php, da uma olhada ai: http://gamersboard.com.br/topic/5079-js-easy-mostrando-os-jogadores-e-atualizando-sem-refresh/ Link para o comentário Compartilhar em outros sites More sharing options...
Guest Dêemezeká Postado Junho 1, 2015 Denunciar Compartilhar Postado Junho 1, 2015 Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas. Atenciosamente, Gamer's Board Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
Cain
Estou com esse erro, quero aprender php pra por status num site que estou fazendo, estou com o seguinte erro:
Segui esse tutorial
http://gamersboard.com.br/topic/289-status-do-seu-server-facil-e-r%C3%A1pido/?hl=%2Bstatus+%2Bminecraft
O meu codigo no teste.php
Link para o comentário
Compartilhar em outros sites
12 respostass a esta questão
Posts Recomendados