01.04.2009, 23:25
(
Last edited by Norn; 16/08/2010 at 04:21 AM.
)
Reading SA-MP Server Packets with PHP.
Why is this useful? Because you can create stuff like this.
First open the socket (Obviously replacing 127.0.0.1 with your servers ip and 1337 with your servers port):
Now checking if the connection was a success and reading packets:
Now you can for example:
this would output the servers gamemode text if it stored in the variable correctly.
Why is this useful? Because you can create stuff like this.
First open the socket (Obviously replacing 127.0.0.1 with your servers ip and 1337 with your servers port):
Code:
$fp = fsockopen("udp://", "127.0.0.1", "1337", $errno, $errstr);
Code:
if ($fp) { $packet = 'SAMP'; $packet .= chr(strtok($ip, '.')); $packet .= chr(strtok('.')); $packet .= chr(strtok('.')); $packet .= chr(strtok('.')); $packet .= chr($port & 0xFF); $packet .= chr($port >> 8 & 0xFF); fwrite($fp, $packet); 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); $strlen = ord(fread($fp, 4)); $gamemode = fread($fp, $strlen); $strlen = ord(fread($fp, 4)); $mapname = fread($fp, $strlen); fclose($fp); }
Code:
echo $gamemode;