Example #1
0
 /**
  * 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));
 }
Example #3
0
 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);
 }
Example #4
0
 /**
  * Post a message to the given countryID, if there is one to be posted. Will also send messages as a
  * GameMaster if the user is a moderator which isn't joined into the game.
  *
  * @param $msgCountryID The countryID to post to, may include 0 (Global)
  */
 public function postMessage($msgCountryID)
 {
     global $Member, $Game, $User, $DB;
     if (isset($_REQUEST['newmessage']) and $_REQUEST['newmessage'] != "") {
         $newmessage = trim($_REQUEST['newmessage']);
         if (isset($Member) && ($Game->pressType == 'Regular' || $Member->countryID == $msgCountryID || $msgCountryID == 0 && ($Game->pressType == 'PublicPressOnly' || $Game->pressType == 'NoPress' && $Game->phase == 'Finished'))) {
             $sendingToMuted = false;
             if ($msgCountryID != 0) {
                 $SendToUser = new User($Game->Members->ByCountryID[$msgCountryID]->userID);
                 if ($SendToUser->isCountryMuted($Game->id, $Member->countryID)) {
                     $sendingToMuted = true;
                 }
             }
             if ($sendingToMuted) {
                 libGameMessage::send($Member->countryID, $msgCountryID, l_t("Cannot send message; this country has muted you."));
             } else {
                 libGameMessage::send($msgCountryID, $Member->countryID, $newmessage);
             }
         } elseif ($User->type['Moderator']) {
             libGameMessage::send(0, 'Moderator', '(' . $User->username . '): ' . $newmessage);
         }
     }
     if (isset($_REQUEST['MarkAsUnread'])) {
         $DB->sql_put("UPDATE wD_Members SET newMessagesFrom = IF( (newMessagesFrom+0) = 0,'" . $msgCountryID . "', CONCAT_WS(',',newMessagesFrom,'" . $msgCountryID . "') )\r\n\t\t\t\t\t\tWHERE gameID = " . $Game->id . " AND countryID=" . $Member->countryID);
         $Member->newMessagesFrom[] = $msgCountryID;
     }
 }