コード例 #1
0
 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;
 }
コード例 #2
0
ファイル: variant.php プロジェクト: Yoyoyozo/webDiplomacy
 /**
  * For everything in board/* (used by ajax.php and board.php) it can be assumed that only one variant
  * will be loaded, so here that variant is defined where it will be globally accessible.
  *
  * @param Variant $Variant
  * @return unknown_type
  */
 public static function setGlobals(WDVariant $Variant)
 {
     if (isset(libVariant::$Variant)) {
         // In DATC tests this might get called twice
         if (libVariant::$Variant->id == $Variant->id) {
             return;
         } else {
             trigger_error(l_t("Alternate variant being set as global"));
         }
     } else {
         libVariant::$Variant = $Variant;
         define('VARIANTID', $Variant->id);
         define('MAPID', $Variant->mapID);
     }
 }
コード例 #3
0
ファイル: gamemessage.php プロジェクト: Yoyoyozo/webDiplomacy
 /**
  * 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);
     }
 }
コード例 #4
0
 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');
 }
コード例 #5
0
ファイル: admincp.php プロジェクト: Yoyoyozo/webDiplomacy
   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;
コード例 #6
0
ファイル: variant.php プロジェクト: Yoyoyozo/webDiplomacy
 /**
  * The location of the territories JSON file which gives the order-generation JavaScript the board layout it needs.
  * Some variants need to extend this function to point to another variant which defines their shared map.
  *
  * @return string
  */
 public function territoriesJSONFile()
 {
     return l_j(libVariant::cacheDir($this->name) . '/territories.js');
 }
コード例 #7
0
ファイル: user.php プロジェクト: Yoyoyozo/webDiplomacy
 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;
 }
コード例 #8
0
ファイル: search.php プロジェクト: Yoyoyozo/webDiplomacy
 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;
 }
コード例 #9
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);
 }
コード例 #10
0
ファイル: redirect.php プロジェクト: Yoyoyozo/webDiplomacy
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   webDiplomacy is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with webDiplomacy.  If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'header.php';
if ((isset($_POST['watch']) || isset($_POST['unwatch'])) && isset($_POST['gameID'])) {
    require_once l_r('objects/game.php');
    require_once l_r('gamepanel/gameboard.php');
    $gameID = (int) $_POST['gameID'];
    // Get the game object, if this fails, then someone has entered some rubbish for the gameID
    $Variant = libVariant::loadFromGameID($gameID);
    libVariant::setGlobals($Variant);
    $Game = $Variant->panelGameBoard($gameID);
    if (isset($_POST['unwatch'])) {
        $Game->unwatch();
        print "Unwatched";
    } else {
        if (isset($_POST['watch'])) {
            $Game->watch();
            print "Watched";
        }
    }
}
header('Location: index.php');
コード例 #11
0
ファイル: gamemaster.php プロジェクト: Yoyoyozo/webDiplomacy
    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..') . ' ';
コード例 #12
0
ファイル: map.php プロジェクト: Yoyoyozo/webDiplomacy
        }
        $owners[$terrID] = $countryID;
        $drawMap->colorTerritory($terrID, $countryID);
    }
    if (isset($Game) && $Game->phase == 'Retreats' or $mapType != 'small') {
        // Only draw standoffs if we're in the retreats phase, or we're viewing that large map
        if ($standoff == 'Yes') {
            $drawMap->drawStandoff($terrID);
        }
    }
}
if (isset($_REQUEST['variantID'])) {
    $drawMap->addTerritoryNames();
    $drawMap->saveThumbnail(libVariant::cacheDir($Variant->name) . '/sampleMap-thumbnail.png');
    $drawMap->write(libVariant::cacheDir($Variant->name) . '/sampleMap.png');
    libHTML::serveImage(libVariant::cacheDir($Variant->name) . '/sampleMap.png');
    die;
}
/*
 * Collect the de-coast mappings. There are 4 types of moves which store decoasted territory data, which now
 * needs to be reconstructed to determine the actual positions.
 */
$deCoastMap = array('SupportMoveFromTerrID' => array(), 'SupportMoveToTerrID' => array(), 'SupportHoldToTerrID' => array(), 'DestroyToTerrID' => array());
$tabl = $DB->sql_tabl("SELECT type, terrID, toTerrID, dislodged, success FROM wD_MovesArchive\r\n\tWHERE gameID = " . $Game->id . " AND turn = " . $turn . " AND unitType='Fleet' AND\r\n\t\t( type='Hold' OR type='Move' OR type='Support hold' OR type='Support move' )");
while (list($moveType, $terrID, $toTerrID, $dislodged, $success) = $DB->tabl_row($tabl)) {
    $terrDeCoast = $Game->Variant->deCoast($terrID);
    $toTerrDeCoast = $Game->Variant->deCoast($toTerrID);
    if ($terrDeCoast != $terrID) {
        $deCoastMap['SupportMoveFromTerrID'][$terrDeCoast] = $terrID;
        $deCoastMap['SupportHoldToTerrID'][$terrDeCoast] = $terrID;
        if (($moveType != 'Move' || $success == 'No') && $dislodged == 'No') {
コード例 #13
0
    /**
     * 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);
    }
コード例 #14
0
ファイル: variants.php プロジェクト: Yoyoyozo/webDiplomacy
    foreach ($variantsOff as $variantName) {
        $Variant = libVariant::loadFromVariantName($variantName);
        print '<li><a href="variants.php#' . $Variant->name . '">' . l_t($Variant->name) . '</a> ' . l_t('(%s Players)', count($Variant->countries)) . '</li>';
    }
    print '</ul>';
}
libHTML::pagebreak();
foreach ($variantsOn as $variantName) {
    $Variant = libVariant::loadFromVariantName($variantName);
    print '<h2><a name="' . $Variant->name . '"></a>' . l_t($Variant->fullName) . ' ' . l_t('(%s Players)', count($Variant->countries)) . '</h2>';
    if (isset($Variant->description)) {
        print l_t($Variant->description) . "<br /><br />";
    }
    print '<div style="text-align:center"><img id="Image_' . $Variant->name . '" src="';
    if (file_exists(l_s(libVariant::cacheDir($Variant->name) . '/sampleMap.png'))) {
        print l_s(libVariant::cacheDir($Variant->name) . '/sampleMap.png');
    } else {
        print 'map.php?variantID=' . $Variant->id;
    }
    print '" alt=" " title="' . l_t('The map for the %s Variant', $Variant->name) . '" /></div><br />';
    print '<strong>' . l_t('Variant Parameters') . '';
    if (isset($Variant->version)) {
        print ' ' . l_t('(Version: %s)', $Variant->version) . '';
    }
    print ':</strong>';
    print '<ul>';
    if (isset($Variant->homepage)) {
        print '<li><a href="' . $Variant->homepage . '">' . l_t('Variant homepage') . '</a></li>';
    }
    if (isset($Variant->author)) {
        print '<li> ' . l_t('Created by: %s', $Variant->author) . '</li>';
コード例 #15
0
ファイル: interactive.php プロジェクト: Yoyoyozo/webDiplomacy
 * 		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 {
コード例 #16
0
ファイル: game.php プロジェクト: Yoyoyozo/webDiplomacy
 /**
  * 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);
 }
コード例 #17
0
ファイル: index.php プロジェクト: Yoyoyozo/webDiplomacy
    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;
    }
コード例 #18
0
 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));
 }
コード例 #19
0
ファイル: gamecreate.php プロジェクト: Yoyoyozo/webDiplomacy
    foreach (Config::$variants as $variantID => $variantName) {
    }
    $defaultVariantName = $variantName;
    print '<input type="hidden" name="newGame[variantID]" value="' . $variantID . '" />';
} else {
    ?>
	<li class="formlisttitle">Variant map/rules:</li>
	<li class="formlistfield">
	<?php 
    $checkboxes = array();
    $first = true;
    foreach (Config::$variants as $variantID => $variantName) {
        if ($first) {
            $defaultVariantName = $variantName;
        }
        $Variant = libVariant::loadFromVariantName($variantName);
        $checkboxes[] = '<input type="radio" ' . ($first ? 'checked="on" ' : '') . 'name="newGame[variantID]" value="' . $variantID . '"> ' . $Variant->link();
        $first = false;
    }
    print '<p>' . implode('</p><p>', $checkboxes) . '</p>';
    ?>
	</li>
	<li class="formlistdesc">
		Select which type of Diplomacy game you would like to play from a selection of maps and alternate rule settings
		available on this server.<br /><br />

		Click any of the variant names to view the details on the variants page.<br /><br />

		<strong>Default:</strong> <?php 
    print $defaultVariantName;
    ?>