FOnline Development > Questions and Answers
FOnline SDK - Question
raynor009:
Wut i newer had the patients to learn web programmin .All i learned was VB.net ,C# and now i try C++
Surf:
Next time you should be a bit more grateful when people are trying to help you instead of writing "wut" or "wtf". ::)
jan0s1k:
--- Quote from: Wipe on January 04, 2011, 09:45:44 pm ---Seriously, it was 10m of work (including googling php socket function) - first (and probably last) time i used sockets in php... Yea, i know it's uberugly - CptRookie, don't say anything :>
--- End quote ---
I'm poor :( My work takes something around one week ;p and it isn't too much changes between my and yours script (in my I have some things to, if server is offline don't wait this 30 seconds, but it doesn't work -.-)
Misiolap:
@raynor009: added some commentary for you.
--- Code: ---<?php
$host = "94.23.237.127"; // Server IP address
$port = "2238"; // Server port
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die( "create\n" ); // create TCP Socket for server connection, abort on error
if( socket_connect( $socket, $host, $port ) ) // connect to $host:$port
{
$magic = pack( 'L', 0xFFFFFFFF ); // create "magic query packet" (4 0xff bytes)
socket_write($socket, $magic) || die( "write\n" ); // send "magic query packet" to server, abort on error
$buf = '';
$recv = socket_recv($socket, $buf, 16, MSG_PEEK ); // recieve server status (16 bytes)
socket_close($socket ); // disconnect
if( $recv < 16 ) // abort on too short data recieved
die( "recv\n" );
$data = unpack( 'V*', $buf ); // unpack recieved data - 4 Little Endian integers - 1st is current online, 2nd is uptime in seconds, others 2 are reserved
$online = $data[1]; // see above
$uptime = $data[2]; //see above
//print( "online: $online, uptime: $uptime seconds" ); // debug ;)
$img = imagecreate( 200, 50 ); // create 200x50px image
$bg = imagecolorallocate($img, 255, 255, 255); // fill background with RGB(255,255,255) (white)
$black = imagecolorallocate($img, 0, 0, 0 ); // allocate RGB(0,0,0) (black) for strings
imagestring($img, 5, 0, 0, "Online: $online", $black ); // Write online count onto image
imagestring($img, 5, 0, 20, "Uptime: $uptime", $black ); // Write uptime onto image
header('Content-type: image/png'); // Set Content-type http headers, so browser knows it receives an image
imagepng( $img ); // Output PNG image
imagedestroy( $img ); // Deallocate image
}
else // Abort on failed connection
die( "connect\n" );
?>
--- End code ---
raynor009:
This is great! Thank you all of you! 8) .I also made a quick aplication but it isnt very advanced.Only says if its on or not.You can try it out bellow is link ;)
DOWNLOAD ME
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version