Just wanted to say thanks in advanced. I'm a complete noob when it comes to php. I run a few game servers and I'm trying to put together a script that sends console messages. I have the messages in an array so I can add new ones easily, but it has a problem with line 15. Line 15 is send_msg($msg);
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
[SOLVED] Need Help with short script!
in PHP Coding Help
Posted
Hi All,
Just wanted to say thanks in advanced. I'm a complete noob when it comes to php. I run a few game servers and I'm trying to put together a script that sends console messages. I have the messages in an array so I can add new ones easily, but it has a problem with line 15. Line 15 is send_msg($msg);
Here is the script:
<?php
// - edit - this is Open Source of course....
/*-------------------------------------------------------------------------*/
// Set up the messages
/*-------------------------------------------------------------------------*/
$msg = array(0 => '"Radio spammers will be killed!"',
1 => '"LG members are admins so shut up!"',
2 => '"Hax accusers will be tarred and beaten!"',
3 => '"Get a demo and shut up!"',
4 => '"Get your stats @ www.LowGravityURT.com"');
foreach ($msg as $key => $value) {
print "$value\n";
}
send_msg($msg);
// ----------------------------------------
// function to connect to game server and
// send the message to the q3a console
// ----------------------------------------
function send_msg($msg){
$rconpassword = "urtlg";
$port = "27960"; // default quake port. Change if needed
$start = "\xff\xff\xff\xffrcon " . $rconpassword . " ";
// ----------------------------------------
// Open socket
// ----------------------------------------
$fp = fsockopen("udp://8.12.16.171", $port, $errno, $errstr, 10);
// ----------------------------------------
// Error checking
// ----------------------------------------
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
stream_set_timeout($fp, 2); // Set a low timeout
// Send commands
fputs($fp, $start . "say " . $msg . "\n");
fclose($fp);
} // end if
// ----------------------------------------
// Change to your liking sleep(seconds)
// ----------------------------------------
sleep(4);
} // end function send_msg
?>