/** * Send a game message. Messages are sanitized * * @param string $toCountryID The countryID being sent to. 'Global' sends to all. * @param string $fromCountryID The county being sent from. 'GameMaster' can also be used. * @param string|array $message The message(s) to be sent (Can be an array of messages for) * @param int[optional] $gameID The game ID to use. If not given the current global Game is sent to. */ public static function send($toCountryID, $fromCountryID, $message, $gameID = -1) { global $DB, $Game; if (!is_object($Game)) { $Variant = libVariant::loadFromGameID($gameID); $Game = $Variant->Game($gameID); } $message = $DB->msg_escape($message); if (!is_numeric($toCountryID)) { $toCountryID = 0; } if (!is_numeric($fromCountryID)) { $message = '<strong>' . $fromCountryID . ':</strong> ' . $message; $fromCountryID = 0; } if (65000 < strlen($message)) { throw new Exception(l_t("Message too long")); } $DB->sql_put("INSERT INTO wD_GameMessages\r\n\t\t\t\t\t(gameID, toCountryID, fromCountryID, turn, message, timeSent)\r\n\t\t\t\t\tVALUES(" . $Game->id . ",\r\n\t\t\t\t\t\t" . $toCountryID . ",\r\n\t\t\t\t\t\t" . $fromCountryID . ",\r\n\t\t\t\t\t\t" . $Game->turn . ",\r\n\t\t\t\t\t\t'" . $message . "',\r\n\t\t\t\t\t\t" . time() . ")"); if ($toCountryID != $fromCountryID || $fromCountryID == 0) { libGameMessage::notify($toCountryID, $fromCountryID); } }
public function reprocessGame(array $params) { global $DB, $Game; $gameID = (int) $params['gameID']; /* * - Check that the game is still active and can be turned back * * - Delete current turn values * - Calculate the turn being moved back to * * - Move the old MovesArchive back to Units * - Move the old MovesArchive (JOIN Units) back to Orders * - Move the old TerrStatusArchive (JOIN Units) back to TerrStatus * * - Update the game turn, phase and next process time * * - Delete Archive values if we have moved back a turn * - Remove the invalid maps in the mapstore */ $DB->sql_put("BEGIN"); require_once l_r('gamemaster/game.php'); $Variant = libVariant::loadFromGameID($gameID); $Game = $Variant->processGame($gameID); $oldPhase = $Game->phase; $oldTurn = $Game->turn; // - Check that the game is still active and can be turned back if ($Game->turn < 1) { throw new Exception(l_t('This game cannot be turned back; it is new or is finished.')); } // - Delete current turn values $DB->sql_put("DELETE FROM wD_Units WHERE gameID = " . $Game->id); $DB->sql_put("DELETE FROM wD_TerrStatus WHERE gameID = " . $Game->id); $DB->sql_put("DELETE FROM wD_Orders WHERE gameID = " . $Game->id); // - Calculate the turn being moved back to $lastTurn = $Game->phase == 'Diplomacy' ? $Game->turn - 1 : $Game->turn; // - Move the old MovesArchive back to Units $DB->sql_put("INSERT INTO wD_Units ( type, terrID, countryID, gameID )\r\n\t\t\t\t\t\tSELECT unitType, terrID, countryID, gameID FROM wD_MovesArchive\r\n\t\t\t\t\t\tWHERE gameID = " . $Game->id . " AND turn = " . $lastTurn . "\r\n\t\t\t\t\t\t\t/* Make sure only the Diplomacy phase unit positions are used */\r\n\t\t\t\t\t\t\tAND type IN ( 'Hold', 'Move', 'Support hold', 'Support move', 'Convoy' )"); // - Move the old MovesArchive (JOIN Units) back to Orders $DB->sql_put("INSERT INTO wD_Orders (gameID, countryID, type, toTerrID, fromTerrID, viaConvoy, unitID)\r\n\t\t\t\t\t\tSELECT m.gameID, m.countryID, m.type, m.toTerrID, m.fromTerrID, m.viaConvoy, u.id\r\n\t\t\t\t\t\tFROM wD_MovesArchive m INNER JOIN wD_Units u ON ( u.terrID = m.terrID AND u.gameID = m.gameID )\r\n\t\t\t\t\t\tWHERE m.gameID = " . $Game->id . " AND m.turn = " . $lastTurn . "\r\n\t\t\t\t\t\t\t/* Make sure only the Diplomacy phase unit positions are used */\r\n\t\t\t\t\t\t\tAND m.type IN ( 'Hold', 'Move', 'Support hold', 'Support move', 'Convoy' )"); // - Move the old TerrStatusArchive back to TerrStatus $DB->sql_put("INSERT INTO wD_TerrStatus ( terrID, standoff, gameID, countryID, occupyingUnitID )\r\n\t\t\t\t\t\tSELECT t.terrID, t.standoff, t.gameID, t.countryID, u.id\r\n\t\t\t\t\t\tFROM wD_TerrStatusArchive t\r\n\t\t\t\t\t\t\tLEFT JOIN wD_Units u\r\n\t\t\t\t\t\t\tON ( " . $Game->Variant->deCoastCompare('t.terrID', 'u.terrID') . " AND u.gameID = t.gameID )\r\n\t\t\t\t\t\tWHERE t.gameID = " . $Game->id . " AND t.turn = " . $lastTurn); // - Update the game turn, phase and next process time $DB->sql_put("UPDATE wD_Games\r\n\t\t\t\t\tSET turn = " . $lastTurn . ", phase = 'Diplomacy', gameOver='No', processTime = phaseMinutes*60+" . time() . ",\r\n\t\t\t\t\t\tprocessStatus='Not-processing', pauseTimeRemaining=NULL\r\n\t\t\t\t\tWHERE id = " . $Game->id); $DB->sql_put("UPDATE wD_Members SET votes='', orderStatus='',\r\n\t\t\tstatus=IF(status='Won' OR status='Survived' OR status='Drawn' OR status='Playing',\r\n\t\t\t\t'Playing',\r\n\t\t\t\tIF(status='Resigned' OR status='Left','Left','Defeated')\r\n\t\t\t)\r\n\t\t\tWHERE gameID = " . $Game->id); $DB->sql_put("COMMIT"); // - Delete Archive values if we have moved back a turn $DB->sql_put("DELETE FROM wD_TerrStatusArchive WHERE gameID = " . $Game->id . " AND turn = " . $lastTurn); $DB->sql_put("DELETE FROM wD_MovesArchive WHERE gameID = " . $Game->id . " AND turn = " . $lastTurn); // - Remove the invalid maps in the mapstore $Game->load(); Game::wipeCache($Game->id); libGameMessage::send(0, 'GameMaster', l_t('This game has been moved back to %s', $Game->datetxt($lastTurn)), $Game->id); return l_t('This game was moved from %s, %s back to Diplomacy, %s, and is ready to be reprocessed.', $oldPhase, $Game->datetxt($oldTurn), $Game->datetxt($lastTurn)); }
You should have received a copy of the GNU Affero General Public License along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>. */ /** * @package Admin */ require_once 'header.php'; ini_set('memory_limit', "128M"); // 8M is the default ini_set('max_execution_time', '240'); if ($User->type['Moderator'] && isset($_REQUEST['viewOrderLogGame']) && isset($_REQUEST['viewOrderLogCountryID'])) { $gameID = (int) $_REQUEST['viewOrderLogGame']; $countryID = (int) $_REQUEST['viewOrderLogCountryID']; require_once l_r('objects/game.php'); $Variant = libVariant::loadFromGameID($gameID); $Game = $Variant->Game($gameID); if (!($data = file_get_contents(libCache::dirID(Config::orderlogDirectory(), $gameID, true) . '/' . $countryID . '.txt'))) { trigger_error(l_t("Couldn't open file %s.txt", $log)); } header('Content-type:text/plain'); print $data; die; } if ($User->type['Admin'] && isset($_REQUEST['viewErrorLog'])) { $log = (int) $_REQUEST['viewErrorLog']; if (!($data = file_get_contents(Config::errorlogDirectory() . '/' . $log . '.txt'))) { trigger_error(l_t("Couldn't open file %s.txt", $log)); } header('Content-type:text/plain'); print $data;
public function banUser(array $params) { global $User, $DB, $Game; $userID = (int) $params['userID']; if (!isset($params['reason']) || strlen($params['reason']) == 0) { return l_t('Couldn\'t ban user; no reason was given.'); } $banReason = $DB->msg_escape($params['reason']); $banUser = new User($userID); if ($banUser->type['Banned']) { throw new Exception(l_t("The user is already banned")); } if ($banUser->type['Admin']) { throw new Exception(l_t("Admins can't be banned")); } if ($banUser->type['Moderator'] and !$User->type['Admin']) { throw new Exception(l_t("Moderators can't be banned by non-admins")); } User::banUser($userID, l_t("Banned by a moderator:") . ' ' . $params['reason']); require_once l_r('gamemaster/game.php'); /* * Explain what has happened to the games the banned user was in, and extend the * turn */ $tabl = $DB->sql_tabl("SELECT gameID, status FROM wD_Members\r\n\t\t\t\t\tWHERE userID = " . $userID); while (list($gameID, $status) = $DB->tabl_row($tabl)) { if ($status != 'Playing') { continue; } $Variant = libVariant::loadFromGameID($gameID); $Game = $Variant->processGame($gameID); $banMessage = l_t('%s was banned: %s. ', $banUser->username, $banReason); if ($Game->phase == 'Pre-game') { if (count($Game->Members->ByID) == 1) { processGame::eraseGame($Game->id); } else { $DB->sql_put("DELETE FROM wD_Members WHERE gameID = " . $Game->id . " AND userID = " . $userID); } } elseif ($Game->processStatus != 'Paused' and $Game->phase != 'Finished') { // The game may need a time extension to allow for a new player to be added // Would the time extension would give a difference of more than ten minutes? If not don't bother if (time() + $Game->phaseMinutes * 60 - $Game->processTime > 10 * 60) { // It is worth adding an extension $DB->sql_put("UPDATE wD_Games\r\n\t\t\t\t\t\tSET processTime = " . time() . " + phaseMinutes*60\r\n\t\t\t\t\t\tWHERE id = " . $Game->id); $Game->processTime = time() + $Game->phaseMinutes * 60; $banMessage .= l_t('The time until the next phase has been extended by one phase length ' . 'to give an opportunity to replace the player.') . "\n" . l_t('Remember to finalize your orders if you don\'t want ' . 'to wait, so the game isn\'t held up unnecessarily!'); } } // IF the game is still running first remove the player from the game and reset the minimum bet so other can join. if ($Game->phase != 'Finished' && $Game->phase != 'Pre-game') { $Game->Members->ByUserID[$userID]->setLeft(1); $Game->resetMinimumBet(); } libGameMessage::send('Global', 'GameMaster', $banMessage); $Game->Members->sendToPlaying('No', l_t('%s was banned, see in-game for details.', $banUser->username)); } $DB->sql_put("UPDATE wD_Orders o INNER JOIN wD_Members m ON ( m.gameID = o.gameID AND m.countryID = o.countryID )\r\n\t\t\t\t\tSET o.toTerrID = NULL, o.fromTerrID = NULL\r\n\t\t\t\t\tWHERE m.userID = " . $userID); unset($Game); return l_t('This user was banned, and had their %s points removed and their games set to civil disorder.', $banUser->points); }
public function cdUser(array $params) { global $DB; require_once l_r('gamemaster/game.php'); $User = new User($params['userID']); $Variant = libVariant::loadFromGameID($this->fixedGameID); $Game = $Variant->processGame($this->fixedGameID); if ($Game->phase == 'Pre-game' || $Game->phase == 'Finished') { throw new Exception(l_t("Invalid phase to set CD")); } $Game->Members->ByUserID[$User->id]->setLeft(1); $Game->resetMinimumBet(); return l_t('This user put into civil-disorder in this game'); }
/** * For the given task display the form, and run the task if data entered from the corresponding form * * @param string $actionName The code-name for the desired task */ public function process($actionName) { global $Misc; // TODO: Use late static binding for this instead of INBOARD detection extract($this->actionsList[$actionName]); print '<li class="formlisttitle"> <a name="' . $actionName . '"></a>' . l_t($name) . '</li>'; try { if (isset($_REQUEST['actionName']) and $_REQUEST['actionName'] == $actionName) { print '<li class="formlistfield">'; $paramValues = array(); foreach ($params as $paramName => $paramFullName) { if (isset($_REQUEST[$paramName])) { $paramValues[$paramName] = $_REQUEST[$paramName]; } } if (isset($paramValues['gameID'])) { require_once l_r('objects/game.php'); $Variant = libVariant::loadFromGameID((int) $paramValues['gameID']); $Game = $Variant->Game((int) $paramValues['gameID']); print '<p>' . l_t('Game link') . ': <a href="board.php?gameID=' . $Game->id . '">' . $Game->name . '</a></p>'; } if (isset($paramValues['userID'])) { $User = new User((int) $paramValues['userID']); print '<p>' . l_t('User link') . ': ' . $User->profile_link() . '</p>'; } if (isset($paramValues['postID'])) { print '<p>' . l_t('Post link') . ': ' . libHTML::threadLink($paramValues['postID']) . '</p>'; } // If it needs confirming but ( hasn't been confirmed or is being resubmitted ): if (!self::isActionDangerous($actionName) && (!isset($_REQUEST['actionConfirm']) || !libHTML::checkTicket())) { print '<strong>' . $this->{$actionName . 'Confirm'}($paramValues) . '</strong>'; print '<form action="' . self::$target . '#' . $actionName . '" method="post"> <input type="hidden" name="actionName" value="' . $actionName . '" /> <input type="hidden" name="actionConfirm" value="on" /> <input type="hidden" name="formTicket" value="' . libHTML::formTicket() . '" />'; foreach ($paramValues as $name => $value) { print '<input type="hidden" name="' . $name . '" value="' . $value . '" />'; } print '</li><li class="formlistfield" style="margin-bottom:20px"> <input type="submit" class="form-submit" value="Confirm" /> </form>'; } else { $details = $this->{$actionName}($paramValues); self::save($name, $paramValues, $details); $description = '<p class="notice">' . $details . '</p> <p>' . l_t($description) . '</p>'; $Misc->LastModAction = time(); } print '</li>'; } } catch (Exception $e) { $description = '<p><strong>' . l_t('Error') . ':</strong> ' . $e->getMessage() . '</p> <p>' . l_t($description) . '</p>'; } self::form($actionName, $params, $description); }
* - What turn are we viewing? * - Is the map we want in the cache? * - Draw countryID colors, standoffs, from TerrStatusArchive * - Draw units, order arrows, from MovesArchive * - Save map * - Recreate map cache files * - Output map */ ini_set('memory_limit', "14M"); ini_set('max_execution_time', '12'); if (!isset($_REQUEST['variantID'])) { /* * Get the two required parameters; game ID and turn */ global $Game; $Variant = libVariant::loadFromGameID($_REQUEST['gameID']); libVariant::setGlobals($Variant); // The game is locked for update so the map isn't drawn twice at the same time $Game = $Variant->Game($_REQUEST['gameID'], UPDATE); /* * Determine which turn we are viewing. This is made a little trickier because * in the Diplomacy phase the *previous* turn is drawn. $_REQUEST['turn'] is * expected to have already been adjusted for this: If this game is in * Diplomacy phase turn should already be one less than the Game's turn */ // Determine the turn number: if ($Game->phase == 'Diplomacy') { $latestTurn = $Game->turn - 1; } else { $latestTurn = $Game->turn; }