The run down..
I have a quake 3 server and a website.
I have setup VSP stats so players can see their rank when they visit my site.
What I'm trying to do is set it up so I can run a .php file that sends the top 5 players of the vsp stats to the game console.
I have a script and when I direct my browser to the location it reads out the info on the browser. So everything is connected to the database where vsp is running, but the info never reaches the console.
Here is the script if someone could check it out and give me some feed back.
Code: Select all
<?php
/*-------------------------------------------------------------------------*/
// Set up the variables
/*-------------------------------------------------------------------------*/
// ----------------------------------------
// Set number of players to list
// ----------------------------------------
$limit = "5";
// ----------------------------------------
// Variables to connect to game server
// ----------------------------------------
$rconpassword = "*****";
$port = "27960"; // default quake port
// ----------------------------------------
// MYSQL variables:
// ----------------------------------------
$db_host = "localhost"; //Address of database server (localhost or IP)
$db_db = "****"; //Database to use
$db_user = "****"; //Username of database (read rights)
$db_pwd = "****"; //Password
$table_prefix = "vsp_"; //Table prefix you use in vsp
/*-------------------------------------------------------------------------*/
// Connect to database and tables
/*-------------------------------------------------------------------------*/
mysql_connect($db_host,$db_user,$db_pwd);
// ----------------------------------------
// Select which database to use
// ----------------------------------------
mysql_select_db($db_db);
// ----------------------------------------
// Connect or die if fails
// ----------------------------------------
$db_link = mysql_connect($db_host, $db_user, $db_pwd)
or die("Connection with ".$db_host." failed");
// ----------------------------------------
// mysql query
// ----------------------------------------
$table = $table_prefix."playerprofile";
$query = "SELECT playerID, playerName, MAX(skill) AS max_skill FROM $table GROUP by skill ORDER BY skill DESC LIMIT $limit";
/*-------------------------------------------------------------------------*/
// Query database and conect to game server.
// If query failes -> no records stop else fetch rows and send msg.
/*-------------------------------------------------------------------------*/
if(!($result = mysql_query($query, $db_link))) {
$error_msg .= "No records found with query ".$query;
} else {
$msg = " ";
// ----------------------------------------
// fetch mysql result into an array
// ----------------------------------------
$rank = "1";
while ($result_array = mysql_fetch_array($result)) {
$playerID = $result_array['playerID'];
$playerName = $result_array['playerName'];
$playerSkill = $result_array['max_skill'];
$msg = $msg."^5Current Player ranked number ".$rank." is ^7".$playerID." Skill: ".$playerSkill."\n"; // Change text to your liking
$rank++;
}
// ----------------------------------------
//for debug, run file on webserver
// ----------------------------------------
print($msg."<br>");
// ----------------------------------------
// Script to send the message to the CoD console
// ----------------------------------------
$start = "\xff\xff\xff\xffrcon " . $rconpassword . " ";
// ----------------------------------------
// Open socket
// ----------------------------------------
$fp = fsockopen("udp://8.2.122.62", $port, $errno, $errstr, 10);
// ----------------------------------------
// Error checking
// ----------------------------------------
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
stream_set_timeout($fp, 2); // Set a low timeout
// echo $msg."<br>";
// Send commands
fputs($fp, $start . "say " . $msg . "\n");
fclose($fp);
} //end if
}
exit;
?>
Ps. I didn't write this script.
Thanks.
