1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\AdminChat\ChatCommand; |
4
|
|
|
|
5
|
|
|
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups; |
6
|
|
|
use eXpansion\Framework\Core\Helpers\ChatNotification; |
7
|
|
|
use eXpansion\Framework\Core\Helpers\Time; |
8
|
|
|
use eXpansion\Framework\Core\Helpers\TMString; |
9
|
|
|
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory; |
10
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
11
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
12
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception as DedicatedException; |
13
|
|
|
use Psr\Log\LoggerInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class ReasonUserCommand |
19
|
|
|
* |
20
|
|
|
* @author Reaby |
21
|
|
|
* @package eXpansion\Bundle\AdminChat\ChatCommand |
22
|
|
|
*/ |
23
|
|
|
class OneParameterCommand extends AbstractConnectionCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Description of the parameter |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $parameterDescription; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Description of the command. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $description; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Message to display in chat. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $chatMessage; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Name of the dedicated function to call. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $functionName; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* OneParameterCommand constructor. |
55
|
|
|
* |
56
|
|
|
* @param $command |
57
|
|
|
* @param string $permission |
58
|
|
|
* @param array $aliases |
59
|
|
|
* @param string $functionName |
60
|
|
|
* @param string $parameterDescription |
61
|
|
|
* @param AdminGroups $adminGroupsHelper |
62
|
|
|
* @param Connection $connection |
|
|
|
|
63
|
|
|
* @param ChatNotification $chatNotification |
64
|
|
|
* @param PlayerStorage $playerStorage |
65
|
|
|
* @param LoggerInterface $logger |
66
|
|
|
* @param Time $timeHelper |
67
|
|
|
*/ |
68
|
1 |
View Code Duplication |
public function __construct( |
|
|
|
|
69
|
|
|
$command, |
70
|
|
|
$permission, |
71
|
|
|
array $aliases = [], |
72
|
|
|
$functionName, |
73
|
|
|
$parameterDescription, |
74
|
|
|
AdminGroups $adminGroupsHelper, |
75
|
|
|
Factory $factory, |
76
|
|
|
ChatNotification $chatNotification, |
77
|
|
|
PlayerStorage $playerStorage, |
78
|
|
|
LoggerInterface $logger, |
79
|
|
|
Time $timeHelper |
80
|
|
|
) { |
81
|
1 |
|
parent::__construct( |
82
|
1 |
|
$command, |
83
|
|
|
$permission, |
84
|
|
|
$aliases, |
85
|
|
|
$adminGroupsHelper, |
86
|
|
|
$factory, |
87
|
|
|
$chatNotification, |
88
|
|
|
$playerStorage, |
89
|
|
|
$logger, |
90
|
|
|
$timeHelper |
91
|
|
|
); |
92
|
|
|
|
93
|
1 |
|
$this->description = 'expansion_admin_chat.'.strtolower($functionName).'.description'; |
94
|
1 |
|
$this->chatMessage = 'expansion_admin_chat.'.strtolower($functionName).'.msg'; |
95
|
1 |
|
$this->functionName = (string) $functionName; |
96
|
1 |
|
$this->parameterDescription = (string) $parameterDescription; |
97
|
1 |
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
*/ |
103
|
1 |
|
protected function configure() |
104
|
|
|
{ |
105
|
1 |
|
parent::configure(); |
106
|
|
|
|
107
|
1 |
|
$this->inputDefinition->addArgument( |
108
|
1 |
|
new InputArgument('parameter', InputArgument::REQUIRED, $this->parameterDescription) |
109
|
|
|
); |
110
|
1 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritdoc |
114
|
|
|
*/ |
115
|
1 |
View Code Duplication |
public function execute($login, InputInterface $input) |
|
|
|
|
116
|
|
|
{ |
117
|
1 |
|
$nickName = $this->playerStorage->getPlayerInfo($login)->getNickName(); |
118
|
1 |
|
$parameter = $input->getArgument('parameter'); |
119
|
1 |
|
$group = $this->getGroupLabel($login); |
120
|
|
|
try { |
121
|
1 |
|
$this->factory->getConnection()->{$this->functionName}($parameter); |
122
|
1 |
|
$this->chatNotification->sendMessage( |
123
|
1 |
|
$this->chatMessage, |
124
|
1 |
|
$this->isPublic ? null : $login, |
125
|
1 |
|
['%adminLevel%' => $group, '%admin%' => $nickName, "%parameter%" => $parameter] |
126
|
|
|
); |
127
|
|
|
|
128
|
1 |
|
$logMessage = $this->chatNotification->getMessage($this->chatMessage, |
129
|
1 |
|
['%adminLevel%' => $group, '%admin%' => $nickName, "%parameter%" => $parameter], "en"); |
130
|
1 |
|
$this->logger->info("[".$login."] ".TMString::trimStyles($logMessage)); |
131
|
|
|
|
132
|
|
|
} catch (DedicatedException $e) { |
133
|
|
|
$this->logger->error("Error on admin command", ["exception" => $e]); |
134
|
|
|
$this->chatNotification->sendMessage("expansion_admin_chat.dedicatedexception", $login, |
135
|
|
|
["%message%" => $e->getMessage()]); |
136
|
|
|
} |
137
|
|
|
|
138
|
1 |
|
} |
139
|
|
|
} |
140
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.