[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
#2

nice tutorial
Reply
#3

Nice tut man.
Reply
#4

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.
Reply
#5

Great tutorial!
Reply
#6

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

I doubt it but whats the harm in asking?
Reply
#7

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.
Reply
#8

Awesome. $2 is cheap, Especially for life. Thanks.
Reply
#9

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

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..
Reply
#11

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.
Reply
#12

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

Nice tut!

Ecko
Reply
#14

Nice TUT
Reply
#15

Oh,is easy, good work man.

I Creted \'Connection Checker DKN\' using packets!
Reply
#16

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

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!
Reply
#18

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

(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]
Reply
#20

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
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)