DIR : /home/kozerus/public_html/dgs/scripts/fix_games_timeleft.php
/home/kozerus/public_html/dgs/scripts
<?php
/*
Dragon Go Server
Copyright (C) 2001- Erik Ouchterlony, Jens-Uwe Gaspar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
chdir( '../' );
require_once 'include/std_functions.php';
require_once 'include/std_classes.php';
require_once 'include/time_functions.php';
require_once 'include/game_functions.php';
$GLOBALS['ThePage'] = new Page('Script', PAGEFLAG_IMPLICIT_FLUSH );
{
connect2mysql();
set_time_limit(0); // don't want script-break during "transaction" with multi-db-queries or for large-datasets
$logged_in = who_is_logged( $player_row, LOGIN_DEFAULT_OPTS_ADM_OPS );
if ( !$logged_in )
error('login_if_not_logged_in', 'scripts.fix_games_timeleft');
if ( $player_row['ID'] <= GUESTS_ID_MAX )
error('not_allowed_for_guest', 'scripts.fix_games_timeleft');
if ( !(@$player_row['admin_level'] & (ADMIN_DATABASE|ADMIN_GAME)) )
error('adminlevel_too_low', 'scripts.fix_games_timeleft');
$page = $_SERVER['PHP_SELF'];
$page_args = array();
start_html( 'fix_games_timeleft', true/*no-cache*/ );
//echo ">>>> One shot fix. Do not run it again."; end_html(); exit;
$do_it = @$_REQUEST['do_it'];
if ( $do_it )
{
function dbg_query($s, $msg='') {
if ( !mysql_query( $s) )
die("<BR>$s;<BR>" . ($msg ? "; -- $msg" : '') . mysql_error() );
}
echo "<p>*** Fixes Games.TimeOutDate ***"
."<br>".anchor(make_url($page, $page_args), 'Just show it')
."</p>";
}
else
{
function dbg_query($s, $msg='') { echo "<BR>$s" . ($msg ? "; -- $msg" : ''); }
$tmp = array_merge($page_args,array('do_it' => 1));
echo "<p>(just show needed queries)"
."<br>".anchor(make_url($page, $page_args), 'Show it again')
."<br>".anchor(make_url($page, $tmp), '[Validate it]')
."</p>";
}
echo "<hr>Find running games ...";
$qsql = new QuerySQL(
SQLP_FIELDS,
"G.*",
"black.OnVacation AS Black_OnVacation",
"white.OnVacation AS White_OnVacation",
SQLP_FROM,
"Games AS G",
"INNER JOIN Players AS black ON black.ID=G.Black_ID",
"INNER JOIN Players AS white ON white.ID=G.White_ID",
SQLP_WHERE,
"Status ".IS_STARTED_GAME
);
//$qsql->add_part( SQLP_WHERE, "TimeOutDate=0" ); // unset games
$query = $qsql->get_select();
//echo $query;
$result = mysql_query( $query ) or die(mysql_error());
$games_cnt = @mysql_num_rows($result);
$curr_cnt = 0;
echo "<br>Found $games_cnt games to process and calculate time left ...\n";
// update Games.TimeOutDate
while ( $row = mysql_fetch_assoc($result) )
{
$gid = $row['ID'];
$to_move = ($row['Black_ID'] == $row['ToMove_ID']) ? BLACK : WHITE;
$timeout_date = NextGameOrder::make_timeout_date( $row, $to_move, $row['ClockUsed'], $row['LastTicks'] );
if ( $row['TimeOutDate'] != $timeout_date )
update_games_timeoutdate( $gid, $timeout_date, $row['TimeOutDate'] );
}
mysql_free_result($result);
if ( $do_it )
echo 'Running games remaining-time fix for Games.TimeOutDate finished.';
echo "<p></p>Done.";
end_html();
}//main
function update_games_timeoutdate( $gid, $timeout_date, $curr_timeout_date )
{
global $games_cnt, $curr_cnt;
if ( ($curr_cnt++ % 50) == 0 )
echo "<br><br>... $curr_cnt of $games_cnt updated ...\n";
$update_query = "UPDATE Games SET TimeOutDate=$timeout_date WHERE ID='$gid' LIMIT 1";
dbg_query($update_query,
sprintf( '%s -> %s (%s)', $curr_timeout_date, $timeout_date, $timeout_date - $curr_timeout_date) );
GameHelper::delete_cache_game_row( "scripts.fix_games_timeleft($gid)", $gid );
}
?>
//
koh5_pano
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer