|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Control; |
|
4
|
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
|
|
6
|
|
|
use request; |
|
7
|
|
|
use Stu\Lib\AccountNotVerifiedException; |
|
8
|
|
|
use Stu\Module\Config\StuConfigInterface; |
|
9
|
|
|
use Stu\Module\PlayerSetting\Lib\UserEnum; |
|
|
|
|
|
|
10
|
|
|
use Stu\Orm\Repository\SessionStringRepositoryInterface; |
|
11
|
|
|
|
|
12
|
|
|
class AccessCheck implements AccessCheckInterface |
|
13
|
|
|
{ |
|
14
|
17 |
|
public function __construct( |
|
15
|
|
|
private readonly SessionStringRepositoryInterface $sessionStringRepository, |
|
16
|
|
|
private readonly StuConfigInterface $stuConfig |
|
17
|
17 |
|
) {} |
|
18
|
|
|
|
|
19
|
15 |
|
#[Override] |
|
20
|
|
|
public function checkUserAccess( |
|
21
|
|
|
ControllerInterface $controller, |
|
22
|
|
|
GameControllerInterface $game |
|
23
|
|
|
): bool { |
|
24
|
|
|
|
|
25
|
15 |
|
if ($controller instanceof NoAccessCheckControllerInterface) { |
|
26
|
1 |
|
return true; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
14 |
|
$hasUser = $game->hasUser(); |
|
30
|
14 |
|
if ($hasUser && $game->getUser()->getState() === UserEnum::USER_STATE_ACCOUNT_VERIFICATION) { |
|
31
|
1 |
|
throw new AccountNotVerifiedException(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
13 |
|
if (!$this->isSessionValid($controller, $hasUser, $game)) { |
|
35
|
3 |
|
return false; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
10 |
|
if (!$controller instanceof AccessCheckControllerInterface) { |
|
39
|
4 |
|
return true; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
6 |
|
$feature = $controller->getFeatureIdentifier(); |
|
43
|
6 |
|
if ($hasUser && $this->isFeatureGranted($game->getUser()->getId(), $feature, $game)) { |
|
44
|
2 |
|
return true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
$game->addInformation('[b][color=#ff2626]Aktion nicht möglich, Spieler ist nicht berechtigt![/color][/b]'); |
|
48
|
|
|
|
|
49
|
4 |
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
13 |
|
private function isSessionValid( |
|
53
|
|
|
ControllerInterface $controller, |
|
54
|
|
|
bool $hasUser, |
|
55
|
|
|
GameControllerInterface $game |
|
56
|
|
|
): bool { |
|
57
|
|
|
|
|
58
|
13 |
|
if (!$controller instanceof ActionControllerInterface) { |
|
59
|
7 |
|
return true; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
6 |
|
if (!$controller->performSessionCheck()) { |
|
63
|
2 |
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
4 |
|
$sessionString = request::indString('sstr'); |
|
67
|
4 |
|
if (!$sessionString) { |
|
|
|
|
|
|
68
|
2 |
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
2 |
|
if (!$hasUser) { |
|
72
|
1 |
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
return $this->sessionStringRepository->isValid( |
|
76
|
1 |
|
$sessionString, |
|
77
|
1 |
|
$game->getUser()->getId() |
|
78
|
1 |
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
7 |
|
#[Override] |
|
82
|
|
|
public function isFeatureGranted(int $userId, AccessGrantedFeatureEnum $feature, GameControllerInterface $game): bool |
|
83
|
|
|
{ |
|
84
|
7 |
|
if ($game->isAdmin()) { |
|
85
|
1 |
|
return true; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
6 |
|
$grantedFeatures = $this->stuConfig->getGameSettings()->getGrantedFeatures(); |
|
89
|
6 |
|
foreach ($grantedFeatures as $entry) { |
|
90
|
|
|
if ( |
|
91
|
5 |
|
$entry['feature'] === $feature->name |
|
|
|
|
|
|
92
|
5 |
|
&& in_array($userId, $entry['userIds']) |
|
93
|
|
|
) { |
|
94
|
1 |
|
return true; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
5 |
|
return false; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths