SA-MP Forums Archive
[TUTORIAL] Reading SA-MP Server packets in PHP. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [TUTORIAL] Reading SA-MP Server packets in PHP. (/showthread.php?tid=71532)

Pages: 1 2


[TUTORIAL] Reading SA-MP Server packets in PHP. - Norn - 01.04.2009

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.


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - brett7 - 01.04.2009

nice tutorial


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Pyrokid - 02.04.2009

Nice tut man.


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - tom_jonez - 02.04.2009

pretty cool
ill be releasing my php/mysql player image srcipt to allow people to have there stats posted in an image from a mysql server.


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - MenaceX^ - 02.04.2009

Great tutorial!


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - On_Top_Non_Stop - 02.04.2009

Is there any free hosts that support PHP and fsockopen/fclose.

I doubt it but whats the harm in asking?


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Norn - 02.04.2009

Quote:
Originally Posted by On_Top_Non_Stop
Is there any free hosts that support PHP and fsockopen/fclose.

I doubt it but whats the harm in asking?
v-hosting.co.uk, it's not exactly free. ($2) but you pay once and you have hosting for life. And it's extremely fast.


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - On_Top_Non_Stop - 02.04.2009

Awesome. $2 is cheap, Especially for life. Thanks.


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - StrickenKid - 07.04.2009

how do you get the gravity and weburl and weather and worldtime by reading the packets?


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Nubotron - 07.04.2009

Quote:
Originally Posted by Norn
Because you can create stuff like this.
I am curious what else you can do.. for me a tutorial should explain how things work, and give some different exemples, not just showing a know script and saying "This open socket" and "This check connection".. In a tutorial, all lines of script should be commented. You may be know how it work, but peolple who need a tutorial for open socket and check connection, probably they do not know how it work at all..


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Think - 23.05.2009

Quote:
Originally Posted by <__Ǝthan__>
how do you get the gravity and weburl and weather and worldtime by reading the packets?
did someone answer this one because i need it too.


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Google63 - 23.05.2009

you can do that with YSF(changing and adding rules = weburl, gravity etc. text).. a lot of easier


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - .::: Ecko :::. - 23.05.2009

Nice tut!

Ecko


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - HyperZ - 12.10.2010

Nice TUT


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - ipsBruno - 12.10.2010

Oh,is easy, good work man.

I Creted \'Connection Checker DKN\' using packets!


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Kwarde - 13.10.2010

Omg it should be better if you made it yourself:
http://www.otaku-studios.com/showthr...packets-in-PHP.


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - woot - 13.10.2010

Quote:
Originally Posted by Kwarde
View Post
Omg it should be better if you made it yourself:
http://www.otaku-studios.com/showthr...packets-in-PHP.
Even my 3 year old brother figured out that both thread submitters have the same username. Palm your face. FACEPALM!


@OT: Handy!


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Kwarde - 13.10.2010

*facepalm* indeed.
Shame me. But I know what it is. I looked at the wrong name :/


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Mauzen - 13.10.2010

(permission to slap me)

[phpnoob]

I am getting this error:


Fatal error: Only variables can be passed by reference in /data/multiserv/users/161811/projects/189964/www/b.php on line 12


with line 12 beeing this:

$fp = fsockopen("udp://", "127.0.0.1", "1337", $errno, $errstr);

(all strings can be changed, if i remove a param, the script stops)


Any solution?

[/phpnoob]


Re: [TUTORIAL] Reading SA-MP Server packets in PHP. - Kwarde - 13.10.2010

Yeah I had that too.
TRY this:

PHP Code:
<?php
$ip 
""//SERVER IP!
$port ""//SERVER PORT!

$fp fsockopen("udp://"$ip$port$errno$errstr);
//The code ...
?>
If that\'s not working, I recommend this: https://sampforum.blast.hk/showthread.php?tid=104299