Originally posted on www.bf2cc.com<?php
/*
LogHash.php
Created by Mugzy
email:
Mugzy@mugzy.org --Usage--
This script will connect to your BF2 server and record the hashes to a MySQL DB.
--Setup--
Create a new MySQL database and run the following SQL to create the required table:
CREATE TABLE `bf2hash` (
`iname` varchar(255) NOT NULL default '',
`hash` varchar(255) NOT NULL default '',
`date` datetime default NULL
) TYPE=MyISAM;
--Configuration--
Enter your servers ip, port, and rcon password.
Enter the database server, username, password, and database name.
*/
session_start();
putenv("TZ=US/Eastern");
buildlist("ip","rconport","rconpassword");
function buildlist($server, $port, $password)
{
ob_start();
$dbserver = "ip";
$dbuser = "user";
$dbPass = "pass";
$dbName = "dbname";
$dbTable = "bf2hash";
$link = mysql_connect ($dbserver, $dbuser, $dbPass)
or die ("Could not connect");
$results = mysql_select_db($dbName,$link)
or die('failed because '.mysql_error());
$timeout = 5;
if(!$handle = @fsockopen($server, $port, $errno, $errstr, $timeout))
{
echo "Could not connect to server: " . $server . "<br>";
ob_end_flush();
flush();
}
else
{
socket_set_timeout($handle, $timeout);
@fread($handle,128);
$keyzeile = @fread($handle,33);
$key = str_replace("### Digest seed: ", "", $keyzeile);
$pass_send = "login " . digest($key, $password) . "\n";
@fwrite($handle, $pass_send);
@fgets($handle);
@fgets($handle);
$antwort = @fgets($handle);
if(substr_count($antwort, "failed"))
{
echo "Login failed<br>";
ob_end_flush();
flush();
return;
}
$cmd = "exec admin.listPlayers\n";
@fwrite($handle, $cmd);
$eofplist = false;
echo "Building Player List...<br>";
flush();
while( !$eofplist )
{
$result = @fgets($handle);
if(trim($result) == "")
{
return;
$eofplist = true;
}
else
{
$result = str_replace(" ", " ", $result);
$columns = explode(" ", trim($result));
if(count($columns)==10)$columns[3]=$columns[3]." ".$columns[4]; // add this line
$result2 = @fgets($handle);
$columns2 = explode(" ", trim($result2));
$ipcolumn = explode(":", $columns[7]);
{
$sql="select count(hash) as cnt, hash from $dbTable where iname = '$columns[3]' group by iname";
$result=MySQL_query($sql,$link) or die('failed because '.mysql_error());
$myrow=MySQL_fetch_array($result);
if($myrow['cnt'] > 0)
{
echo "$columns[3] is already in database<br>";
}
else
{
echo "Adding " . $columns[3] . " " . $columns2[2] . " to database<br>";
mysql_select_db($dbName,$link);
$sql="insert into $dbTable (iname, hash, date) VALUES('$columns[3]', '$columns2[2]', SYSDATE())";
$result=MySQL_query($sql,$link) or die('failed because '.mysql_error());
flush();
}
}
}
}
}
}
function digest($seed, $pw)
{
$m = md5($seed . $pw);
return $m;
}
?>