Skocz do zawartości
  • 0
X3nO

Blank screen (?)

Pytanie

Witam, mam problem z pustą stroną. Nie wyświetlają się nawet errory przez co nie mogę sprawdzić co jest źle. Mój kod:

	public function render()
	{
		ini_set('display_errors', 1);
		ini_set('display_startup_errors', 1);
		error_reporting(E_ALL);
		require "applications/serverviewer/lgsl_class.php";

		$server_list = lgsl_query_group();
		$server_list = lgsl_sort_servers($server_list);

		$server['num'] = 0;
		$output = [];
		foreach ($server_list as $server) {
			$server['misc'] = lgsl_server_misc($server);
			$server = lgsl_server_html($server);
			$server['num']++;
			if ($server['s']['players'] > 0 ) {
				$server['$serverclientsvalue'] = ($server['s']['players']) / ($server['s']['playersmax']) *100;
				$server['$serverclients'] = number_format($server['$serverclientsvalue'], 0);
			} else {
				$server['serverclients'] = number_format(0, 0);
			}
			$output[] = $server;
		}

		return $this->output( $output );
	}

Oraz szablon:

<ips:template parameters="$output" />
<h2 class="ipsType_sectionTitle ipsType_reset ipsType_blendLinks cForumTitle">Lista serwerów</h2>
<table class="ipsTable ipsTable_responsive ipsTable_zebra ipsBox">
	<thead>
		<tr>
			<td style="text-align: center;">#</td>
			<td style="text-align: center;">Status</td>
			<td style="text-align: center;">Gra</td>
			<td style="text-align: center;">Adres IP</td>
			<td style="text-align: center;">Nazwa serwera</td>
			<td style="text-align: center;">Mapa</td>
			<td style="text-align: center;">Graczy</td>
			<td style="text-align: center;">Dodatki</td>
		</tr>
	</thead>
	<tbody>
		{{foreach $output as $server}}
		<tr>
			<td style="text-align: center;">
				<img data-ipstooltip _title="Numer: {$server['num']}" src="http://goldenshoot.pl/ikony/{$a['type']}.gif">
			</td>
			<td style="text-align: center;">
				{$server['misc']['icon_status_ipb']}
			</td>
			<td style="text-align: center;">
				<img src='{$server['misc']['icon_game']}' data-ipstooltip _title='{$server['misc']['text_type_game']}' />
			</td>
			<td style="text-align: center;">
				{$server['b']['ip']}:{$server['b']['c_port']}
			</td>
			<td style="text-align: center;">
				{$server['s']['name']}
			</td>
			<td style="text-align: center;">
				{$server['s']['map']}
			</td>
			<td style="text-align: center;">
				<a data-ipstooltip _title="{$server['s']['players']} / {$server['s']['playersmax']} ({$serverclients}%)" class="ipsAttachment_progress" style="width: 78px;">
					<span style="width: {$serverclients}%; background-color: #3c6994"></span>
				</a>
			</td>
			<td style="text-align: center;">
				<a data-ipstooltip _title="Kilknij, aby zobaczyć informacje o serwerze" href="#" data-ipsdialog data-ipsdialog-url="#" data-ipsdialog-title="Informacje o serwerze" class="ipsButton ipsButton_primary ipsButton_verySmall"><i class="fa fa-bar-chart"></i></a>
				<a data-ipstooltip _title="Kilknij, aby połączyć się z serwerem" href="{$server['misc']['software_link']}" data-ipsdialog-title="Połącz z serwerem" class="ipsButton ipsButton_primary ipsButton_verySmall"><i class="fa fa-play-circle-o"></i></a>
			</td>
		</tr>
		{{endforeach}}
    </tbody>
</table><br />

I tutaj moja prośba o nakierowanie na zrobiony przeze mnie błąd ;c

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

12 odpowiedzi na to pytanie

Polecane posty

  • 0

Eh, nie ten kod ale problem ten sam,,

	public function render()
	{
		$server = [];
		foreach ( \IPS\Db::i()->select( '*', 'serverviewer_servers') as $row ) {
			switch ($row['type']) {
				case 'samp':
					$SampQueryAPI = new \IPS\serverviewer\sources\SampQueryAPI($row['ip'], $row['q_port']);
					$row['SampInformation'] = $SampQueryAPI->getInfo();
					if ($row['SampInformation']['players'] > 0 ) {
						$row['clientsvalue'] = ($row['SampInformation']['players']) / ($row['SampInformation']['maxplayers']) *100;
						$row['clients'] = number_format($row['clientsvalue'], 0);
					} else {
						$row['clients'] = number_format(0, 0);
					}
					$row['status'] = $SampQueryAPI->isOnline();
					$row['connect'] = $row['type']."://".$row['ip'].":".$row['c_port'];
					$row['hostname'] = $row['SampInformation']['hostname'];
					$row['mapname'] = $row['SampInformation']['mapname'];
					$row['players'] = $row['SampInformation']['players'];
					$row['maxplayers'] = $row['SampInformation']['maxplayers'];
					break;

				case 'ts3':
					$row['mapname'] = "TS3";
					$row['connect'] = "ts3server://".$row['ip'].":".$row['c_port'];
					break;
				
				default:
					$row['connect'] = $row['type']."://".$row['ip'].":".$row['c_port'];
					break;
			}
			if (empty($row['status'])) $row['status'] = "Brak odpowiedzi";
			if (empty($row['hostname'])) $row['hostname'] = "Brak odpowiedzi";
			if (empty($row['mapname'])) $row['mapname'] = "Brak odpowiedzi";
			$server[] = $row;
		}

		return $this->output( $server );
	}
<ips:template parameters="$server" />
<h2 class="ipsType_sectionTitle ipsType_reset ipsType_blendLinks cForumTitle">Lista serwerów</h2>
<table class="ipsTable ipsTable_responsive ipsTable_zebra ipsBox">
	<thead>
		<tr>
			<th style="text-align: center;">Gra</th>
			<th style="text-align: center;">Status</th>
			<th style="text-align: center;">Adres IP</th>
			<th style="text-align: center;">Nazwa serwera</th>
			<th style="text-align: center;">Mapa</th>
			<th style="text-align: center;">Graczy</th>
			<th style="text-align: center;">Dodatki</th>
		</tr>
	</thead>
	<tbody>
		{{foreach $server as $server}}
		<tr>
			<td style="text-align: center;">
				<img src="applications/serverviewer/sources/icons/{$server['type']}.png" />
			</td>
			<td style="text-align: center;">
				{{if $server['status']}}
					<span class="ipsBadge ipsBadge_positive">Dostępny</span>
				{{else}}
					<span class="ipsBadge ipsBadge_negative">Brak odpowiedzi</span>
				{{endif}}
			</td>
			<td style="text-align: center;">
				{$server['ip']}:{$server['c_port']}
			</td>
			<td style="text-align: center;">
				{$server['hostname']|raw}
			</td>
			<td style="text-align: center;">
				{$server['mapname']|raw}
			</td>
			<td style="text-align: center;">
				<a data-ipstooltip _title="{$server['players']} / {$server['maxplayers']} ({$server['clients']}%)" class="ipsAttachment_progress" style="width: 78px;">
					<span style="width: {$server['clients']}%; background-color: #3c6994"></span>
				</a>
			</td>
			<td style="text-align: center;">
				<a data-ipstooltip _title="Kilknij, aby zobaczyć informacje o serwerze" href="#" data-ipsdialog data-ipsdialog-url="#" data-ipsdialog-title="Informacje o serwerze" class="ipsButton ipsButton_primary ipsButton_verySmall"><i class="fa fa-bar-chart"></i></a>
				<a data-ipstooltip _title="Kilknij, aby połączyć się z serwerem" href="{$server['connect']}" data-ipsdialog-title="Połącz z serwerem" class="ipsButton ipsButton_primary ipsButton_verySmall"><i class="fa fa-play-circle-o"></i></a>
			</td>
		</tr>
		{{endforeach}}
    </tbody>
</table><br />
<?php
/**
 *	This API connects directly to the server, without any need for any
 *	middlemen connections.
 *	Your server must have fsockopen enabled in order to access the 
 *	functions that have been made available from this.
 *
 *	@package sampAPI
 *	@version 1.2
 *	@author David Weston <westie@typefish.co.uk>
 *	@copyright 2010; http://www.typefish.co.uk/licences/
 */

namespace IPS\serverviewer\sources;

class _SampQueryAPI
{
	/**
	 *	@ignore
	 */
	protected $rSocket = false;
	
	
	/**
	 *	@ignore
	 */
	protected $aServer = array();
	
	
	/**
	 *	Creation of the server class.
	 *
	 *	@param string $sServer Server IP, or hostname.
	 *	@param integer $iPort Server port
	 */
	public function __construct($sServer, $iPort = 7777)
	{
		/* Fill some arrays. */
		$this->aServer[0] = $sServer;
		$this->aServer[1] = $iPort;
		
		/* Start the connection. */	
		$this->rSocket = fsockopen('udp://'.$this->aServer[0], $this->aServer[1], $iError, $sError, 2);
		
		if(!$this->rSocket)
		{
			$this->aServer[4] = false;
			return;
		}
		
		socket_set_timeout($this->rSocket, 2);
		
		$sPacket = 'SAMP';
		$sPacket .= chr(strtok($this->aServer[0], '.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr($this->aServer[1] & 0xFF);
		$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
		$sPacket .= 'p4150';
		
		fwrite($this->rSocket, $sPacket);
		
		if(fread($this->rSocket, 10))
		{
			if(fread($this->rSocket, 5) == 'p4150')
			{
				$this->aServer[4] = true;
				return;
			}
		}
		
		$this->aServer[4] = false;
	}
	
	
	/**
	 *	@ignore
	 */
	public function __destruct()
	{
		@fclose($this->rSocket);
	}
	
	
	/**
	 *	Used to tell if the server is ready to accept queries.
	 *
	 *	If false is returned, then it is suggested that you remove the
	 *	class from active use, so that you can reload the class if needs
	 *	be.
	 *
	 *	@return bool true if success, false if failure.
	 */
	public function isOnline()
	{
		return isset($this->aServer[4]) ? $this->aServer[4] : false;
	}
	
	
	/**
	 *	This function is used to get the server information.
	 *
	 *	<code>
	 *	Array
	 *	(
	 *		[password] => 0
	 *		[players] => 9
	 *		[maxplayers] => 500
	 *		[hostname] => Everystuff Tr3s [MAD]oshi (03a Final) [FIXED]
	 *		[gamemode] => Stunt/Race/DM/FR Everystuff
	 *		[mapname] => Everystuff
	 *	)
	 *	</code>
	 *
	 *	@return array Array of server information.
	 */
	public function getInfo()
	{
		@fwrite($this->rSocket, $this->createPacket('i'));
		
		fread($this->rSocket, 11);
	
		$aDetails['password'] = (integer) ord(fread($this->rSocket, 1));
		
		$aDetails['players'] = (integer) $this->toInteger(fread($this->rSocket, 2));
		
		$aDetails['maxplayers'] = (integer) $this->toInteger(fread($this->rSocket, 2));
		
		$iStrlen = ord(fread($this->rSocket, 4));
		if(!$iStrlen) return -1;
		
		$aDetails['hostname'] = (string) fread($this->rSocket, $iStrlen);
		
		$iStrlen = ord(fread($this->rSocket, 4));
		$aDetails['gamemode'] = (string) fread($this->rSocket, $iStrlen);
		
		$iStrlen = ord(fread($this->rSocket, 4));
		$aDetails['mapname'] = (string) fread($this->rSocket, $iStrlen);
		
		return $aDetails;
	}
	
	
	/**
	 *	This function gets a basic list of all the players on the server.
	 *
	 *	Note as of 0.3.0, the amount of players that can be retrieved is
	 *	limited to 100. This means if there are more players than 100,
	 *	then no data will be returned, and it will be a blank array.
	 *
	 *	<code>
	 *	Array
	 *	(
	 *		[0] => Array
 	 *			(
	 *				[nickname] => K1nNngO
	 *				[score] => 72
	 *			)
	 *		
	 *		[1] => Array
	 *			(
	 *				[nickname] => [kikOo]
	 *				[score] => 150
	 *			)
	 *
	 *		[and so on...]
	 *	)
	 *	</code>
	 *
	 *	@return array Array of player information.
	 */
	public function getBasicPlayers()
	{
		@fwrite($this->rSocket, $this->createPacket('c'));
		fread($this->rSocket, 11);
		
		$iPlayerCount = ord(fread($this->rSocket, 2));
		$aDetails = array();
		
		if($iPlayerCount > 0)
		{
			for($iIndex = 0; $iIndex < $iPlayerCount; ++$iIndex)
			{
				$iStrlen = ord(fread($this->rSocket, 1));
				$aDetails[] = array
				(
					"nickname" => (string) fread($this->rSocket, $iStrlen),
					"score" => (integer) $this->toInteger(fread($this->rSocket, 4)),
				);
			}
		}
		
		return $aDetails;
	}
	
	
	/**
	 *	This function gets a detailed list of all the players on the server.
	 *
	 *	Note as of 0.3.0, the amount of players that can be retrieved is
	 *	limited to 100. This means if there are more players than 100,
	 *	then no data will be returned, and it will be a blank array.
	 *
	 *	<code>
	 *	Array
	 *	(
	 *		[0] => Array
	 *			(
	 *				[playerid] => 0
	 *				[nickname] => K1nNngO
 	 *				[score] => 72
	 *				[ping] => 195
	 *			)
	 *	
	 *		[1] => Array
	 *			(
	 *				[playerid] => 1
	 *				[nickname] => [kikOo]
	 *				[score] => 150
	 *				[ping] => 375
	 *			)
	 *
	 *		[and so on...]
	 *	)
	 *	</code>
	 *
	 *	@return array Array of player information.
	 */
	public function getDetailedPlayers()
	{
		@fwrite($this->rSocket, $this->createPacket('d'));
		fread($this->rSocket, 11);
	
		$iPlayerCount = ord(fread($this->rSocket, 2));
		$aDetails = array();
		
		for($iIndex = 0; $iIndex < $iPlayerCount; ++$iIndex)
		{
			$aPlayer['playerid'] = (integer) ord(fread($this->rSocket, 1));
			
			$iStrlen = ord(fread($this->rSocket, 1));
			$aPlayer['nickname'] = (string) fread($this->rSocket, $iStrlen);
			
			$aPlayer['score'] = (integer) $this->toInteger(fread($this->rSocket, 4));
			$aPlayer['ping'] = (integer) $this->toInteger(fread($this->rSocket, 4));
			
			$aDetails[] = $aPlayer;
			unset($aPlayer);
		}
		
		return $aDetails;
	}
	
	
	/**
	 *	This function gets all the server rules from the server.
	 *
	 *	Rules in this context are not player rules, they are client rules,
	 *	like the weather of the server, time, and so on. (Custom rules,
	 *	when supported by a SA-MP plugin, will be included here.) 
	 *
	 *	<code>
	 *	Array
	 *	(
	 *		[gravity] => 0.007900
	 *		[mapname] => Everystuff
	 *		[version] => 0.3a
	 *		[weather] => 0
	 *		[weburl] => samp.madoshi.net
	 *		[worldtime] => 12:00
	 *	)
	 *	</code>
	 *
	 *	@return array Array of server rules.
	 */
	public function getRules()
	{
		@fwrite($this->rSocket, $this->createPacket('r'));
		fread($this->rSocket, 11);
		
		$iRuleCount = ord(fread($this->rSocket, 2));
 		$aReturn = array();
		
		for($iIndex = 0; $iIndex < $iRuleCount; ++$iIndex)
		{
			$iStrlen = ord(fread($this->rSocket, 1));
			$sRulename = (string) fread($this->rSocket, $iStrlen);
			
			$iStrlen = ord(fread($this->rSocket, 1));
			$aDetails[$sRulename] = (string) fread($this->rSocket, $iStrlen);
		}
		
		return $aDetails;
	}
	
	
	/**
	 *	@ignore
	 */
	protected function toInteger($sData)
	{
		if($sData === "")
		{
			return null;
		}
		
 		$iInteger = 0;
 		$iInteger += (ord($sData[0]));
 
 		if(isset($sData[1]))
 		{
 			$iInteger += (ord($sData[1]) << 8);
 		}
 		
 		if(isset($sData[2]))
 		{
 			$iInteger += (ord($sData[2]) << 16);
 		}
 		
 		if(isset($sData[3]))
 		{
 			$iInteger += (ord($sData[3]) << 24);
 		}
 		
 		if($iInteger >= 4294967294)
		{
 			$iInteger -= 4294967296;
		}
 		
 		return $iInteger;
	}
	
	
	/**
	 *	@ignore
	 */
	protected function createPacket($sPayload)
	{
		$sPacket = 'SAMP';
		$sPacket .= chr(strtok($this->aServer[0], '.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr(strtok('.'));
		$sPacket .= chr($this->aServer[1] & 0xFF);
		$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
		$sPacket .= $sPayload;
	
		return $sPacket;
	}
}

 

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0

A w pliku z logami albo coś? tak się nie da tego zweryfikować na podstawie fragmentu kodu

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0

Log z ACP:

Whoops\Exception\ErrorException: You have used a file management function directly (/applications/serverviewer/sources/SampQueryAPI.php::62). Please use the proper APIs instead. (256)

 

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0

no i masz błąd. nie powinieneś używać

require "applications/serverviewer/lgsl_class.php";

tylko użyć do tego

require \IPS\ROOT_PATH . "/applications/serverviewer/lgsl_class.php";

 

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0
3 godziny temu, Spanner napisał:

no i masz błąd. nie powinieneś używać


require "applications/serverviewer/lgsl_class.php";

tylko użyć do tego


require \IPS\ROOT_PATH . "/applications/serverviewer/lgsl_class.php";

 

W 1 poście dałem nie ten kod, patrz 2 post

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0

ok, to chyba wiem o co chodzi. nie powinieneś używać

fsockopen

tylko użyć ich api do pobierania danych 

\IPS\Http\Url::external();

 

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0
Cytat

Whoops\Exception\ErrorException: socket_set_timeout() expects parameter 1 to be resource, object given (2)

$this->rSocket = \IPS\Http\Url::external('udp://'.$this->aServer[0], $this->aServer[1], $iError, $sError, 2);

Raczej źle używam tej funkcji

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0

Sprawdź jakie parametry mają być co przekazujesz itp a będziesz wiedzieć

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0
	public static function external( $url )
	{
		return new static( $url, FALSE );
	}

Ta funkcja niewiele mi mówi, mogę prosić o nakierowanie (czyt. gotowca)

Edytowano przez X3nO

Udostępnij ten post


Link to postu
Udostępnij na innych stronach
  • 0

tzn, że do external przekazujesz tylko jeden parametr, którym jest adres. Jeśli chcesz dodatkowe rzeczy ustawić, to zobacz jak ustawić parametry. Przykładowo to jest wywołanie get'em:

$response = \IPS\Http\Url::external( 'http://www.ipsbeyond.pl/' )->request()->get();

 

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

Bądź aktywny! Zaloguj się lub utwórz konto

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony


  • Kto przegląda   0 użytkowników

    Brak zalogowanych użytkowników przeglądających tę stronę.

×

Ważne informacje

Kontynuując przeglądanie strony, wyrażasz zgodę na używanie przez nas plików cookies.