php: how to communicate with quake2 server?
Posted: Fri Apr 23, 2004 3:46 am
yeah, simple example, hope ppl can use this as frame:
(there was a bug in php that did prevent reading from udp stream, tho it was fixed in 4.3.1 (or smthng), so you'll need recent version of php for this.
(there was a bug in php that did prevent reading from udp stream, tho it was fixed in 4.3.1 (or smthng), so you'll need recent version of php for this.
Code: Select all
<?php
//set servers rcon password
$rcon_password = "SecreT"
//command to send to server
$yourcommand = "say message from outer world: it's SUMMER!";
//open connection
$conn = fsockopen( "udp://10.0.0.1", 27910, $error, $errdescription, 10 );
//check if connection was made
if ($conn) {
//send data to server
fputs( $conn, "\xff\xff\xff\xff".$yourcommand);
//parse output
$output = str_replace("ÿ", "", (fread( $conn, 1024 )));
//aaand make array out of it
$reply = split ("\x0a", $output);
//then let's see what we wanna do with those rows that server sent back
foreach ($reply as $r) {
//as i am simple man, i don't wanna do anything but print the output
print $r."\n";
}
}
//something ain't working
else {
//i've seen it all
die("ERROR with connection: ".$errdescription);
}
?>