[TUTORIAL] Reading SA-MP Server packets in PHP.
#1

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):
Code:
$fp = fsockopen("udp://", "127.0.0.1", "1337", $errno, $errstr);
Now checking if the connection was a success and reading packets:
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);
    }
Now you can for example:
Code:
echo $gamemode;
this would output the servers gamemode text if it stored in the variable correctly.
Reply


Messages In This Thread
[TUTORIAL] Reading SA-MP Server packets in PHP. - by Norn - 01.04.2009, 23:25
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by brett7 - 01.04.2009, 23:37
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Pyrokid - 02.04.2009, 01:42
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by tom_jonez - 02.04.2009, 10:40
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by MenaceX^ - 02.04.2009, 11:04
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by On_Top_Non_Stop - 02.04.2009, 11:12
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Norn - 02.04.2009, 12:59
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by On_Top_Non_Stop - 02.04.2009, 13:33
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by StrickenKid - 07.04.2009, 06:58
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Nubotron - 07.04.2009, 07:28
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Think - 23.05.2009, 21:18
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Google63 - 23.05.2009, 21:22
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by .::: Ecko :::. - 23.05.2009, 21:23
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by HyperZ - 12.10.2010, 18:22
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by ipsBruno - 12.10.2010, 19:12
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Kwarde - 13.10.2010, 14:06
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by woot - 13.10.2010, 15:12
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Kwarde - 13.10.2010, 16:15
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Mauzen - 13.10.2010, 17:07
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Kwarde - 13.10.2010, 17:46
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Twain32 - 18.10.2010, 21:07
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by TrinityGamingRoleplay - 01.04.2014, 06:36
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Flake. - 01.04.2014, 07:05
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by stundje - 01.04.2014, 07:29
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by TrinityGamingRoleplay - 01.04.2014, 07:39
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by ChrisDamon - 07.06.2016, 04:17
Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - by Youssefree - 27.06.2016, 22:07

Forum Jump:


Users browsing this thread: 1 Guest(s)