public static function newJSON($key, $json) { $inContext = (array) json_decode($json); $authContext = self::getContext($inContext); $inContext = $authContext['context']; if ($authContext['key'] != $key) { throw new Exception("JSON token given is invalid"); } require_once l_r('lib/variant.php'); $Variant = libVariant::loadFromVariantID($inContext['variantID']); libVariant::setGlobals($Variant); require_once l_r('objects/basic/set.php'); $OI = $Variant->OrderInterface($inContext['gameID'], $inContext['variantID'], $inContext['userID'], $inContext['memberID'], $inContext['turn'], $inContext['phase'], $inContext['countryID'], new setMemberOrderStatus($inContext['orderStatus']), $inContext['tokenExpireTime'], $inContext['maxOrderID']); return $OI; }
public function unCrashGames(array $params) { global $DB; require_once l_r('gamemaster/game.php'); $excludeGameIDs = explode(',', $params['excludeGameIDs']); foreach ($excludeGameIDs as $index => $gameID) { $gameID = (int) $gameID; $excludeGameIDs[$index] = $gameID; } $excludeGameIDs = implode(',', $excludeGameIDs); $tabl = $DB->sql_tabl("SELECT * FROM wD_Games WHERE processStatus = 'Crashed' " . ($excludeGameIDs ? "AND id NOT IN (" . $excludeGameIDs . ")" : "") . " FOR UPDATE"); $count = 0; while ($row = $DB->tabl_hash($tabl)) { $count++; $Variant = libVariant::loadFromVariantID($row['variantID']); $Game = $Variant->processGame($row); if ($Game->phase == 'Finished') { $DB->sql_put("UPDATE wD_Games SET processStatus = 'Not-processing', pauseTimeRemaining=NULL, processTime = " . time() . " WHERE id = " . $Game->id); continue; } if ($Game->phaseMinutes < 12 * 60) { if ($Game->phase == 'Pre-game') { $newTimeDetails = ""; $DB->sql_put("UPDATE wD_Games SET processStatus = IF(pauseTimeRemaining IS NULL,'Not-processing','Paused') WHERE id = " . $Game->id); } else { $newTimeDetails = l_t(", and the game has been paused, since it's a fast game, to give players a chance to regroup"); $Game->processStatus = 'Not-processing'; $Game->togglePause(); } } else { $newTimeDetails = l_t(", and the game's next process time has been reset"); $DB->sql_put("UPDATE wD_Games SET processStatus = 'Not-processing', processTime = " . time() . " + 60*phaseMinutes, pauseTimeRemaining=NULL WHERE id = " . $Game->id); } $Game->Members->send('No', l_t("This game has been uncrashed%s. Thanks for your patience.", $newTimeDetails)); } /* Simpler, but doesn't accomodate live games well $DB->sql_put( "UPDATE wD_Games SET processStatus = 'Not-processing', processTime = ".time()." + 60*phaseMinutes WHERE AND processStatus = 'Crashed' ".( $excludeGameIDs ? "AND id NOT IN (".$excludeGameIDs.")" : "" ) );*/ $details = l_t('All crashed games were un-crashed'); if ($excludeGameIDs) { $details .= l_t(', except: %s', $excludeGameIDs); } $details .= l_t('. %s games in total.', $count); return $details; }
miscUpdate::errorLog(); miscUpdate::forum(); miscUpdate::game(); miscUpdate::user(); } //- Check last process time, pause processing/save current process time if (time() - $Misc->LastProcessTime > Config::$downtimeTriggerMinutes * 60) { libHTML::notice(l_t('Games not processing'), libHTML::admincp('resetLastProcessTime', null, l_t('Continue processing now'))); } $Misc->LastProcessTime = time(); $Misc->write(); $startTime = time(); // Only do ~30 sec of processing per cycle $tabl = $DB->sql_tabl("SELECT * FROM wD_Games\r\n\tWHERE processStatus='Not-processing' AND processTime <= " . time() . " AND NOT phase='Finished'"); while (time() - $startTime < 30 && ($gameRow = $DB->tabl_hash($tabl))) { $Variant = libVariant::loadFromVariantID($gameRow['variantID']); $Game = $Variant->Game($gameRow); print '<a href="board.php?gameID=' . $Game->id . '">gameID=' . $Game->id . ': ' . $Game->name . '</a>: '; try { if ($Game->processStatus != 'Crashed' && $Game->attempts > count($Game->Members->ByID) * 2) { $Game = $Variant->processGame($Game->id); $Game->crashed(); $DB->sql_put("COMMIT"); print 'Crashed.'; } elseif ($Game->needsProcess()) { $DB->sql_put("UPDATE wD_Games SET attempts=attempts+1 WHERE id=" . $Game->id); $DB->sql_put("COMMIT"); print 'Rechecking.. '; $Game = $Variant->processGame($Game->id); if ($Game->needsProcess()) { print l_t('Processing..') . ' ';
public function printGamesList($Pager = null) { global $DB; $SQL = $this->sql(); //$this->devQueryData($SQL); if ($Pager instanceof Pager) { $SQL .= $Pager->SQLLimit(); } $tabl = $DB->sql_tabl($SQL); $count = 0; print '<div class="gamesList">'; while ($row = $DB->tabl_hash($tabl)) { $count++; $Variant = libVariant::loadFromVariantID($row['variantID']); $G = $Variant->panelGame($row); print $G->summary(false); print '<div class="hr"></div>'; } print '</div>'; return $count; }
foreach ($User->getMuteCountries() as $muteGamePair) { list($gameID, $muteCountryID) = $muteGamePair; if (!isset($MutedGames[$gameID])) { $MutedGames[$gameID] = array(); } $MutedGames[$gameID][] = $muteCountryID; } if (count($MutedGames) > 0) { print '<li class="formlisttitle">Muted countries:</li>'; print '<li class="formlistdesc">The countries which you muted, and are unable to send you messages.</li>'; print '<li class="formlistfield"><ul>'; $LoadedVariants = array(); foreach ($MutedGames as $gameID => $mutedCountries) { list($variantID) = $DB->sql_row("SELECT variantID FROM wD_Games WHERE id=" . $gameID); if (!isset($LoadedVariants[$variantID])) { $LoadedVariants[$variantID] = libVariant::loadFromVariantID($variantID); } $Game = $LoadedVariants[$variantID]->Game($gameID); print '<li>' . $Game->name . '<ul>'; foreach ($mutedCountries as $mutedCountryID) { print '<li>' . $Game->Members->ByCountryID[$mutedCountryID]->country . ' ' . libHTML::muted("board.php?gameID=" . $Game->id . "&msgCountryID=" . $mutedCountryID . "&toggleMute=" . $mutedCountryID . "&rand=" . rand(0, 99999) . '#chatboxanchor') . '</li>'; } print '</ul></li>'; } print '</ul></li>'; } $tablMutedThreads = $DB->sql_tabl("SELECT mt.muteThreadID, f.subject, f.replies, fu.username " . "FROM wD_MuteThread mt " . "INNER JOIN wD_ForumMessages f ON f.id = mt.muteThreadID " . "INNER JOIN wD_Users fu ON fu.id = f.fromUserID " . "WHERE mt.userID = " . $User->id); $mutedThreads = array(); while ($mutedThread = $DB->tabl_hash($tablMutedThreads)) { $mutedThreads[] = $mutedThread; }
* Once adjudication is done the outcomes are tested against the DATC test's required outcomes, differences result * in exceptions. Then orders and units are archived and the game is set to a phase where it'll be drawn by map.php. * - Two map.php requests, for large and small maps, are submitted. DATC tests are written to a different folder, and * will overwrite existing maps by default, but are otherwise handled as regular maps are. * If DATC testing is in batch mode, and no errors occurred, the page will move onto the next test after a 1 second wait. * This continues until all tests are complete or an error is found. Once all tests are complete the DATC test * game is wiped. * * The code is inefficient, messy, will corrupt games being processed normally at the same time, and may screw up badly if * run two at a time, but it works and provides an easy way to test changes to orders/adjudication code. * * Non-Diplomacy phase DATC tests are currently unsupported. */ print l_t('Loading test') . ' <strong><a href="http://web.inter.nl.net/users/L.B.Kruijswijk/#' . $testName . '">' . $testName . '</a></strong>: ' . $testDesc . '<br /><br />'; global $Variant; $Variant = libVariant::loadFromVariantID($variantID); $testCase = new datcGame($testID); $testCase->outputTest(); print l_t('Initialized test'); if (!isset($_REQUEST['DATCResults'])) { // We're loading a new test: Set the game up $testCase->initialize(); print ', ' . l_t('generating orders') . '<br /><br />'; $testCase->submitOrders(); print l_t('Orders being generated and sumbitted') . '...<br /><br />'; // submitOrders() has code that will submit the results of all countryID's ajax JSON orders updates once finished. } else { // Since the code above all countryID's orders have been submitted, and the results are now given via a JSON encoded DATCResults parameter. // Order updates have been saved to wD_Orders; check the ajax.php results are correct, then adjudicate and check the adjudication results. $_REQUEST['DATCResults'] = (array) json_decode($_REQUEST['DATCResults']); try {
/** * Create a new game, insert it into the database, return the Game object. * * @param string $name The name of the game * @param string $password The password required to join the game * @param int $bet The amount which needs to be bet into the game to join initially * @param string $potType 'Winner-takes-all' or 'Points-per-supply-center' * * @return Game The object corresponding to the new game */ public static function create($variantID, $name, $password, $bet, $potType, $phaseMinutes, $joinPeriod, $anon, $press, $missingPlayerPolicy = 'Normal', $drawType, $rrLimit) { global $DB; if ($name == 'DATC-Adjudicator-Test' and !defined('DATC')) { throw new Exception(l_t("The game name 'DATC-Adjudicator-Test' is reserved for the automated DATC tester.")); } // Find a unique game name $unique = false; $i = 1; while (!$unique) { list($count) = $DB->sql_row("SELECT COUNT(id) FROM wD_Games WHERE name='" . $name . ($i > 1 ? '-' . $i : '') . "'"); if ($count == 0) { $unique = true; } else { $i++; } } /* * The password is not salted, because it's given out to several people anyway and it * isn't worth changing the existing behaviour. */ $pTime = time() + $joinPeriod * 60; $pTime = $pTime - fmod($pTime, 300) + 300; // for short game & phase timer $DB->sql_put("INSERT INTO wD_Games\r\n\t\t\t\t\tSET variantID=" . $variantID . ",\r\n\t\t\t\t\t\tname = '" . $name . ($i > 1 ? '-' . $i : '') . "',\r\n\t\t\t\t\t\tpotType = '" . $potType . "',\r\n\t\t\t\t\t\tpot = 0, /* This will receive the first player's bet soon */\r\n\t\t\t\t\t\tminimumBet = " . $bet . ",\r\n\t\t\t\t\t\tanon = '" . $anon . "',\r\n\t\t\t\t\t\tpressType = '" . $press . "',\r\n\t\t\t\t\t\t" . ($password ? "password = UNHEX('" . md5($password) . "')," : "") . "processTime = " . $pTime . ",\n\t\t\t\t\t\tphaseMinutes = " . $phaseMinutes . ",\r\n\t\t\t\t\t\tmissingPlayerPolicy = '" . $missingPlayerPolicy . "',\n\t\t\t\t\t\tdrawType='{$drawType}', minimumReliabilityRating={$rrLimit}"); $gameID = $DB->last_inserted(); $Variant = libVariant::loadFromVariantID($variantID); return $Variant->processGame($gameID); }
public static function gameNotifyBlock() { global $User, $DB; $tabl = $DB->sql_tabl("SELECT g.* FROM wD_Games g\r\n\t\t\tINNER JOIN wD_Members m ON ( m.userID = " . $User->id . " AND m.gameID = g.id )\r\n\t\t\tWHERE NOT g.phase = 'Finished'\r\n\t\t\tORDER BY g.processStatus ASC, g.processTime ASC"); $buf = ''; $count = 0; while ($game = $DB->tabl_hash($tabl)) { $count++; $Variant = libVariant::loadFromVariantID($game['variantID']); $Game = $Variant->panelGameHome($game); $buf .= '<div class="hr"></div>'; $buf .= $Game->summary(); } if ($count == 0) { $buf .= '<div class="hr"></div>'; $buf .= '<div class="bottomborder"><p class="notice">' . l_t('You\'re not joined to any games!') . '<br /> ' . l_t('Access the <a href="gamelistings.php?tab=">Games</a> ' . 'link above to find games you can join, or start a ' . '<a href="gamecreate.php">New game</a> yourself.</a>') . '</p></div>'; } elseif ($count == 1 && $User->points > 5) { $buf .= '<div class="hr"></div>'; $buf .= '<div class="bottomborder"><p class="notice">' . l_t('You can join as many games as you ' . 'have the points to join.') . ' </a></p></div>'; } return $buf; }
*/ // Determine the turn number: if ($Game->phase == 'Diplomacy') { $latestTurn = $Game->turn - 1; } else { $latestTurn = $Game->turn; } $turn = $latestTurn; $givenTurn = (int) $_REQUEST['turn']; if ($givenTurn >= -1 && $givenTurn <= $latestTurn) { $turn = $givenTurn; } unset($givenTurn); $mapType = Game::mapType(); } else { $Variant = libVariant::loadFromVariantID($_REQUEST['variantID']); libVariant::setGlobals($Variant); $mapType = 'small'; $turn = -1; } // Load the drawMap object for the given map type if ($mapType == 'xml') { require_once l_r('map/drawMapXML.php'); $drawMap = $Variant->drawMapXML(); } elseif ($mapType == 'json') { require_once l_r('board/orders/jsonBoardData.php'); $filename = Game::mapFilename($Game->id, $turn, 'json'); file_put_contents($filename, jsonBoardData::getBoardTurnData($Game->id)); libHTML::serveImage($filename, 'text/plain'); } else { require_once l_r('map/drawMap.php');