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); }