garrensilverwing
New Member
- Messages
- 148
- Reaction score
- 0
- Points
- 0
This guy and I are creating a ranking system for this game we play. The game automatically generates game reports and posts them on a webserver: server.war2.ru/reports. The guy wrote a short php function that parses the game reports and then separates important information out, including winner's name, loser's name, etc... Now in some cases the function will parse a game and give us either a blank winner, or a blank loser. We have no idea what is causing this and was hoping you could help us out a little. Here is a link to a game report that creates a ghost player: http://server.war2.ru/reports/gr_20091201223149_025853, in this case the player should be vanwilder but it is coming as blank. If anyone has an idea of how to fix this I will give them rep and whatever else I can! Here is the function:
Code:
<?php
function insertLadderGame($GameID, $map, $Winner, $Loser)
{
$wresult = mysql_query("select * from standings where Player = '$Winner'");
$lresult = mysql_query("select * from standings where Player = '$Loser'");
if (mysql_num_rows($wresult) == 0 || mysql_num_rows($lresult) == 0)
{
if (mysql_num_rows($wresult) == 0)
{
$result = mysql_query("SELECT * FROM standings order by Rank desc limit 1") or die(mysql_error());
while($row = mysql_fetch_array($result)){$highestRank = $row['Rank'];}
$WOldRank = $WNewRank = $highestRank + 1;
mysql_query("INSERT INTO standings (Player,Rank,Wins,Losses,HighRank,Streak) VALUES('$Winner','$WNewRank','1','0','$WNewRank','1');") or die(mysql_error());
}
else
{
$result = mysql_query("SELECT * FROM standings where Player = '$Winner'") or die(mysql_error());
while($row = mysql_fetch_array($result))
{$WOldRank = $WNewRank = $row['Rank']; $Wins = $row['Wins']; $wStreak = $row['Streak'];}
if ($wStreak > 0) $wStreak++;
else $wStreak = 1;
mysql_query("UPDate standings SET Wins='$Wins+1', Streak='$wStreak' where Player = '$Winner'") or die(mysql_error());
}
if (mysql_num_rows($lresult) == 0)
{
$result = mysql_query("SELECT * FROM standings order by Rank desc limit 1") or die(mysql_error());
while($row = mysql_fetch_array($result))
{$highestRank = $row['Rank'];}
$LOldRank = $LNewRank = $highestRank + 1;
mysql_query("INSERT INTO standings (Player,Rank,Wins,Losses,HighRank,Streak)
VALUES('$Loser','$LNewRank','0','1','$LNewRank','-1');") or die(mysql_error());
}
else
{
$result = mysql_query("SELECT * FROM standings where Player = '$Winner'") or die(mysql_error());
while($row = mysql_fetch_array($result))
{$LOldRank = $LNewRank = $row['Rank'];$Losses = $row['Losses'];$lStreak = $row['Streak'];}
if ($lStreak < 0) $lStreak--;
else $lStreak = -1;
mysql_query("UPDate standings SET Losses='$Losses+1', Streak='$lStreak' where Player = '$Loser'") or die(mysql_error());
}
$DateT = substr($GameID, 4, 14);
mysql_query("INSERT INTO checkedgames (GameID,Winner,Loser,WOldRank,WNewRank,LOldRank,LNewRank,Map,DateT)
VALUES('$GameID', '$Winner','$Loser','$WOldRank','$WNewRank','$LOldRank','$LNewRank','$map','$DateT' );") or die(mysql_error());
return 0;
}
// If neither player is new
$result = mysql_query("SELECT * FROM standings where Player='$Winner'") or die(mysql_error());
while($row = mysql_fetch_array($result))
{$highrank = $row['HighRank'];$WOldRank = $row['rank'];$Wins = $row['Wins'];$WStreak = $row['Streak'];$WSeries = $row['series'];}
$Wins++;
if ($wstreak > 0) $wstreak++;
else $wstreak = 1;
$result = mysql_query("SELECT * FROM standings where Player='$Loser'") or die(mysql_error());
while($row = mysql_fetch_array($result))
{$LOldrank = $row['Rank'];$Losses = $row['Losses'];$LStreak = $row['Streak'];}
$Losses++;
if ($LStreak < 0) $LStreak--;
else $LStreak = -1;
if ($LOldRank + $WOldRank == 3) $WSeries++;
if ($WSeries > 0)
{
mysql_query("UPDATE standings SET series='$WSeries' where Player = '$Winner'") or die(mysql_error());
if ($WSeries == 3)
{$counter = 3; while($counter > 2 && $counter < 11) {$newrank = $counter-1; mysql_query("UPDATE standings SET rank ='$newrank' where Rank = '$counter'"); $counter = $counter+1;}
mysql_query("UPDATE standings SET series='0', rank='1' where Player = '$Winner'") or die(mysql_error());
mysql_query("UPDATE standings SET series='0', rank='10' where Player = '$Loser'") or die(mysql_error());
}
}
if ($WOldRank > $LOldRank && $WSeries == 0)
{
$WNewRank = ($WOldRank + $LOldRank)/2;
$WNewRank = intval($WNewRank);
$n = $WOldRank-1;
if ($WNewRank == 2)
{
mysql_query("UPDATE standings SET series='0', rank='2' where player = '$Loser'") or die(mysql_error());
$result = mysql_query("SELECT * FROM standings where rank = '1'") or die(mysql_error());
while($row = mysql_fetch_array($result)) $TopPlayer = $row['Player'];
mysql_query("UPDATE standings SET series='0' where Player = '$TopPlayer'") or die(mysql_error());
}
while ($n >= $WNewRank)
{
$result = mysql_query("SELECT * FROM standings where rank = '$n'") or die(mysql_error());
while($row = mysql_fetch_array($result)) $passedPlayer = $row['player'];
$m = $n+1;
mysql_query("UPDATE standings SET rank='$m' where player = '$passedPlayer'") or die(mysql_error());
$n--;
}
}
else $wnewrank = $woldrank;
if ($wnewrank < $highrank) $highrank = $wnewrank;
if ($wnewrank == $loldrank) $lnewrank = $loldrank + 1;
else $lnewrank = $loldrank;
mysql_query("UPDATE standings SET rank='$wnewrank', wins='$wins', streak='$wstreak', highrank='$highrank' where player = '$winner'");
mysql_query("UPDATE standings SET losses='$losses', streak='$lstreak' where player = '$loser'");
mysql_query("INSERT INTO checkedgames (gameID,loser,winner,woldrank,wnewrank,loldrank,lnewrank,map,datet)
VALUES('$gameID', '$loser','$winner','$woldrank','$wnewrank','$loldrank','$lnewrank','$map','now()' );")
or die(mysql_error());
return 0;
}
function insertGameID($GameID)
{
mysql_query("INSERT INTO checkedgames (GameID,Loser,Winner,WOldRank,WNewRank,LOldRank,LNewRank,Map)
VALUES('$GameID', 'none','none','none','none','none','none','none');") or die(mysql_error());
}
function parseGameInfo($GameID)
{
set_time_limit(8000);
$war2gameinfo = file('http://server.war2.ru/reports/'.$GameID);
$war2gameinfotxt = implode('',$war2gameinfo);
if (preg_match('/mapauth=\"Self-Made\"/', $war2gameinfotxt) == 0 && preg_match('/DRAW/', $war2gameinfotxt) == 0
&& preg_match('/DISCONNECT/', $war2gameinfotxt) == 0)
{
if (preg_match('/ LOSS/', $war2gameinfotxt) == 0)
{
return 0;
}
if (preg_match('/ WIN/', $war2gameinfotxt) == 0)
{
return 0;
}
$startHere = strstr($war2gameinfotxt,'joins=');
$line = explode("\n", $startHere);
$joinCount = substr($startHere, 6, 1);
$englishCount = preg_match_all('/ and played for/', $startHere, $matches);
if ($englishCount < $joinCount)
{
return 0;
}
$watcherCount = preg_match_all('/ 1 for Units/', $startHere, $matches);
$PlayerCount = $joinCount - $watcherCount;
if ($PlayerCount == 2)
{
preg_match('/mapfile=\".+\.pud\"/', $war2gameinfotxt, $mapmatch);
$map = substr($mapmatch[0], 9, -5);
$throwAway = preg_match_all('/\d+ for Units/', $startHere, $matches);
/* While loop: creates a variable Player1 first time through, Player2 second time through.
Sets Player1[0] to the first Player's name, [1] to the result, [2] to his units.
Sets Player2[0] to the second Player's name, etc.
If Player's units are more than 1, and he lost or disconnected, his name is set to $Loser.
If Player's units are more than 1, and he won, his name is set to $Winner.
*/
$n = 0;
while ($n < $PlayerCount)
{${'Player'.($n+1)} = preg_split("/\s+/", $line[3+$n]);${'Player'.($n+1)}[2] = $matches[0][$n]; if (${'Player'.($n+1)}[2] > 1 && ${'Player'.($n+1)}[1] == 'LOSS') $Loser = ${'Player'.($n+1)}[0]; if (${'Player'.($n+1)}[2] > 1 && ${'Player'.($n+1)}[1] == 'WIN')
$Winner = ${'Player'.($n+1)}[0];
$n++;
}
}
else
{
return 0;
}
}
else
{
return 0;
}
if($Winner == "" OR $Loser == ""){
echo "<li style=\"color: red\">$GameID</li>";
}
else {
insertLadderGame($GameID, $map, $Winner, $Loser);
}
return 0;
}
?>