game/cron/battle_finish.php

81 lines
3.2 KiB
PHP
Raw Blame History

<?php
const GAME = true;
include('/home/newcom1/public_html/_incl_data/class/__db_connect.php');
/*
CRON Çàâåðøåíèå ïîåäèíêà è óäàëåíèå èç çàÿâîê
*/
$hend = 2; //×åðåç ñêîëüêî ÷àñîâ ïðîâåðÿòü è âðåìÿ áåçäåéñòâèÿ
$sp = mysql_query('SELECT * FROM `battle` WHERE `time_start` < "'.( time() - 1800*$hend ).'" AND `team_win` = -1 LIMIT 100');
while( $pl = mysql_fetch_array($sp) ) {
$test = mysql_fetch_array(mysql_query('SELECT * FROM `battle_logs` WHERE `battle` = "'.$pl['id'].'" ORDER BY `time` DESC LIMIT 1'));
if(!isset($test['id']) || $test['time'] < ( time() - 1800*$hend ) ) {
mysql_query('UPDATE `battle` SET `team_win` = "0",`time_over` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
mysql_query('UPDATE `users` SET `battle` = "0" WHERE `battle` = "'.$pl['id'].'"');
}
}
// <20>àñ÷åò òàéìà â íàïàäåíèßõ
$sp = mysql_query('SELECT * FROM `battle` WHERE `time_start` < "'.( time() - 180).'" AND `team_win` = -1 AND `typeBattle` = 9 LIMIT 100');
while( $pl = mysql_fetch_array($sp) ) {
$test = mysql_fetch_array(mysql_query('SELECT COUNT(`u`.`id`) as count
FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`battle`= "'.$pl['id'].'"'));
if ($test['count'] < 8)
{
mysql_query('UPDATE `battle` SET `timeout` = "60" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
}
elseif ($test['count'] < 12)
{
mysql_query('UPDATE `battle` SET `timeout` = "120" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
} else {
mysql_query('UPDATE `battle` SET `timeout` = "180" WHERE `id` = "' . $pl['id'] . '" LIMIT 1');
}
}
// batle cache
mysql_query('DELETE FROM `battle_cache` WHERE `time` < "'.(time()-3600).'"');
//âûòàñêèâàåì ïåðñîâ èç ïðèç õàîòà åñëè çàñòðßëè (1-5 ìèíóò îêîí÷àíèå)
$sp = mysql_fetch_array(mysql_query('SELECT * FROM `battle` WHERE `type` = 33 AND `time_over` < "'.(time()-120).'" AND `time_over` > "'.(time() - 360).'" AND `time_over` != 0 ORDER BY `battle`.`time_over` DESC LIMIT 1'));
if (isset($sp['id']))
{
mysql_query('UPDATE `battle` SET `time_over` = `time_over` - 300 WHERE `id` = "'.$sp['id'].'" LIMIT 1');
$sps = mysql_query('SELECT * FROM `users` WHERE `mail` LIKE "haot@new-combats.com" AND `battle` = 0');
while( $pl = mysql_fetch_array($sps))
{
if (isset($pl['id']))
{
mysql_query('UPDATE `users` SET `inUser` = "0" WHERE `inUser` = "'.$pl['id'].'" LIMIT 1');
mysql_query('DELETE FROM `users` WHERE `id` = "'.$pl['id'].'" LIMIT 1');
mysql_query('DELETE FROM `stats` WHERE `id` = "'.$pl['id'].'" LIMIT 1');
mysql_query('DELETE FROM `items_users` WHERE `uid` = "'.$pl['id'].'" LIMIT 100');
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "'.$pl['id'].'" LIMIT 100');
}
}
}
//‚ûòàñêèâàåì ïåðñîâ åñëè çàñòðßëè â áîßõ
$sps = mysql_query('SELECT * FROM `users` WHERE `battle` > 0');
while( $pl = mysql_fetch_array($sps))
{
if (isset($pl['id']))
{
$test = mysql_fetch_array(mysql_query('SELECT * FROM `battle` WHERE `id` = "'.$pl['battle'].'" LIMIT 1'));
if (($test['time_over'] < (time()-600) && $test['time_over'] !=0) || !isset($test['id']))
{
mysql_query('UPDATE `users` SET `battle`= 0 WHERE `id` = "'.$pl['id'].'" LIMIT 1');
mysql_query('UPDATE `stats` SET `battle_yron` = 0 WHERE `id` = "'.$pl['id'].'" LIMIT 1');
}
}
}
//÷èñòèì ïàìßòü
unset($sp,$sps,$pl,$test);