Skip to content

Commit

Permalink
Admin now can lock some games.
Browse files Browse the repository at this point in the history
Players can't enter orders till an issue is resolved.
  • Loading branch information
Sleepcap committed Dec 29, 2012
1 parent 914c704 commit 9301069
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
15 changes: 15 additions & 0 deletions admin/adminActionsRestrictedVDip.php
Expand Up @@ -25,6 +25,11 @@ public function __construct()
'description' => 'Set the orderstatus of all countries to "Ready".',
'params' => array('gameID'=>'GameID')
),
'toggleAdminLock' => array(
'name' => 'Lock/unlock a game.',
'description' => 'Lock (or unlock) a game to prevent users to enter orders.',
'params' => array('gameID'=>'GameID')
),
'delVariantGameCache' => array(
'name' => 'Clear cache of a given variant.',
'description' => 'Clear all cache files of all games from a given variant.',
Expand Down Expand Up @@ -71,6 +76,16 @@ public function clearAdvancedAccessLogs(array $params)
return 'Old advanced access logs cleared; '.$i.' records deleted.';
}

public function toggleAdminLock(array $params)
{
global $DB;
$gameID = (int)$params['gameID'];
list($status)=$DB->sql_row("SELECT adminLock FROM wD_Games WHERE id = ".$gameID);
$DB->sql_put("UPDATE wD_Games SET adminLock = '".($status == 'Yes' ? 'No' : 'Yes')."' WHERE id = ".$gameID);

return 'This game is now '.( $status == 'No' ? 'locked' : 'unlocked').'.';
}

public function RowAsString(array $row)
{
global $DB;
Expand Down
15 changes: 11 additions & 4 deletions board.php
Expand Up @@ -242,11 +242,18 @@

if ( 'Pre-game' != $Game->phase && $Game->phase!='Finished' )
{
$OI = OrderInterface::newBoard();
$OI->load();
if ($Game->adminLock == 'No' || $User->type['Admin'] || defined('AdminUserSwitch'))
{
$OI = OrderInterface::newBoard();
$OI->load();

$Orders = '<div id="orderDiv'.$Member->id.'">'.$OI->html().'</div>';
unset($OI);
$Orders = '<div id="orderDiv'.$Member->id.'">'.$OI->html().'</div>';
unset($OI);
}
else
{
$Orders = '<div id="orderDiv'.$Member->id.'">Game is currently locked by an admin (usually to fix some errors).</div>';
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion board/orders/orderinterface.php
Expand Up @@ -135,7 +135,15 @@ public function load()
$this->Orders[] = $Order;
}

list($checkTurn, $checkPhase) = $DB->sql_row("SELECT turn, phase FROM wD_Games WHERE id=".$this->gameID);
list($checkTurn, $checkPhase, $adminLock) = $DB->sql_row("SELECT turn, phase, adminLock FROM wD_Games WHERE id=".$this->gameID);

if( $adminLock == 'Yes' )
{
list($usertype) = $DB->sql_row("SELECT type FROM wD_Users WHERE id=".$this->userID);
if (strpos($usertype,'Admin')===false)
throw new Exception("Game is currently locked by an admin (usually to fix some errors).");
}

if( $checkTurn != $this->turn || $checkPhase != $this->phase )
throw new Exception("The game has moved on, you can no longer alter these orders, please refresh.");

Expand Down
3 changes: 3 additions & 0 deletions gamepanel/game.php
Expand Up @@ -192,6 +192,9 @@ function gameIcons()
if( $this->pot > $Misc->GameFeaturedThreshold )
$buf .= '<img src="images/icons/star.png" alt="Featured" title="This is a featured game, one of the highest stakes games on the server!" /> ';

if( $this->adminLock == 'Yes' )
$buf .= '<img src="images/icons/lock.png" alt="Locked" title="Game is currently locked by an admin (usually to fix some errors)." /> ';

if( $this->private )
$buf .= '<img src="images/icons/lock.png" alt="Private" title="This is a private game; password needed!" /> ';

Expand Down
2 changes: 2 additions & 0 deletions install/vdip-1.03-1.04/24 - AdminGameLock.sql
@@ -0,0 +1,2 @@
ALTER TABLE `wD_Games` ADD `adminLock` enum('Yes','No') CHARACTER SET utf8 NOT NULL DEFAULT 'No';
ALTER TABLE `wD_Backup_Games` ADD `adminLock` enum('Yes','No') CHARACTER SET utf8 NOT NULL DEFAULT 'No';
8 changes: 8 additions & 0 deletions objects/game.php
Expand Up @@ -245,6 +245,13 @@ public static function gameFolder($gameID)
*/
public $chessTime;

/**
* adminLock, Yes or No (Admins can lock a game for interaction for bugfixing)
*
* @var string
*/
public $adminLock;

/**
* @param int/array $gameData The game ID of the game to load, or the array of its database row
* @param string[optional] $lockMode The database locking phase to use; no locking by default
Expand Down Expand Up @@ -370,6 +377,7 @@ function load()
g.specialCDturn,
g.rlPolicy,
g.chessTime,
g.adminLock,
g.missingPlayerPolicy
FROM wD_Games g
WHERE g.id=".$this->id.' '.$this->lockMode);
Expand Down

0 comments on commit 9301069

Please sign in to comment.