Exemplo n.º 1
0
    // get ladder team id for selected name
    $result = mysql_query("SELECT id FROM ".$teamstable." WHERE name = '".mysql_real_escape_string($loseTeamName)."'");
		if (mysql_num_rows($result) != 1) {
       $loseTeamId = 0;
    } else {
      $row = mysql_fetch_array($result);
      $loseTeamId = $row[0];
    }
    
    // update current ladder game
    $sql = "UPDATE $gamestable SET winnerteam='$winTeamId', loserteam='$loseTeamId', edited=1 WHERE game_id = $game_id";
    $result = mysql_query($sql);
		
    $logRep->logInfo('sql='.$sql.' affected='.mysql_affected_rows());
    
    UpdateLadderGamePoints($game_id, $logRep);
    
    // Insert teams
    if ($winTeamId > 0 || $loseTeamId > 0) {
      $sql = "SELECT sm.*, sp1.id AS patchIdHome, sp2.id AS patchIdAway, wg.winner, wg.winner2, wg.sixGameId ".
        "FROM weblm_games wg ".
        "LEFT JOIN six_matches sm ON sm.id=wg.sixGameId ".
        "LEFT JOIN six_patches sp1 ON sp1.hash=sm.hashHome ".
        "LEFT JOIN six_patches sp2 ON sp2.hash=sm.hashAway ".
        "WHERE wg.game_id=".$game_id;
      $row = mysql_fetch_array(mysql_query($sql));
      
      $logRep->logInfo('sql='.$sql.' affected='.mysql_affected_rows());
      
      $scoreHome = $row['score_home'];
      $scoreAway = $row['score_away'];
Exemplo n.º 2
0
function InsertTeamAndUpdate($patchId, $sixTeamId, $ladderTeamId, $logRep, $season, $cookie_name)
{
    $exists = false;
    $sql = "SELECT * FROM six_teams WHERE patchId=" . $patchId . " AND sixTeamId=" . $sixTeamId;
    $res = mysql_query($sql);
    $logRep->logInfo("InsertTeamAndUpdate: sql=" . $sql);
    while ($row = mysql_fetch_array($res)) {
        $exists = true;
        $existingLadderTeamId = $row['ladderTeamId'];
        if ($existingLadderTeamId != $ladderTeamId) {
            $logRep->logInfo('InsertTeamAndUpdate: ERROR: existingLadderTeamId=' . $existingLadderTeamId . ' ladderTeamId=' . $ladderTeamId);
        } else {
            $logRep->logInfo('InsertTeamAndUpdate: Team already defined, existingLadderTeamId=' . $existingLadderTeamId);
        }
    }
    $logRep->logInfo('InsertTeamAndUpdate: sql=' . $sql . ' exists=' . $exists);
    if (!$exists) {
        $sql = "SELECT player_id FROM weblm_players WHERE name='{$cookie_name}'";
        $resPlayer = mysql_query($sql);
        $rowPlayer = mysql_fetch_array($resPlayer);
        $playerId = $rowPlayer[0];
        $sql = "INSERT INTO six_teams (patchId, sixTeamId, ladderTeamId, playerId) " . "VALUES ('" . $patchId . "','" . $sixTeamId . "','" . $ladderTeamId . "','" . $playerId . "')";
        mysql_query($sql);
        $logRep->logInfo('InsertTeamAndUpdate: sql=' . $sql . ' affected=' . mysql_affected_rows());
    }
    // Update other games
    $sql = "SELECT wg.game_id, wg.winner, wg.winner2, wg.winnerteam, wg.loserteam, wg.sixGameId, sm.* FROM weblm_games wg " . "LEFT JOIN six_matches sm ON wg.sixGameId=sm.id " . "LEFT JOIN six_patches sp1 ON sm.hashHome=sp1.hash " . "WHERE wg.sixGameId IS NOT NULL " . "AND wg.season=" . $season . " " . "AND sm.reported=1 " . "AND sp1.id=" . $patchId . " " . "AND (wg.winnerteam=0 OR wg.loserteam=0) " . "AND (sm.team_id_home=" . $sixTeamId . " OR sm.team_id_away=" . $sixTeamId . ") ";
    $res = mysql_query($sql);
    $logRep->logInfo('InsertTeamAndUpdate: Other Games: sql=' . $sql . ' affected=' . mysql_affected_rows());
    while ($row = mysql_fetch_array($res)) {
        $game_id = $row['game_id'];
        $winnerteam = $row['winnerteam'];
        $loserteam = $row['loserteam'];
        $scoreHome = $row['score_home'];
        $scoreAway = $row['score_away'];
        $setWinner = false;
        $setLoser = false;
        if ($scoreHome < $scoreAway) {
            $sixWinTeam = $row['team_id_away'];
            $sixLoseTeam = $row['team_id_home'];
        } elseif ($scoreHome > $scoreAway) {
            $sixWinTeam = $row['team_id_home'];
            $sixLoseTeam = $row['team_id_away'];
        } else {
            // draw could have been flipped
            $winner = $row['winner'];
            $winner2 = $row['winner2'];
            $sixGameId = $row['sixGameId'];
            $winnerIsHome = false;
            $sql = "SELECT wp.name FROM weblm_players wp " . "LEFT JOIN six_profiles sp ON sp.user_id=wp.player_id " . "LEFT JOIN six_matches_played smp ON smp.profile_id=sp.id " . "WHERE smp.match_id=" . $sixGameId . " AND smp.home=1";
            $drawRes = mysql_query($sql);
            $logRep->logInfo('InsertTeamAndUpdate: DrawFlip: sql=' . $sql . ' affected=' . mysql_affected_rows());
            while ($drawRow = mysql_fetch_array($drawRes)) {
                $homeName = $drawRow['name'];
                if ($homeName == $winner || $homeName == $winner2) {
                    $winnerIsHome = true;
                }
            }
            $logRep->logInfo('InsertTeamAndUpdate: DrawFlip: winnerIsHome=' . $winnerIsHome);
            if ($winnerIsHome) {
                $sixWinTeam = $row['team_id_home'];
                $sixLoseTeam = $row['team_id_away'];
            } else {
                $sixWinTeam = $row['team_id_away'];
                $sixLoseTeam = $row['team_id_home'];
            }
        }
        if ($sixWinTeam == $sixTeamId && $winnerteam == 0) {
            $sql = "UPDATE weblm_games SET winnerteam=" . $ladderTeamId . " WHERE game_id=" . $game_id;
            mysql_query($sql);
            $logRep->logInfo('InsertTeamAndUpdate: Other Games: sql=' . $sql . ' affected=' . mysql_affected_rows());
            $setWinner = true;
        }
        if ($sixLoseTeam == $sixTeamId && $loserteam == 0) {
            $sql = "UPDATE weblm_games SET loserteam=" . $ladderTeamId . " WHERE game_id=" . $game_id;
            mysql_query($sql);
            $logRep->logInfo('InsertTeamAndUpdate: Other Games: sql=' . $sql . ' affected=' . mysql_affected_rows());
            $setLoser = true;
        }
        $logRep->logInfo('InsertTeamAndUpdate: Other Games: winnerteam=' . $winnerteam . ' loserteam=' . $loserteam . ' setWinner=' . $setWinner . ' setLoser=' . $setLoser);
        if ($setWinner && $loserteam > 0 || $setLoser && $winnerteam > 0 || $setWinner && $setLoser) {
            UpdateLadderGamePoints($game_id, $logRep);
            $sql = "UPDATE weblm_games SET edited=1 WHERE game_id=" . $game_id;
            mysql_query($sql);
            $logRep->logInfo('InsertTeamAndUpdate: Other Games: sql=' . $sql . ' affected=' . mysql_affected_rows());
        }
    }
}