Ir para conteúdo
  • Cadastre-se

Posts Recomendados

Eu estava colocando um script php em meu site que mostra quantos players estão online no servidor, ele até está mostrando mas fica dando o seguinte "erro".

 Notice: Undefined property: ServStatus::$checkTime in C:\Program Files (x86)\VertrigoServ\www\playerson\status.class.php on line 27
Call Stack
#	Time	Memory	Function	Location
1	0.0010	332320	{main}( )	..\status.php:0
2	0.0020	405048	ServStatus->Connect( )	..\status.php:30

( ! ) Notice: Undefined property: ServStatus::$checkTime in C:\Program Files (x86)\VertrigoServ\www\playerson\status.class.php on line 195
Call Stack
#	Time	Memory	Function	Location
1	0.0010	332320	{main}( )	..\status.php:0
2	0.0020	405048	ServStatus->Connect( )	..\status.php:30
3	0.3430	408824	ServStatus->SaveStatus( )	..\status.class.php:88

( ! ) Notice: Undefined variable: host in C:\Program Files (x86)\VertrigoServ\www\playerson\status.class.php on line 215
Call Stack
#	Time	Memory	Function	Location
1	0.0010	332320	{main}( )	..\status.php:0
2	0.0020	405048	ServStatus->Connect( )	..\status.php:30
3	0.3430	408824	ServStatus->SaveStatus( )	..\status.class.php:88

( ! ) Warning: file_put_contents(status\) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in C:\Program Files (x86)\VertrigoServ\www\playerson\status.class.php on line 215
Call Stack
#	Time	Memory	Function	Location
1	0.0010	332320	{main}( )	..\status.php:0
2	0.0020	405048	ServStatus->Connect( )	..\status.php:30
3	0.3430	408824	ServStatus->SaveStatus( )	..\status.class.php:88
4	0.3440	410584	file_put_contents ( )	..\status.class.php:215

Aqui o arquivo php

<?PHP
/*===========================================*\
|| # OTServ Status 1.2                     # ||
|| # -----------------------------------   # ||
|| # Developed by Robson Dias (aka v0id5)  # ||
|| # https://github.com/v0id5/OTServStatus # ||
\*===========================================*/

/*

	<! Notes !>
	1. For now the class is using preg_match, but we are changing it for a better way, to avoid some errors that may occur.
	
*/

class ServStatus {
	
	function Connect($host, $port) {
		
		$this->Host = $host;
		$this->Port = $port;
		
		// load status file
		$Status = @parse_ini_file("status\\{$host}");
		
		// check time to next server check
		if($Status['LastCheck'] <= (time() - $this->checkTime)) {
		
			$Socket = fsockopen($host, $port, $errno, $errstr, 5);
			
			if(!$Socket) {
				return false;
			} else {

				stream_set_timeout($Socket, 1);
				stream_set_blocking($Socket, false);

				fwrite($Socket, chr(6).chr(0).chr(255).chr(255).'info');
				while(!feof($Socket)) {
					$this->SocketData .= fgets($Socket, 8192);
				}
				fclose($Socket);

				preg_match('/players online="(\d+)" max="(\d+)"/', $this->SocketData, $matches);
				$this->Players = $matches[1];
				$this->PlayersMax = $matches[2];

				preg_match('/uptime="(\d+)"/', $this->SocketData, $matches);
				$this->UptimeHour = floor($matches[1] / 3600);
				$this->UptimeMinutes = floor(($matches[1] - $this->UptimeHour * 3600) / 60);

				preg_match('/monsters total="(\d+)"/', $this->SocketData, $matches);
				$this->Monsters = $matches[1];
				
				// update players peak
				if($this->Players > $Status['PlayersPeak']) {
					$this->PlayersPeak = $this->Players;
				} else {
					$this->PlayersPeak = $Status['PlayersPeak'];
				}

				preg_match('#server="(.*?)" version="(.*?)"#s', $this->SocketData, $matches);
				$this->ServerVersion = "{$matches[1]} {$matches[2]}";

				// Get current number of npcs on server
				// NOTE: on some servers, it returns zero
				preg_match('#npcs total="(.*?)"#s', $this->SocketData, $matches);
				$this->NPCs = $matches[1];

				preg_match('#name="(.*?)" author="(.*?)" width="(.*?)" height="(.*?)"#s', $this->SocketData, $matches);
				$this->MapName = $matches[1];
				$this->MapAuthor = $matches[2];
				$this->MapWidth = $matches[3];
				$this->MapHeight = $matches[4];

				preg_match('#servername="(.*?)"#s', $this->SocketData, $matches);
				$this->ServerName = $matches[1];
				
				// Get current server client version
				// NOTE: on some servers this doesn't work
				preg_match('#client="(.*?)"#s', $this->SocketData, $matches);
				$this->ClientVersion = $matches[1];
				
				preg_match('#ip="(.*?)"#s', $this->SocketData, $matches);
				$this->ServerIP = $matches[1];

				// save status file
				$this->SaveStatus();
				
				return true;
			}
		} else {
			
			$this->ServerIP = $Server['ServerIP'];
			
			$this->Players = $Status['Players'];
			$this->PlayersMax = $Status['PlayersMax'];
			$this->PlayersPeak = $Status['PlayersPeak'];

			$this->UptimeHour = $Status['UptimeHours'];
			$this->UptimeMinutes = $Status['UptimeMinutes'];

			$this->NPCs = $Status['NPCs'];
			$this->Monsters = $Status['Monsters'];

			$this->MapWidth = $Status['MapWidth'];
			$this->MapHeight = $Status['MapHeight'];
			$this->MapName = $Status['MapName'];

			$this->ServerName = $Status['ServerName'];
			$this->ClientVersion = $Status['ClientVersion'];
			$this->ServerVersion = $Status['ServerVersion'];
			
			return true;
		}
	}
	
	function SetCheckTime($seconds) {
		$this->checkTime = (int) $seconds;
	}

	function PlayersPeak() {
		$PlayersPeak = (int) $this->PlayersPeak;
		return (!$PlayersPeak ? 0 : $PlayersPeak);
	}
	
	function ServerIP() {
		return $this->ServerIP;
	}
	
	function ServerVersion() {
		return (!$this->ServerVersion ? 'N/A' : $this->ServerVersion);
	}
	
	function ServerName() {
		return $this->ServerName;
	}
	
	function ClientVersion() {
		return $this->ClientVersion;
	}
	
	function Monsters() {
		$Monsters = (int) $this->Monsters;
		return (!$Monsters ? 0 : $Monsters);
	}
	
	function NPCs() {
		$NPCs = (int) $this->NPCs;
		return (!$NPCs ? 0 : $NPCs);
	}
	
	function UptimeHours() {
		$UptimeHour = (int) $this->UptimeHour;
		return (!$UptimeHour ? 0 : $UptimeHour);
	}
	
	function UptimeMinutes() {
		$UptimeMinutes = (int) $this->UptimeMinutes;
		return (!$UptimeMinutes ? 0 : $UptimeMinutes);
	}
	
	function Players() {
		$Players = (int) $this->Players;
		return (!$Players ? 0 : $Players);
	}
	
	function PlayersMax() {
		$PlayersMax = (int) $this->PlayersMax;
		return (!$PlayersMax ? 0 : $PlayersMax);
	}
	
	function MapName() {
		$MapName = (int) $this->MapName;
		return (!$MapName ? 0 : $MapName);
	}
	
	function MapAuthor() {
		$MapAuthor = (int) $this->MapAuthor;
		return (!$MapAuthor ? 0 : $MapAuthor);
	}
	
	function MapWidth() {
		$MapWidth = (int) $this->MapWidth;
		return (!$MapWidth ? 0 : $MapWidth);
	}

	function MapHeight() {
		$MapHeight = (int) $this->MapHeight;
		return (!$MapHeight ? 0 : $MapHeight);
	}
	
	private function SaveStatus() {
		$Status = array(
			'LastCheck' => time() + $this->checkTime,
			'ServerIP' => $this->ServerIP(),
			'Players' => $this->Players(),
			'PlayersMax' => $this->PlayersMax(),
			'PlayersPeak' => $this->PlayersPeak(),
			'UptimeHours' => $this->UptimeHours(),
			'UptimeMinutes' => $this->UptimeMinutes(),
			'Monsters' => $this->Monsters(),
			'ServerVersion' => $this->ServerVersion(),
			'NPCs' => $this->NPCs(),
			'MapName' => $this->MapName(),
			'MapAuthor' => $this->MapAuthor(),
			'MapWidth' => $this->MapWidth(),
			'MapHeight' => $this->MapHeight(),
			'ClientVersion' => $this->ClientVersion(),
		);
		foreach ($Status as $key => $content){
			$lines = "{$key} = {$content}";
		}
		// save config file
		file_put_contents("status\\{$host}", $lines);
	}

} 

Status servidor pokechu: online.png

assinatura.png

 

Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo