/** * Create a clean new game to apply the test to * * @var string $testID The test ID */ function __construct($testID) { global $DB, $Game, $Variant; /* * Create a clean new game to apply the test to */ $this->testID = $testID; list($id) = $DB->sql_row("SELECT id FROM wD_Games WHERE name='DATC-Adjudicator-Test'"); if ($id) { $DB->sql_put("UPDATE wD_Games SET phase = 'Diplomacy', turn = " . $testID . ", gameOver = 'No' WHERE id = " . $id); } else { $Game = processGame::create(1, 'DATC-Adjudicator-Test', '', 5, 'Winner-takes-all', 30, 30, 'No', 'Regular'); $id = $Game->id; $DB->sql_put("UPDATE wD_Games SET phase = 'Diplomacy', turn = " . $testID . " WHERE id = " . $id); } if (!isset($_REQUEST['DATCResults'])) { self::wipe($id); $countries = array(); for ($i = 1; $i <= count($Variant->countries); $i++) { $countries[] = $i; } $DB->sql_put("INSERT INTO wD_Members (gameID, userID, countryID, bet, timeLoggedIn)\r\n\t\t\t\t\tVALUES " . Database::packArray("(" . $id . ", 2, ", $countries, ", 5, " . time() . ")", ",")); } parent::__construct($id); $GLOBALS['Game'] = $this; $Game = $this; }
/** * Apply the adjudicated moves; move the actual units around and change the ownerships of territories etc * * @param array $standOffTerrs An array of territories which currently have a standoff */ public function apply($standoffTerrs) { global $Game, $DB; /* * - Occupy all units, Set dislodged units to retreat * - Update unit positions * - Empty all territories now without units * - Insert standoffs */ /* * - Occupy all units, Set dislodged units to retreat */ // FIXME: This query seems to take ~1/2 the time of the entire game-processing period $DB->sql_put("INSERT INTO wD_TerrStatus\r\n\t\t\t\t( gameID, countryID, occupyingUnitID, terrID, occupiedFromTerrID, retreatingUnitID )\r\n\t\t\tSELECT\r\n\t\t\t\t" . $Game->id . " as gameID,\r\n\t\t\t\t0 as countryID, /* This will be set later */\r\n\t\t\t\toccupy.unitID as occupyingUnitID,\r\n\t\t\t\toccupy.toTerrID as terrID,\r\n\t\t\t\t/* If we are moving from a convoy we don't register\r\n\t\t\t\tthe territory we came from. See DATC 4.A.5-b */\r\n\t\t\t\tIF( occupy.viaConvoy='No', occupy.terrID, NULL) as occupiedFromTerrID,\r\n\t\t\t\tretreat.unitID as retreatingUnitID\r\n\t\t\tFROM wD_Moves occupy\r\n\t\t\tLEFT JOIN wD_Moves retreat\r\n\t\t\t\tON ( retreat.terrID = occupy.toTerrID AND retreat.dislodged = 'Yes' AND retreat.gameID=" . $GLOBALS['GAMEID'] . " )\r\n\t\t\tWHERE occupy.success = 'Yes' AND occupy.moveType = 'Move' AND occupy.gameID=" . $GLOBALS['GAMEID'] . "\r\n\t\t\tON DUPLICATE KEY\r\n\t\t\t\tUPDATE occupyingUnitID = VALUES(occupyingUnitID),\r\n\t\t\t\t\t\toccupiedFromTerrID = VALUES(occupiedFromTerrID),\r\n\t\t\t\t\t\tretreatingUnitID = VALUES(retreatingUnitID)"); // - Update unit positions $DB->sql_put("UPDATE wD_Units u INNER JOIN wD_Orders o INNER JOIN wD_Moves m ON ( m.gameID=o.gameID AND m.orderID = o.id )\r\n\t\t\tSET u.terrID = o.toTerrID\r\n\t\t\tWHERE o.type='Move' AND m.success='Yes'\r\n\t\t\t\tAND u.id = o.unitID AND o.gameID = " . $Game->id); /* * *** * An important change has happened: Before that query the units were in their * pre-process positions, now all units in the units table are in their updated positions * *** */ // - Empty all territories now without units /* This is now done in processGame::updateTerrStatus $DB->sql_put( "UPDATE wD_TerrStatus t /* If this territory is occupied this join will find a match .. / LEFT JOIN wD_Units u ON ( ".Database::deCoastCompare('t.terrID','u.terrID')." AND u.gameID = t.gameID ) SET occupyingUnitID = NULL WHERE t.gameID = ".$Game->id." /* .. so all territories which aren't matched are updated / AND u.id IS NULL"); */ // - Insert standoffs if (count($standoffTerrs)) { $DB->sql_put("INSERT INTO wD_TerrStatus\r\n\t\t\t\t( gameID, countryID, terrID, standoff )\r\n\t\t\tVALUES " . Database::packArray('(' . $Game->id . ", 0, '", $standoffTerrs, "', 'Yes')", ',') . "\r\n\t\t\tON DUPLICATE KEY UPDATE standoff = 'Yes'"); } // All Units and TerrStatus changes done, except countryID and occupiedByID }
private function compareUserAgentData($bUserID, $bUserTotal) { $aUserTotal = $this->aLogsData['total']; $aUserData = $this->aLogsData['userAgents']; $bTally = array(); $matches = self::sql_list("SELECT HEX(userAgent), COUNT(userAgent)\r\n\t\t\tFROM wD_AccessLog\r\n\t\t\tWHERE userID = " . $bUserID . " AND\r\n\t\t\t\t( " . Database::packArray("UNHEX('", $aUserData, "') = userAgent", " OR ") . " )\r\n\t\t\tGROUP BY userAgent", $bTally); if (count($matches)) { $aTally = array(); self::sql_list("SELECT HEX(userAgent), COUNT(userAgent)\r\n\t\t\t\tFROM wD_AccessLog\r\n\t\t\t\tWHERE userID = " . $this->aUserID . " AND\r\n\t\t\t\t\t( " . Database::packArray("UNHEX('", $matches, "') = userAgent", " OR ") . " )\r\n\t\t\t\tGROUP BY userAgent", $aTally); self::printDataComparison('UserAgent', $matches, count($matches), count($aUserData), array('Italy' => 2 / 3, 'Turkey' => 3 / 4, 'Austria' => 7 / 8), $aTally, $aUserTotal, $bTally, $bUserTotal); } }