Parsing Packets With PHP (Cool Title Don't Ya Think - God I Need To Get A Life.)
Anyway, I have been playing around with the code that was posted on the fourms here not to long ago by our resident PHP InSim Guru filur. Anyway, in his exprament he simply took the first 3 charaters from the packet and added a little Keanu Reeves 'Whoa' to it then thow it out for us all to see. But it only had the packet identifier, it did not have information on what the packet really had in it.
So this it my (failed) attemp to read a LAP packet from the server using PHP.
<?php
php
stream_set_blocking( $socketOut = fsockopen( "udp://127.0.0.1", 65000 ), FALSE );
stream_set_blocking( $socketIn = stream_socket_server( "udp://127.0.0.1:64999", $errno, $errstr, STREAM_SERVER_BIND ), FALSE );
fwrite( $socketOut, "ISI\0" . pack( "Scc", 64999, 1+8+16+32, 1 ) . str_pad( "asdf", 16, "\0" ) );
$time = microtime( TRUE );
while( microtime( TRUE ) - $time < 30 )
{
if( $packet = fread( $socketIn, 1024 ) )
{
$time = microtime( TRUE );
switch( substr( $packet, 0, 3 ) )
{
case 'LAP':
$LAP['LAP'] = substr( $packet, 0, 3 );
$LAP['UName'] = substr( $packet, 4, 28);
$LAP['PName'] = substr( $packet,29, 33);
$LAP['CName'] = substr( $packet,34, 66);
$LAP['Time'] = substr( $packet,67, 61);
$LAP['PlyNum'] = substr( $packet,62, 63);
$LAP['UniqueId']= substr( $packet,64, 65);
$LAP['VerifyId']= substr( $packet,66, 68);
break;
default:
echo "Packet " . substr( $packet, 0, 3 ) . " Is Unhandled\n";
}
}
usleep(100 * 1000);
}
?>