|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace eXpansion\Framework\GameManiaplanet\DataProviders; |
|
5
|
|
|
|
|
6
|
|
|
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\CompatibilityCheckDataProviderInterface; |
|
8
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
9
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
10
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException; |
|
11
|
|
|
use Psr\Log\LoggerInterface; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class ScriptApiVersionSetterDataProvider |
|
16
|
|
|
* |
|
17
|
|
|
* @package eXpansion\Framework\GameManiaplanet\DataProviders; |
|
18
|
|
|
* @author oliver de Cramer <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class ScriptApiVersionSetterDataProvider extends AbstractDataProvider implements CompatibilityCheckDataProviderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var Connection */ |
|
23
|
|
|
protected $connection; |
|
24
|
|
|
|
|
25
|
|
|
/** @var LoggerInterface */ |
|
26
|
|
|
protected $logger; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $apiVersion; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* ScriptApiVersionSetterDataProvider constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Connection $connection |
|
35
|
|
|
* @param LoggerInterface $logger |
|
36
|
|
|
* @param string $apiVersion |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(Connection $connection, LoggerInterface $logger, string $apiVersion = '2.4.0') |
|
39
|
|
|
{ |
|
40
|
|
|
$this->connection = $connection; |
|
41
|
|
|
$this->logger = $logger; |
|
42
|
|
|
$this->apiVersion = $apiVersion; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @inheritdoc |
|
48
|
|
|
*/ |
|
49
|
|
|
public function isCompatible(Map $map): bool |
|
50
|
|
|
{ |
|
51
|
|
|
try { |
|
52
|
|
|
$this->connection->triggerModeScriptEvent("XmlRpc.SetApiVersion", [$this->apiVersion]); |
|
53
|
|
|
return true; |
|
54
|
|
|
} catch (FaultException $e) { |
|
55
|
|
|
$this->logger->warning( |
|
56
|
|
|
"Can't set script api version. This might be normal if you are using a custom script.", |
|
57
|
|
|
['exception' => $e->getMessage(), 'trace' => $e->getTraceAsString()] |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return true; |
|
62
|
|
|
} |
|
63
|
|
|
} |