1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Correction of 'None' fields, removing PID=0 users from stats.

Discussion in 'BF2Statistics discussion' started by FiberLetalis, May 3, 2006.

  1. FiberLetalis

    FiberLetalis New Member

    I've noticed that sometimes server generates POST requests to web-server with python's 'None' instead of 0 (for example, ...\pID_0\None\...). I'm not shure when this happens and I don't have a direct access to our game server which has such problem to check what's going wrong, so I've just added a small check to ASP/bf2statistics.php to avoid this problem:
    Code:
    diff -Naur old/bf2statistics.php new/bf2statistics.php
    --- old/bf2statistics.php	2006-02-19 01:20:16.000000000 +0600
    +++ new/bf2statistics.php	2006-05-03 16:33:44.863500000 +0700
    @@ -62,6 +62,8 @@
    // Get URL POST data
    $rawdata = file_get_contents('php://input');
    
    +$rawdata = str_replace('\\None\\', '\\0\\', $rawdata);
    +
    // Seperate data
    $gooddata = explode('\\', $rawdata);
    
    
    Remember my bug report about mixing online and offline users on server? Well, it seems to be true. I've disabled autogeneration of PIDs for offline users and now everything works fine. But it's a bother to have a zero-PID user in statistics which accumulates all points earned by offline users. To hide it i've modified some of the .aspx files in ASP directory (this also hides it from web-statistics):
    Code:
    diff -Naur old/getleaderboard.aspx new/getleaderboard.aspx
    --- old/getleaderboard.aspx	2006-02-14 12:48:52.000000000 +0600
    +++ new/getleaderboard.aspx	2006-05-03 15:36:53.582250000 +0700
    @@ -57,7 +57,7 @@
    {
    if ($id == 'overall')
    {
    -			$query = "SELECT COUNT(id) FROM player WHERE score > 0";
    +			$query = "SELECT COUNT(id) FROM player WHERE score > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    print "D\t$row[0]\t" . time() . "\n";
    @@ -67,7 +67,7 @@
    
    if (!$pid)
    {
    -				$query = "SELECT id, name, rank, country, time, score FROM player WHERE score > 0 ORDER BY score DESC LIMIT {$min}, {$max}";
    +				$query = "SELECT id, name, rank, country, time, score FROM player WHERE score > 0 and id  0 ORDER BY score DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    @@ -97,7 +97,7 @@
    }
    elseif ($id == 'commander')
    {
    -			$query = "SELECT COUNT(id) FROM player WHERE cmdscore > 0";
    +			$query = "SELECT COUNT(id) FROM player WHERE cmdscore > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    @@ -108,7 +108,7 @@
    
    if (!$pid)
    {
    -				$query = "SELECT id, name, rank, country, cmdtime, cmdscore FROM player WHERE cmdscore > 0 ORDER BY cmdscore DESC LIMIT {$min}, {$max}";
    +				$query = "SELECT id, name, rank, country, cmdtime, cmdscore FROM player WHERE cmdscore > 0 and id  0 ORDER BY cmdscore DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    @@ -138,7 +138,7 @@
    }
    elseif ($id ==  'team')
    {
    -			$query = "SELECT COUNT(id) FROM player WHERE teamscore > 0";
    +			$query = "SELECT COUNT(id) FROM player WHERE teamscore > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    @@ -149,7 +149,7 @@
    
    if (!$pid)
    {
    -				$query = "SELECT id, name, rank, country, time, teamscore FROM player WHERE teamscore > 0 ORDER BY teamscore DESC LIMIT {$min}, {$max}";
    +				$query = "SELECT id, name, rank, country, time, teamscore FROM player WHERE teamscore > 0 and id  0 ORDER BY teamscore DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    @@ -179,7 +179,7 @@
    }
    elseif ($id == 'combat')
    {
    -			$query = "SELECT COUNT(id) FROM player WHERE kills > 0";
    +			$query = "SELECT COUNT(id) FROM player WHERE kills > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    @@ -190,7 +190,7 @@
    
    if (!$pid)
    {
    -				$query = "SELECT id, name, rank, country, time, kills, skillscore FROM player WHERE kills > 0 ORDER BY skillscore DESC LIMIT {$min}, {$max}";
    +				$query = "SELECT id, name, rank, country, time, kills, skillscore FROM player WHERE kills > 0 and id  0 ORDER BY skillscore DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    @@ -224,7 +224,7 @@
    # Need weekly score calculations!
    elseif ($type == 'risingstar')
    {
    -		$query = "SELECT COUNT(id) FROM player WHERE score > 0";
    +		$query = "SELECT COUNT(id) FROM player WHERE score > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    @@ -235,7 +235,7 @@
    
    if (!$pid)
    {
    -			$query = "SELECT id, name, rank, country, time, score, joined FROM player WHERE score > 0 ORDER BY score DESC LIMIT {$min}, {$max}";
    +			$query = "SELECT id, name, rank, country, time, score, joined FROM player WHERE score > 0 and id  0 ORDER BY score DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    @@ -269,7 +269,7 @@
    }
    elseif ($type == 'kit')
    {
    -		$query = "SELECT COUNT(id) FROM kits WHERE kills{$id} > 0";
    +		$query = "SELECT COUNT(id) FROM kits WHERE kills{$id} > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    @@ -280,7 +280,7 @@
    
    if (!$pid)
    {
    -			$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN kits WHERE kills{$id} > 0 ORDER BY kills{$id} DESC LIMIT {$min}, {$max}";
    +			$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN kits WHERE kills{$id} > 0 and plid  0 ORDER BY kills{$id} DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    @@ -312,7 +312,7 @@
    }
    elseif ($type == 'vehicle')
    {
    -		$query = "SELECT COUNT(id) FROM vehicles WHERE kills{$id} > 0";
    +		$query = "SELECT COUNT(id) FROM vehicles WHERE kills{$id} > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    @@ -323,7 +323,7 @@
    
    if (!$pid)
    {
    -			$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN vehicles WHERE kills{$id} > 0 ORDER BY kills{$id} DESC LIMIT {$min}, {$max}";
    +			$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN vehicles WHERE kills{$id} > 0 and plid  0 ORDER BY kills{$id} DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    @@ -355,7 +355,7 @@
    }
    elseif ($type == 'weapon')
    {
    -		$query = "SELECT COUNT(id) FROM weapons WHERE kills{$id} > 0";
    +		$query = "SELECT COUNT(id) FROM weapons WHERE kills{$id} > 0 and id  0";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    
    @@ -367,7 +367,7 @@
    
    if (!$pid)
    {
    -			$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time, hit{$id} AS hit, fired{$id} AS fired FROM player NATURAL JOIN weapons WHERE kills{$id} > 0 ORDER BY kills{$id} DESC LIMIT {$min}, {$max}";
    +			$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time, hit{$id} AS hit, fired{$id} AS fired FROM player NATURAL JOIN weapons WHERE kills{$id} > 0 and plid  0 ORDER BY kills{$id} DESC LIMIT {$min}, {$max}";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
    diff -Naur old/getplayerinfo.aspx new/getplayerinfo.aspx
    --- old/getplayerinfo.aspx	2006-02-14 12:40:04.000000000 +0600
    +++ new/getplayerinfo.aspx	2006-05-03 15:36:55.707250000 +0700
    @@ -117,7 +117,7 @@
    if ($count) {$acc /= $count;}
    
    // Favorite opponent
    -		$query = "SELECT attacker, count FROM kills WHERE victim = {$pid} GROUP BY count DESC LIMIT 1";
    +		$query = "SELECT attacker, count FROM kills WHERE victim = {$pid} and attacker  0 GROUP BY count DESC LIMIT 1";
    $result = mysql_query($query) or die(mysql_error());
    $row2 = mysql_fetch_array($result);
    $favoi = $row2['attacker'];
    @@ -133,7 +133,7 @@
    $favor = $row2['rank'];
    
    // Favorite victim
    -		$query = "SELECT victim, count FROM kills WHERE attacker = {$pid} GROUP BY count DESC LIMIT 1";
    +		$query = "SELECT victim, count FROM kills WHERE attacker = {$pid} and victim  0 GROUP BY count DESC LIMIT 1";
    $result = mysql_query($query) or die(mysql_error());
    $row2 = mysql_fetch_array($result);
    $favvi = $row2['victim'];
    diff -Naur old/searchforplayers.aspx new/searchforplayers.aspx
    --- old/searchforplayers.aspx	2006-02-14 12:22:32.000000000 +0600
    +++ new/searchforplayers.aspx	2006-05-03 15:36:56.191625000 +0700
    @@ -38,7 +38,7 @@
    $connection = @mysql_connect($dbhost, $dbuser, $dbpass);
    @mysql_select_db($dbname);
    
    -	$query = "SELECT id, name, score FROM player WHERE name LIKE '%{$nick}%'";
    +	$query = "SELECT id, name, score FROM player WHERE name LIKE '%{$nick}%' and id  0";
    $result = mysql_query($query) or die(mysql_error());
    
    $num = 1;
    
    
     
  2. FiberLetalis

    FiberLetalis New Member

    And here's a full patch. (patch -p1 < bf2statistics.patch)
     
  3. FiberLetalis

    FiberLetalis New Member

  4. harrier

    harrier New Member

    This is excellent. I got around this in the past by 'sed'ing the log files replacing 'none' with '12345678' and re-importing the logfiles into a clean database. It's great to see a patch that handles it properly.
    Cheers,
    harrier.