SAMP query script [php]
#1

Hey, how can i make a samp query script i got this (only need to check offline - online )

PHP Code:
<? if (!isset($ip))
        
$ip '83.149.98.25';
    if (!isset(
$port))
        
$port 3333;

    
$fp fsockopen('udp://' $ip$port$errno$errstr);
    if (!
$fp)
    {
        echo 
"Server status: Offline";
    }
  else
  {
    echo 
"Server status: Online";
  }  
?>
Reply
#2

its nott working im not a php expert maybe can someone fix mah code? :P
Reply
#3

Im building a whole damn website built around my samp server. Heres the function i wrote today when i was making my live rcon line.
Code:
define("game_server_host","IP");
define("game_server_port",PORT);
//^^ Just make sure the command can read this unless you change them. I have them defined because i use them across my whole website

function GetGTAServerStatus($image,$hostname,$port)
{
	$realtimeout = ini_get("default_socket_timeout");
	ini_set("default_socket_timeout","1");
	if(!isset($image)) $image = 1;
	if(!isset($hostname)) $fp = fsockopen("udp://".game_server_host, game_server_port, $errno, $errstr);
	else if(isset($hostname) && !isset($port)) $fp = fsockopen("udp://".$hostname, 7777, $errno, $errstr);
  else if(isset($hostname) && isset($port)) $fp = fsockopen("udp://".$hostname, $port, $errno, $errstr);
	ini_set("default_socket_timeout",$realtimeout);
	if($fp)
	{
		$packet = 'SAMP';
		$packet .= chr(strtok($ip, '.')).chr(strtok('.')).chr(strtok('.')).chr(strtok('.'));
		$packet .= chr($port & 0xFF);
		$packet .= chr($port >> 8 & 0xFF);

		fwrite($fp, $packet.'i');
		fread($fp, 11);
		$is_passworded = ord(fread($fp, 1));
		$plr_count   = ord(fread($fp, 2));
		$max_plrs   = ord(fread($fp, 2));
		$strlen    = ord(fread($fp, 4));
		$hostname   = fread($fp, $strlen);
		fclose($fp);
		if(strlen($hostname) > 0)
		{
			if($image) echo("<center><a href=\"status.php\"><img src=\"images/serverup.png\" alt=\"The Game Server Is Up!\" border=\"0\"></a></center>");
			return 1;
		}
		if(strlen($hostname) == 0)
		{
			if($image) echo("<center><img src=\"images/serverdown.png\" alt=\"The Game Server Is Down!\"></center>");
			return 0;
		}
	}
	if($image) echo("<center><img src=\"images/serverdown.png\" alt=\"The Game Server Is Down!\"></center>");
	return 0;
}
Syntax: GetGTAServerStatus($image,$hostname,$port);
$image = Integer, 1 or 0. Declares whether or not to echo the image(serverup/serverdown).
$hostname = if not defined, uses the declared game_server_host.
$port = if not defined, uses the declared game_server_port;
if $hostname is defined, but port is not, it uses port 7777.

I hope you enjoy it. When you first start your server, give it 30 seconds or so to get the socket running.

EDIT: the reason for the if(strlen($hostname) == 0) is because sometimes the socket still connects for some strange reason but it wont be able to get the variables. with that it does a double check to see if its connected.
The reason i set the ini to 1, is because for some reason it takes me for effin ever to get a no connection error without it. even when i put 1, it doesnt work.
Reply
#4

from where did you get packet to send ?
$packet << SAMP... From where to find for other servers ? for example Counter Strike..
Reply
#5

and whats with the status.php? whats the function of this php?
Reply
#6

Quote:
Originally Posted by nodarinodo
View Post
from where did you get packet to send ?
$packet << SAMP... From where to find for other servers ? for example Counter Strike..
Common sense and ******.

Quote:
Originally Posted by gcw
View Post
and whats with the status.php? whats the function of this php?
function GetGTAServerStatus($image,$hostname,$port)
Reply
#7

Fatal error: Cannot redeclare class functions in /var/www/UCP/functions.php on line 18
ah damn im not php pro, can you help me?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)