1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Dedipanel project |
5
|
|
|
* |
6
|
|
|
* (c) 2010-2015 Dedipanel <http://www.dedicated-panel.net> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DP\GameServer\SteamServerBundle\Listener; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\Event\PreUpdateEventArgs; |
15
|
|
|
use DP\GameServer\SteamServerBundle\Entity\SteamServer; |
16
|
|
|
use DP\Core\MachineBundle\Entity\Machine; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Albin Kerouanton |
20
|
|
|
*/ |
21
|
|
|
class ConfigModifier |
22
|
|
|
{ |
23
|
|
|
protected $container; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set service container |
27
|
|
|
* |
28
|
|
|
* @param ServiceContainer $container |
29
|
|
|
*/ |
30
|
|
|
public function setServiceContainer($container) |
31
|
|
|
{ |
32
|
|
|
$this->container = $container; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get steam query service |
37
|
|
|
* |
38
|
|
|
* @return Twig_Environment |
39
|
|
|
* @throws Exception |
40
|
|
|
*/ |
41
|
|
|
protected function getTwig() |
42
|
|
|
{ |
43
|
|
|
if (is_null($this->container)) { |
44
|
|
|
throw new Exception('The service container is not yet set.'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->container->get('twig'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Maj des scripts du serveur si la config du serveur (port, maxplayers, dir) a été modifié |
52
|
|
|
* Ou si la config du jeu (bin, binDir, launchName, map, orangebox, source) a été modifié |
53
|
|
|
* Ou si l'IP publique de la machine a été modifié |
54
|
|
|
* |
55
|
|
|
* Réinstallation du serveur |
56
|
|
|
* Si des modifs ont été faites sur la machine (IP privée, home, user) |
57
|
|
|
* Ou si le serveur de jeu n'est plus sur la meme machine |
58
|
|
|
* Ou si le jeu du serveur est modifié |
59
|
|
|
* |
60
|
|
|
* @param \Doctrine\ORM\Event\PreUpdateEventArgs $args |
61
|
|
|
*/ |
62
|
|
|
public function preUpdate(PreUpdateEventArgs $args) |
63
|
|
|
{ |
64
|
|
|
$entity = $args->getEntity(); |
65
|
|
|
|
66
|
|
|
if ($entity instanceof SteamServer) { |
67
|
|
|
if ($args->hasChangedField('port') |
68
|
|
|
|| ($args->hasChangedField('maxplayers') && $entity->getGame()->getLaunchName() != "csgo") |
69
|
|
|
|| $args->hasChangedField('core') || $args->hasChangedField('mode')) { |
70
|
|
|
try { |
71
|
|
|
$entity->uploadHldsScript($this->getTwig()); |
72
|
|
|
} |
73
|
|
|
catch (\Exception $e) {} |
74
|
|
|
} |
75
|
|
|
if ($args->hasChangedField('maxplayers') && $entity->getGame()->getLaunchName() == "csgo") { |
76
|
|
|
try { |
77
|
|
|
$entity->modifyGameModesCfg(); |
78
|
|
|
} |
79
|
|
|
catch (\Exception $e) {} |
80
|
|
|
} |
81
|
|
|
if ($args->hasChangedField('dir')) { |
82
|
|
|
try { |
83
|
|
|
$entity->uploadShellScripts($this->getTwig()); |
84
|
|
|
} |
85
|
|
|
catch (\Exception $e) {} |
86
|
|
|
} |
87
|
|
|
if ($args->hasChangedField('rebootAt')) { |
88
|
|
|
//suppression del'ancienne tâche cron |
89
|
|
|
$entity->removeAutoReboot($args->getOldValue('rebootAt')); |
90
|
|
|
|
91
|
|
|
if ($args->getNewValue('rebootAt') != null) { |
92
|
|
|
$entity->addAutoReboot(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
if ($args->hasChangedField('name') || $args->hasChangedField('rconPassword')) { |
96
|
|
|
try { |
97
|
|
|
$entity->modifyServerCfgFile(); |
98
|
|
|
} |
99
|
|
|
catch (\Exception $e) {} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
elseif ($entity instanceof Machine) { |
103
|
|
|
// Upload des scripts si l'IP publique ou le home de la machine a été modifié |
104
|
|
|
if ($args->hasChangedField('publicIp') || $args->hasChangedField('home')) { |
105
|
|
|
$servers = $entity->getGameServers(); |
106
|
|
|
|
107
|
|
|
foreach ($servers AS $server) { |
108
|
|
|
if (!$server instanceof SteamServer) continue; |
109
|
|
|
|
110
|
|
|
try { |
111
|
|
|
$server->uploadShellScripts($this->getTwig()); |
112
|
|
|
} |
113
|
|
|
catch (\Exception $e) {} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|