Exemple #1
0
 /**
  * Allow the user to join a game. The User must have enough points, the Game must be
  * locked for UPDATE, if the game is private a password must be supplied, if there is
  * a civil disorder player the member ID of the civil disorder member must be
  * supplied, there mustn't be too many users in the game, the user mustn't join the
  * same game twice, etc, etc.
  *
  * If successful the user is redirected to the game they just joined. If unsuccessful
  * an exception is thrown.
  *
  * @param string[optional] $password The optional password supplied to enter the game
  * @param string[optional] $countryID The countryID to be taken (filtered)
  */
 function join($password = "", $countryID = -1)
 {
     global $DB, $User;
     $countryID = (int) $countryID;
     // If we're not locked for UPDATE we can't keep things consistant
     assert('$this->Game->lockMode == UPDATE');
     if ($this->Game->private and md5($password) != $this->Game->password and $password != $this->Game->password) {
         throw new Exception(l_t("The password you supplied is incorrect, please try again."));
     }
     if (!$this->Game->isJoinable()) {
         throw new Exception(l_t("You cannot join this game."));
     }
     if (!($this->Game->minimumReliabilityRating <= $User->reliabilityRating)) {
         throw new Exception(l_t("Your Reliability Rating of %s%% is not high enough to join this game, which is restricted to %s%% RR and above.", $User->reliabilityRating, $this->Game->minimumReliabilityRating));
     }
     // We can join, the only question is how?
     if ($this->Game->phase == 'Pre-game') {
         // Creates the Member record, the member object, and records the bet
         processMember::create($User->id, $this->Game->minimumBet);
         $M = $this->ByUserID[$User->id];
         if ($this->Game->isMemberInfoHidden()) {
             $this->sendExcept($M, 'No', l_t('Someone has joined the game.'));
         } else {
             $this->sendExcept($M, 'No', l_t('%s has joined the game.', $User->username));
         }
         $M->send('No', 'No', l_t('You have joined! Good luck'));
         if (count($this->ByUserID) == count($this->Game->Variant->countries)) {
             // Ready to start
             $this->Game->resetMinimumBet();
         }
     } else {
         // Taking over from CD: Valid countryID to take over? Got enough points?
         if (0 >= $countryID || count($this->Game->Variant->countries) < $countryID) {
             throw new Exception(l_t("You haven't specified which countryID you want to take over."));
         }
         $CD = $this->ByCountryID[$countryID];
         if ($CD->status != 'Left') {
             throw new Exception(l_t('The player selected is not in civil disorder.'));
         }
         $bet = $CD->pointsValueInTakeover();
         if ($User->points < $bet) {
             throw new Exception(l_t("You do not have enough points to take over that countryID."));
         }
         $CD->setTakenOver();
         // Refund its points if required, and send it a message
         // Start updating the member record and object
         list($orderCount) = $DB->sql_row("SELECT COUNT(id) FROM wD_Orders\r\n\t\t\t\t\tWHERE gameID = " . $CD->gameID . "\r\n\t\t\t\t\t\tAND countryID = " . $CD->countryID);
         $DB->sql_put("UPDATE wD_Members\r\n\t\t\t\t\tSET userID = " . $User->id . ", status='Playing', orderStatus=REPLACE(orderStatus,'Ready',''),\r\n\t\t\t\t\t\tmissedPhases = 0, timeLoggedIn = " . time() . "\r\n\t\t\t\t\tWHERE id = " . $CD->id);
         $DB->sql_put('DELETE FROM wD_WatchedGames WHERE userID=' . $User->id . ' AND gameID=' . $this->Game->id);
         unset($this->ByUserID[$CD->userID]);
         unset($this->ByStatus['Left'][$CD->id]);
         $CD->userID = $User->id;
         $CD->status = 'Playing';
         $CD->missedPhases = 0;
         $CD->orderStatus->Ready = false;
         $CD->points = $User->points;
         $this->ByUserID[$CD->userID] = $CD;
         $this->ByStatus['Playing'][$CD->id] = $CD;
         $CD->makeBet($bet);
         $this->Game->resetMinimumBet();
         $CDCountryName = $this->Game->Variant->countries[$CD->countryID - 1];
         if ($this->Game->isMemberInfoHidden()) {
             $this->sendExcept($CD, 'No', l_t('Someone has taken over %s.', $CDCountryName));
         } else {
             $this->sendExcept($CD, 'No', l_t('%s has taken over %s.', $User->username, $CDCountryName));
         }
         $CD->send('No', 'No', l_t('You took over %s! Good luck', $CDCountryName));
     }
     $this->Game->gamelog(l_t('New member joined'));
     $this->joinedRedirect();
 }
Exemple #2
0
            default:
                $input['drawType'] = 'draw-votes-public';
                break;
        }
        $input['minimumReliabilityRating'] = (int) $input['minimumReliabilityRating'];
        if ($input['minimumReliabilityRating'] < 0 or $input['minimumReliabilityRating'] > 100) {
            throw new Exception(l_t("The reliability rating threshold must range from 0-100"));
        }
        if ($input['minimumReliabilityRating'] > $User->reliabilityRating) {
            throw new Exception(l_t("Your reliability rating is %s%%, so you can't create a game which requires players to have a RR of %s%% or greater.", $User->reliabilityRating, $input['minimumReliabilityRating']));
        }
        // Create Game record & object
        require_once l_r('gamemaster/game.php');
        $Game = processGame::create($input['variantID'], $input['name'], $input['password'], $input['bet'], $input['potType'], $input['phaseMinutes'], $input['joinPeriod'], $input['anon'], $input['pressType'], $input['missingPlayerPolicy'], $input['drawType'], $input['minimumReliabilityRating']);
        // Create first Member record & object
        processMember::create($User->id, $input['bet']);
        $Game->Members->joinedRedirect();
    } catch (Exception $e) {
        print '<div class="content">';
        print '<p class="notice">' . $e->getMessage() . '</p>';
        print '</div>';
    }
}
if ($User->points >= 5) {
    $roundedDefault = round($User->points / 7 / 10) * 10;
    if ($roundedDefault > 5) {
        $defaultPoints = $roundedDefault;
    } else {
        $defaultPoints = 5;
    }
} else {