Esempio n. 1
0
        if ($winnerresult - $loserresult == 0) {
            $isDraw = 1;
            $winLoss = 0;
            $sqlDraw = " draws = draws + 1, totaldraws = totaldraws + 1, ";
            $addWinOrDefeat = 0;
        } else {
            $isDraw = 0;
            $winLoss = 1;
            $sqlDraw = "";
            $addWinOrDefeat = 1;
        }
        if ($winnerresult - $loserresult == 0) {
            $isDraw = 1;
        }
        $comment = "";
        $calc = calculateGamePointsReportGame($winnername, $winnername2, $losername, $losername2, $winnerresult, $loserresult, $winnerteam, $loserteam, $ratingOldWinner1, $ratingOldWinner2, $ratingOldLoser1, $ratingOldLoser2, $pointsOldWinner1, $pointsOldWinner2, $pointsOldLoser1, $pointsOldLoser2, $type, $isDraw, $comment, null);
        $ratingdiff = $calc["ratingdiff"];
        $ra2newwinneradd = $calc["addPointsWinner"];
        $ra2newloserremL1 = $calc["removePointsLoser1"];
        $ra2newloserremL2 = $calc["removePointsLoser2"];
        $ra2newwinner = $calc["pointsNewWinner1"];
        $ra2newwinner2 = $calc["pointsNewWinner2"];
        $ra2newloser = $calc["pointsNewLoser1"];
        $ra2newloser2 = $calc["pointsNewLoser2"];
        $message = $calc["message"];
        $msg .= "<p>Game type: <b>{$type}</b> -> " . $ladderType . " Ladder</p>";
        $msg .= "<p{$message}</p>";
    }
}
?>
Esempio n. 2
0
function ReportGame($winnername, $winnername2, $losername, $losername2, $date, $comment, $gameid, $winnerresult, $loserresult, $host, $fairness, $version, $winnerteam, $loserteam, $sixGameId)
{
    require 'variables.php';
    require 'variablesdb.php';
    require_once 'log/KLogger.php';
    $log = new KLogger('/var/www/yoursite/http/log/report', KLogger::INFO);
    $log->logInfo('Reporting ' . $winnername . ' vs. ' . $losername);
    $resultText = "";
    $comment = htmlentities($comment);
    $comment = nl2br($comment);
    if (!empty($winnername2) || !empty($losername2)) {
        // game for team ladder
        $pointsField = "teamPoints";
        $gamesField = "teamGames";
        $winsField = "teamWins";
        $lossesField = "teamLosses";
        $drawsField = "teamDraws";
        $teamLadder = 1;
        $ladderType = "Team";
    } else {
        // single ladder
        $pointsField = getPointsFieldForVersion($version);
        $gamesField = getGamesFieldForVersion($version);
        $winsField = getWinsFieldForVersion($version);
        $lossesField = getLossesFieldForVersion($version);
        $drawsField = "draws";
        $teamLadder = 0;
        $ladderType = "Single";
    }
    $row = getRatingAndPointsForPlayer($winnername, $pointsField);
    $ratingOldWinner1 = $row["rating"];
    $pointsOldWinner1 = $row[$pointsField];
    $row = getRatingAndPointsForPlayer($losername, $pointsField);
    $ratingOldLoser1 = $row["rating"];
    $pointsOldLoser1 = $row[$pointsField];
    $type = "1on1";
    if (!empty($winnername2)) {
        $type = "2on1";
        $row = getRatingAndPointsForPlayer($winnername2, $pointsField);
        $ratingOldWinner2 = $row["rating"];
        $pointsOldWinner2 = $row[$pointsField];
    }
    if (!empty($losername2)) {
        $type = "1on2";
        $row = getRatingAndPointsForPlayer($losername2, $pointsField);
        $ratingOldLoser2 = $row["rating"];
        $pointsOldLoser2 = $row[$pointsField];
    }
    if (!empty($winnername2) && !empty($losername2)) {
        $type = "2on2";
    }
    if ($winnerresult - $loserresult == 0) {
        $isDraw = 1;
        $winLoss = 0;
        $sqlDraw = " " . $drawsField . " = " . $drawsField . " + 1, totaldraws = totaldraws + 1, ";
        $addWinOrDefeat = 0;
    } else {
        $isDraw = 0;
        $winLoss = 1;
        $sqlDraw = "";
        $addWinOrDefeat = 1;
    }
    $calc = calculateGamePointsReportGame($winnername, $winnername2, $losername, $losername2, $winnerresult, $loserresult, $winnerteam, $loserteam, $ratingOldWinner1, $ratingOldWinner2, $ratingOldLoser1, $ratingOldLoser2, $pointsOldWinner1, $pointsOldWinner2, $pointsOldLoser1, $pointsOldLoser2, $type, $isDraw, $comment, $sixGameId);
    $ratingdiff = $calc["ratingdiff"];
    $ra2newwinneradd = $calc["addPointsWinner"];
    $ra2newloserremL1 = $calc["removePointsLoser1"];
    $ra2newloserremL2 = $calc["removePointsLoser2"];
    $ra2newwinner = $calc["pointsNewWinner1"];
    $ra2newwinner2 = $calc["pointsNewWinner2"];
    $ra2newloser = $calc["pointsNewLoser1"];
    $ra2newloser2 = $calc["pointsNewLoser2"];
    $teamBonusWinner = $calc["teamBonusWinner"];
    $message = $calc["message"];
    echo $message;
    // $log->logInfo('ra2newwinneradd: '.$ra2newwinneradd);
    // $log->logInfo('ra2newwinner: '.$ra2newwinner);
    // $log->logInfo('ra2newloser: '.$ra2newloser);
    if (strlen($comment) > 256) {
        $comment = substr($comment, 0, 255);
    }
    $comment = mysql_real_escape_string($comment);
    $dateday = date("d/m/Y");
    $ip = Get_ip();
    $deleted = "no";
    $sql = "UPDATE {$playerstable} " . " SET {$lossesField} = {$lossesField} + {$winLoss},  totallosses = totallosses + {$winLoss}, " . "{$gamesField} = {$gamesField} + 1, " . "totalgames = totalgames + 1, " . $sqlDraw . "streakwins = 0, " . "streaklosses = streaklosses + {$winLoss}, " . "rating = rating - {$ratingdiff}, " . "{$pointsField} = {$ra2newloser} " . "WHERE name='{$losername}'";
    $log->logInfo('sql: ' . $sql);
    $res = mysql_query($sql);
    $result = $res;
    $log->logInfo('result: ' . $result);
    $sql = "UPDATE {$playerstable} " . " SET {$winsField} = {$winsField} + {$winLoss}, totalwins = totalwins + {$winLoss}, {$gamesField} = {$gamesField} + 1, " . "totalgames = totalgames + 1, " . "streakwins = streakwins + {$winLoss}, " . "streaklosses = 0, " . $sqlDraw . "rating = rating + {$ratingdiff}, " . "{$pointsField} = {$ra2newwinner} " . "WHERE name='{$winnername}'";
    $log->logInfo('sql: ' . $sql);
    $res = mysql_query($sql);
    $result = $result + $res;
    $log->logInfo('result: ' . $result);
    if (!empty($losername2)) {
        $sql = "UPDATE {$playerstable} " . " SET {$lossesField} = {$lossesField} + {$winLoss},  totallosses = totallosses + {$winLoss}, " . "{$gamesField} = {$gamesField} + 1, " . "totalgames = totalgames + 1, " . "streakwins = 0, " . "streaklosses = streaklosses + {$winLoss}, " . $sqlDraw . "rating = rating - {$ratingdiff}, " . "{$pointsField} = {$ra2newloser2} " . "WHERE name='{$losername2}'";
        $log->logInfo('sql: ' . $sql);
        $res = mysql_query($sql);
        $result = $result + $res;
        $log->logInfo('result: ' . $result);
        //		echo "<p>".$sql." - <b>$res</b></p>";
    }
    if (!empty($winnername2)) {
        $sql = "UPDATE {$playerstable} " . " SET {$winsField} = {$winsField} + {$winLoss}, totalwins = totalwins + {$winLoss}, {$gamesField} = {$gamesField} + 1, " . "totalgames = totalgames + 1, " . "streakwins = streakwins + {$winLoss}, " . "streaklosses = 0, " . $sqlDraw . "rating = rating + {$ratingdiff}, " . "{$pointsField} = {$ra2newwinner2} " . "WHERE name='{$winnername2}'";
        $log->logInfo('sql: ' . $sql);
        $res = mysql_query($sql);
        $result = $result + $res;
        $log->logInfo('result: ' . $result);
        //		echo "<p>".$sql." - <b>$res</b></p>";
    }
    if (is_null($sixGameId)) {
        $sql = "INSERT INTO {$gamestable} " . "(isDraw, winner, winner2, loser, loser2, date, winnerresult, loserresult, comment, " . "dateday, winpoints, losepoints, losepoints2, ratingdiff, ip, deleted, " . "host, season, fairness, version, winnerteam, loserteam, teamBonus, teamLadder) " . "VALUES ('{$isDraw}', '{$winnername}', '{$winnername2}', '{$losername}', '{$losername2}', '{$date}', '{$winnerresult}', '{$loserresult}', '{$comment}', " . "'{$dateday}', '{$ra2newwinneradd}', '{$ra2newloserremL1}', '{$ra2newloserremL2}', '{$ratingdiff}', '{$ip}', '{$deleted}', '{$host}', " . "'{$season}', '{$fairness}', '{$version}', '{$winnerteam}', '{$loserteam}', '{$teamBonusWinner}', '{$teamLadder}')";
    } else {
        $sql = "INSERT INTO {$gamestable} " . "(isDraw, winner, winner2, loser, loser2, date, winnerresult, loserresult, comment, " . "dateday, winpoints, losepoints, losepoints2, ratingdiff, ip, deleted, " . "host, season, fairness, version, winnerteam, loserteam, teamBonus, teamLadder, sixGameId) " . "VALUES ('{$isDraw}', '{$winnername}', '{$winnername2}', '{$losername}', '{$losername2}', '{$date}', '{$winnerresult}', '{$loserresult}', '{$comment}', " . "'{$dateday}', '{$ra2newwinneradd}', '{$ra2newloserremL1}', '{$ra2newloserremL2}', '{$ratingdiff}', '{$ip}', '{$deleted}', '{$host}', " . "'{$season}', '{$fairness}', '{$version}', '{$winnerteam}', '{$loserteam}', '{$teamBonusWinner}', '{$teamLadder}', '{$sixGameId}')";
    }
    $log->logInfo('sql: ' . $sql);
    $res = mysql_query($sql);
    $result = $result + $res;
    $log->logInfo('result: ' . $result);
    if ($result > 2) {
        $resultText .= "<p>Your game was successfully reported for the " . $ladderType . " Ladder.</p>";
    } else {
        $resultText .= "<p>There seems to be a problem with the database, your game has not been reported.</p>" . "<p>Please contact an admin if the problem persists.</p>" . "<p>Error code: <b>{$result}</p>";
    }
    echo $resultText;
    return $result;
}