php: how to communicate with quake2 server?

Forum for anything hard- or software related.

Moderator: Moderators

Post Reply
spectre
joined the game
Posts: 26
Joined: Tue Jul 29, 2003 4:32 am
Location: fi

php: how to communicate with quake2 server?

Post by spectre »

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.


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);



}

?>

Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

Diddnt the last q2 update (3.21?) block msges like that?



Oh w8 ur using rcon :) nevermind
There's a chopper coming in 3 days and there's a katana on top of the cafe and that's all you need to know
Image
Da^JuaN
was picked off
Posts: 1163
Joined: Sun Jul 27, 2003 1:30 pm
Location: nl
Contact:

Post by Da^JuaN »

where can you use it for especially?
Image
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

for loadsa things



like set a server with eaql settings and map changes :)



quite easy to do
There's a chopper coming in 3 days and there's a katana on top of the cafe and that's all you need to know
Image
spectre
joined the game
Posts: 26
Joined: Tue Jul 29, 2003 4:32 am
Location: fi

Post by spectre »

yeah, just add fputs-lines for every rcon command you want to issue, and so on. you don't NEED to check the reply btw. if you just wanna execute rcon commands, skip the postprocessing.



and simple remote console for server would be:


Code: Select all


<html>

<body>

<?php

//set server's rcon password

$rcon_password = $_POST['rcon'];



//command to send to server

$yourcommand = $_POST['command'];



//server address

$serveraddr = $_POST['server'];



//open connection

$conn = fsockopen($serveraddr, 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."<br>\n";

   }

}

print "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";

?>

<input type="text" name="server" size="20"> : server address<br>

<input type="text" name="rcon" size="20"> : rcon password<br>

<input type="text" name="command" size="20"> : command<br>

<input type="submit">

</form>

</body>

</html>

Da^JuaN
was picked off
Posts: 1163
Joined: Sun Jul 27, 2003 1:30 pm
Location: nl
Contact:

Post by Da^JuaN »

me php n00b dont get this at all, maybe if i understand it sometime.. i will look at it ;)
Image
Rallu
hit the ground hard, real hard
Posts: 93
Joined: Thu Jul 31, 2003 11:36 pm
Location: fi
Contact:

Post by Rallu »

spectre, this looks intresting... I have used a bit these php -> q2 things, but I haven't put enough effort to resolve those things what you need to send to q2 server...





where did you hack that '\xff\xff\xff\xff'? from q2 source?
kaaos
blew itself up
Posts: 361
Joined: Sat Aug 09, 2003 11:32 am
Location: fi

Post by kaaos »

i copypasted everything from that finished script but for some reason it doesn't work, it just prints:



Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/kaaos/public_html/q2server.php on line 14



Warning: fsockopen(): unable to connect to :27910 in /home/kaaos/public_html/q2server.php on line 14




and the input boxes below it.



:scratch:
THEIR WHITE FLAGS ARE NO MATCH FOR OUR MACHINEGUNS
spectre
joined the game
Posts: 26
Joined: Tue Jul 29, 2003 4:32 am
Location: fi

Post by spectre »

Rallu wrote:where did you hack that '\xff\xff\xff\xff'? from q2 source?


nope, just captured the rcon packets from homenetwork, simple logic helped me a bit too ;)



kaaos:

seems like your php can't handle udp connections, what's the version and os the php runs on? shouldn't be os relevant, but anyway.
Post Reply