game/_incl_data/crons/clear.php

123 lines
6.1 KiB
PHP
Raw Normal View History

2023-08-07 10:52:16 +00:00
<?php
# Каждую полночь
use Core\Db;
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
/**
* CRON Очистки сервера от ненужной информации
* Действия:
* 1. Очистка чата
* 2. Очистка заявок в поединки
* 3. Очистка заявок в пещеры
* 4. Очистка походов
* */
// ЕБИИИИИИИЧЕСКАЯ СИИИИЛА!!!!! (с) Инс.
// forign_keys! Никто не знает про foreign_keys!
function clearUsersFromDb(array $uidsArray, array $loginsArray)
{
$uids = implode(',', $uidsArray);
$logins = implode(',', $loginsArray);
Db::sql('delete from aaa_znahar where uid in (?)', [$uids]);
Db::sql('delete from actions where uid in (?)', [$uids]);
Db::sql('delete from add_smiles where uid in (?)', [$uids]);
Db::sql('delete from a_com_act where uid in (?)', [$uids]);
Db::sql('delete from bandit where uid in (?)', [$uids]);
Db::sql('delete from bank_alh where uid in (?)', [$uids]);
Db::sql('delete from battle_actions where uid in (?)', [$uids]);
Db::sql('delete from battle_cache where uid in (?)', [$uids]);
Db::sql('delete from battle_last where uid in (?)', [$uids]);
Db::sql('delete from battle_users where uid in (?)', [$uids]);
Db::sql('delete from battle_act where uid1 in (?) or uid2 in (?)', [$uids, $uids]);
Db::sql('delete from battle_stat where uid1 in (?) or uid2 in (?)', [$uids, $uids]);
Db::sql('delete from bs_actions where uid in (?)', [$uids]);
Db::sql('delete from bs_zv where uid in (?)', [$uids]);
Db::sql('delete from building where uid in (?)', [$uids]);
Db::sql('delete from complects_priem where uid in (?)', [$uids]);
Db::sql('delete from dialog_act where uid in (?)', [$uids]);
Db::sql('delete from dump where uid in (?)', [$uids]);
Db::sql('delete from dungeon_actions where uid in (?)', [$uids]);
Db::sql('delete from eff_users where uid in (?)', [$uids]);
Db::sql('delete from ekr_sale where uid in (?)', [$uids]);
Db::sql('delete from feerverks where uid in (?)', [$uids]);
Db::sql('delete from fontan where uid in (?)', [$uids]);
Db::sql('delete from fontan_hp where uid in (?)', [$uids]);
Db::sql('delete from fontan_text where uid in (?)', [$uids]);
Db::sql('delete from friends where user in (?) or friend in (?) or enemy in (?) or notinlist in (?) or ignor in (?) or login_ignor in (?) or user_ignor in (?)',
[$uids, $uids, $uids, $uids, $uids, $logins, $logins]);
Db::sql('delete from house where owner in (?)', [$uids]);
Db::sql('delete from items_img where uid in (?)', [$uids]);
Db::sql('delete from items_users where uid in (?)', [$uids]);
Db::sql('delete from izlom_rating where uid in (?)', [$uids]);
Db::sql('delete from laba_act where uid in (?)', [$uids]);
Db::sql('delete from laba_itm where uid in (?)', [$uids]);
Db::sql('delete from lastnames where uid in (?)', [$uids]);
Db::sql('delete from logs_auth where uid in (?)', [$uids]);
Db::sql('delete from loto_win where uid in (?)', [$uids]);
Db::sql('delete from mults where uid in (?) or uid2 in (?)', [$uids, $uids]);
Db::sql('delete from notepad where uid in (?)', [$uids]);
Db::sql('delete from obraz where uid in (?) or login in (?)', [$uids, $logins]);
Db::sql('delete from online where uid in (?)', [$uids]);
Db::sql('delete from pirogi where uid in (?)', [$uids]);
Db::sql('delete from reimage where uid in (?)', [$uids]);
Db::sql('delete from rep where id in (?)', [$uids]);
Db::sql('delete from repass where uid in (?)', [$uids]);
Db::sql('delete from ruletka_coin where uid in (?)', [$uids]);
Db::sql('delete from save_com where uid in (?)', [$uids]);
Db::sql('delete from stats where id in (?)', [$uids]);
Db::sql('delete from transfers where uid1 in (?) or uid2 in (?)', [$uids, $uids]);
Db::sql('delete from users where id in (?)', [$uids]);
Db::sql('delete from users_delo where uid in (?)', [$uids]);
Db::sql('delete from users_animal where uid in (?)', [$uids]);
Db::sql('delete from users_gifts where uid in (?)', [$uids]);
Db::sql('delete from users_ico where uid in (?)', [$uids]);
Db::sql('delete from users_reputation where user_id in (?)', [$uids]);
Db::sql('delete from users_turnirs where uid in (?)', [$uids]);
Db::sql('delete from users_twink where uid in (?)', [$uids]);
Db::sql('delete from zayvki where creator in (?)', [$uids]);
}
//1. Очистка чата, остается чат только за последние 3 дня
//Db::sql('delete from chat where time < unix_timestamp() - 86400 * 3');
//2. Очистка заявок в поединки
Db::sql('delete from zayvki where start > 0 or cancel > 0 or time < unix_timestamp() - 86400');
//3. Очистка заявок в пещеры
Db::sql('delete from dungeon_zv where `delete` > 0 or time < unix_timestamp() - 86400');
//4. Очистка походов
$idsArr = Db::getColumn('select id from dungeon_now where time_start < unix_timestamp() - 86400 or time_finish > 0');
$idsStr = implode(',', $idsArr);
Db::sql('delete from dungeon_actions where dn in (?)', [$idsStr]);
Db::sql('delete from dungeon_bots where dn in (?)', [$idsStr]);
Db::sql('delete from dungeon_items where dn in (?)', [$idsStr]);
Db::sql('delete from dungeon_obj where dn in (?)', [$idsStr]);
Db::sql('delete from dungeon_now where id in (?)', [$idsStr]);
//5. Очистка монстров
$botuids = [];
$botlogins = [];
$bots = Db::getRows('select users.id, login
from users
left join battle on users.battle = battle.id
where `real` = 0 and battle.id = 0 and team_win >= 0 and not exists(select 1 from users where inUser = users.id) order by id');
foreach ($bots as $bot) {
$botuids[] = $bot['id'];
$botlogins[] = $bot['login'];
}
clearUsersFromDb($botuids, $botlogins);
Db::sql('delete from stats where id not in (select id from users)');
Db::sql('delete from items_users where `delete` > time_create and `delete` > 0');
//6. Очистка личного дела
//mysql_query('DELETE FROM `users_delo` WHERE `time` < "'.(time()-86400*30).'" LIMIT 1000');