$tms=mysql_query('select b.id, max(m.movie_time) last_turn, b.timeout from (battle_movie m, battle_request b) where b.id=m.battle_id and b.id="'.$User['current_battle_id'].'" group by b.id');
$tim=mysql_fetch_array($tms);
if(time()>($tim['last_turn']+$tim['timeout']*60)) {
if(checkAdmin()) {
$rs=mysql_query('select nick from users where current_battle_id='.$User['current_battle_id']);
while($r=mysql_fetch_array($rs)) add_private_system_message('Ничья. Бой завершён по таймауту', $r['nick']);
mysql_query('update users set current_battle_id=0 where current_battle_id='.$User['current_battle_id']);
mysql_query('delete from user_in_battle where battle_id='.$User['current_battle_id']);
mysql_query('delete from battle_request where id='.$User['current_battle_id']);
mysql_query('delete from battle_movie where battle_id='.$User['current_battle_id']);
}
}