Add support of Socket Host config

This commit is contained in:
Beu 2021-03-14 10:37:47 +01:00
parent fdaa53220c
commit c2b9a41f3d

View File

@ -30,6 +30,7 @@ class CommunicationManager implements CallbackListener, UsageInformationAble {
/** Constants */ /** Constants */
const SETTING_SOCKET_ENABLED = "Activate Socket"; const SETTING_SOCKET_ENABLED = "Activate Socket";
const SETTING_SOCKET_PASSWORD = "Password for the Socket Connection"; const SETTING_SOCKET_PASSWORD = "Password for the Socket Connection";
const SETTING_SOCKET_HOST = "Socket Host for Server ";
const SETTING_SOCKET_PORT = "Socket Port for Server "; const SETTING_SOCKET_PORT = "Socket Port for Server ";
const ENCRYPTION_IV = "kZ2Kt0CzKUjN2MJX"; const ENCRYPTION_IV = "kZ2Kt0CzKUjN2MJX";
@ -191,6 +192,7 @@ class CommunicationManager implements CallbackListener, UsageInformationAble {
$servers = $this->maniaControl->getServer()->getAllServers(); $servers = $this->maniaControl->getServer()->getAllServers();
foreach ($servers as $server) { foreach ($servers as $server) {
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SOCKET_HOST . $server->login, "127.0.0.1");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SOCKET_PORT . $server->login, 31500 + $server->index); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SOCKET_PORT . $server->login, 31500 + $server->index);
} }
@ -239,6 +241,7 @@ class CommunicationManager implements CallbackListener, UsageInformationAble {
} }
$serverLogin = $this->maniaControl->getServer()->login; $serverLogin = $this->maniaControl->getServer()->login;
$socketHost = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SOCKET_HOST . $serverLogin);
$socketPort = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SOCKET_PORT . $serverLogin); $socketPort = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SOCKET_PORT . $serverLogin);
$password = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SOCKET_PASSWORD); $password = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SOCKET_PASSWORD);
@ -293,7 +296,7 @@ class CommunicationManager implements CallbackListener, UsageInformationAble {
}); });
}); });
//TODO check if port is closed //TODO check if port is closed
$this->socket->listen($socketPort, '0.0.0.0'); $this->socket->listen($socketPort, $this->maniaControl->getServer()->ip);
Logger::log("[CommunicationManager] Socket " . $this->maniaControl->getServer()->ip . ":" . $this->socket->getPort() . " Successfully created!"); Logger::log("[CommunicationManager] Socket " . $this->maniaControl->getServer()->ip . ":" . $this->socket->getPort() . " Successfully created!");
} catch (ConnectionException $e) { } catch (ConnectionException $e) {
@ -315,4 +318,4 @@ class CommunicationManager implements CallbackListener, UsageInformationAble {
$communication->tick(); $communication->tick();
} }
} }
} }