1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Asylamba\Modules\Hephaistos\Routine; |
4
|
|
|
|
5
|
|
|
use Asylamba\Classes\Entity\EntityManager; |
6
|
|
|
|
7
|
|
|
use Asylamba\Modules\Zeus\Manager\PlayerManager; |
8
|
|
|
|
9
|
|
|
use Asylamba\Classes\Worker\API; |
10
|
|
|
|
11
|
|
|
use Asylamba\Modules\Hermes\Model\Notification; |
12
|
|
|
use Asylamba\Modules\Zeus\Model\Player; |
13
|
|
|
|
14
|
|
|
use Asylamba\Classes\Library\Utils; |
15
|
|
|
|
16
|
|
|
class DailyRoutine |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param EntityManager $entityManager |
20
|
|
|
* @param API $api |
21
|
|
|
* @param string $apimode |
22
|
|
|
* @param PlayerManager $playerManager |
23
|
|
|
* @param int $playerInactiveTimeLimit |
24
|
|
|
* @param int $playerGlobalInactiveTime |
25
|
|
|
* @param int $readTimeout |
26
|
|
|
* @param int $unreadTimeout |
27
|
|
|
*/ |
28
|
|
|
public function execute( |
29
|
|
|
EntityManager $entityManager, |
30
|
|
|
API $api, |
31
|
|
|
$apimode, |
32
|
|
|
PlayerManager $playerManager, |
33
|
|
|
$playerInactiveTimeLimit, |
34
|
|
|
$playerGlobalInactiveTime, |
35
|
|
|
$readTimeout, |
36
|
|
|
$unreadTimeout |
37
|
|
|
) |
38
|
|
|
{ |
|
|
|
|
39
|
|
|
$entityManager->getRepository(Notification::class)->cleanNotifications($readTimeout, $unreadTimeout); |
|
|
|
|
40
|
|
|
|
41
|
|
|
$players = $playerManager->getByStatements([Player::ACTIVE, Player::INACTIVE]); |
42
|
|
|
$nbPlayers = count($players); |
43
|
|
|
// @TODO understand this strange loop condition |
44
|
|
|
for ($i = $nbPlayers - 1; $i >= 0; $i--) { |
45
|
|
|
$player = $players[$i]; |
46
|
|
|
if (Utils::interval(Utils::now(), $player->getDLastConnection()) >= $playerInactiveTimeLimit) { |
|
|
|
|
47
|
|
|
|
48
|
|
|
$playerManager->kill($player->id); |
49
|
|
|
} elseif (Utils::interval(Utils::now(), $player->getDLastConnection()) >= $playerGlobalInactiveTime AND $player->statement == Player::ACTIVE) { |
|
|
|
|
50
|
|
|
$player->statement = Player::INACTIVE; |
51
|
|
|
|
52
|
|
|
if ($apimode === 'enabled') { |
53
|
|
|
# sending email API call |
54
|
|
|
$api->sendMail($player->bind, API::TEMPLATE_INACTIVE_PLAYER); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
$entityManager->flush(Player::class); |
59
|
|
|
} |
60
|
|
|
} |