Search in sources :

Example 6 with TelemetryConfig

use of org.terasology.engine.config.TelemetryConfig in project Terasology by MovingBlocks.

the class TelemetryScreen method pushAddServerPopupAndStartEmitter.

private void pushAddServerPopupAndStartEmitter() {
    AddServerPopup addServerPopup = nuiManager.pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
    addServerPopup.removeTip();
    ServerInfo serverInfo;
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    String telemetryDestination = telemetryConfig.getTelemetryDestination();
    if (telemetryDestination != null) {
        try {
            URL url = new URL(telemetryDestination);
            String address = url.getHost();
            int port = url.getPort();
            serverInfo = new ServerInfo(telemetryConfig.getTelemetryServerName(), address, port);
            serverInfo.setOwner(telemetryConfig.getTelemetryServerOwner());
        } catch (Exception e) {
            logger.error("Exception when get telemetry server information", e);
            serverInfo = new ServerInfo(TelemetryEmitter.DEFAULT_COLLECTOR_NAME, TelemetryEmitter.DEFAULT_COLLECTOR_HOST, TelemetryEmitter.DEFAULT_COLLECTOR_PORT);
            serverInfo.setOwner(TelemetryEmitter.DEFAULT_COLLECTOR_OWNER);
        }
    } else {
        serverInfo = new ServerInfo(TelemetryEmitter.DEFAULT_COLLECTOR_NAME, TelemetryEmitter.DEFAULT_COLLECTOR_HOST, TelemetryEmitter.DEFAULT_COLLECTOR_PORT);
        serverInfo.setOwner(TelemetryEmitter.DEFAULT_COLLECTOR_OWNER);
    }
    addServerPopup.setServerInfo(serverInfo);
    addServerPopup.onSuccess((item) -> {
        TelemetryEmitter telemetryEmitter = (TelemetryEmitter) emitter;
        Optional<URL> optionalURL = item.getURL("http");
        if (optionalURL.isPresent()) {
            telemetryEmitter.changeUrl(optionalURL.get());
            // Save the telemetry destination
            telemetryConfig.setTelemetryDestination(optionalURL.get().toString());
            telemetryConfig.setTelemetryServerName(item.getName());
            telemetryConfig.setTelemetryServerOwner(item.getOwner());
        }
    });
    addServerPopup.onCancel((button) -> config.getTelemetryConfig().setTelemetryEnabled(false));
}
Also used : ServerInfo(org.terasology.engine.config.ServerInfo) AddServerPopup(org.terasology.engine.rendering.nui.layers.mainMenu.AddServerPopup) URL(java.net.URL) TelemetryConfig(org.terasology.engine.config.TelemetryConfig)

Aggregations

TelemetryConfig (org.terasology.engine.config.TelemetryConfig)6 Config (org.terasology.engine.config.Config)4 URL (java.net.URL)3 TelemetryLogstashAppender (org.terasology.engine.telemetry.logstash.TelemetryLogstashAppender)3 ServerInfo (org.terasology.engine.config.ServerInfo)2 AddServerPopup (org.terasology.engine.rendering.nui.layers.mainMenu.AddServerPopup)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 MalformedURLException (java.net.MalformedURLException)1 TelemetryConfiguration (org.terasology.engine.config.facade.TelemetryConfiguration)1 TelemetryConfigurationImpl (org.terasology.engine.config.facade.TelemetryConfigurationImpl)1 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)1 LaunchPopup (org.terasology.engine.rendering.nui.layers.mainMenu.LaunchPopup)1 TelemetryEmitter (org.terasology.engine.telemetry.TelemetryEmitter)1