Search in sources :

Example 1 with ServerInfo

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

the class JoinGameScreen method bindCustomButtons.

private void bindCustomButtons() {
    UIList<?> customServerList = find("customServerList", UIList.class);
    ReadOnlyBinding<Boolean> localSelectedServerOnly = new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return customServerList.getSelection() != null;
        }
    };
    UIButton add = find("add", UIButton.class);
    if (add != null) {
        add.subscribe(button -> {
            AddServerPopup popup = getManager().pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
            // select the entry if added successfully
            popup.onSuccess(item -> {
                config.getNetwork().addServerInfo(item);
                visibleList.setSelection(item);
            });
        });
    }
    UIButton edit = find("edit", UIButton.class);
    if (edit != null) {
        edit.bindEnabled(localSelectedServerOnly);
        edit.subscribe(button -> {
            AddServerPopup popup = getManager().pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
            ServerInfo info = visibleList.getSelection();
            popup.setServerInfo(info);
            // editing invalidates the currently known info, so query it again
            popup.onSuccess(item -> extInfo.put(item, infoService.requestInfo(item.getAddress(), item.getPort())));
        });
    }
    UIButton removeButton = find("remove", UIButton.class);
    if (removeButton != null) {
        removeButton.bindEnabled(localSelectedServerOnly);
        removeButton.subscribe(button -> {
            ServerInfo info = visibleList.getSelection();
            if (info != null) {
                config.getNetwork().removeServerInfo(info);
                extInfo.remove(info);
                visibleList.setSelection(null);
            }
        });
    }
    UILabel downloadLabel = find("download", UILabel.class);
    if (downloadLabel != null) {
        downloadLabel.bindText(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return translationSystem.translate(downloader.getStatus());
            }
        });
    }
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) ServerInfo(org.terasology.engine.config.ServerInfo) UIButton(org.terasology.nui.widgets.UIButton)

Example 2 with ServerInfo

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

the class JoinGameScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    downloader = new ServerListDownloader(config.getNetwork().getMasterServer());
    CardLayout cards = find("cards", CardLayout.class);
    UIList<ServerInfo> customServerList = find("customServerList", UIList.class);
    if (customServerList != null) {
        customServerList.setList(config.getNetwork().getServerInfos());
        configureServerList(customServerList);
    }
    UIList<ServerInfo> onlineServerList = find("onlineServerList", UIList.class);
    if (onlineServerList != null) {
        onlineServerList.setList(listedServers);
        configureServerList(onlineServerList);
    }
    ActivateEventListener activateCustom = e -> {
        cards.setDisplayedCard("customServerListScrollArea");
        find("customButton", UIButton.class).setFamily("highlight");
        find("onlineButton", UIButton.class).setFamily("default");
        visibleList = customServerList;
        refresh();
    };
    WidgetUtil.trySubscribe(this, "customButton", activateCustom);
    ActivateEventListener activateOnline = e -> {
        cards.setDisplayedCard("onlineServerListScrollArea");
        find("customButton", UIButton.class).setFamily("default");
        find("onlineButton", UIButton.class).setFamily("highlight");
        visibleList = onlineServerList;
        refresh();
    };
    WidgetUtil.trySubscribe(this, "onlineButton", activateOnline);
    bindCustomButtons();
    bindInfoLabels();
    WidgetUtil.trySubscribe(this, "close", button -> {
        config.save();
        triggerBackAnimation();
    });
    activateOnline.onActivated(null);
}
Also used : BindHelper(org.terasology.nui.databinding.BindHelper) In(org.terasology.engine.registry.In) Color(org.terasology.nui.Color) LoggerFactory(org.slf4j.LoggerFactory) StorageServiceWorker(org.terasology.engine.identity.storageServiceClient.StorageServiceWorker) Collections2(com.google.common.collect.Collections2) WidgetUtil(org.terasology.nui.WidgetUtil) WorldInfo(org.terasology.engine.world.internal.WorldInfo) Future(java.util.concurrent.Future) FontColor(org.terasology.nui.FontColor) Map(java.util.Map) StateLoading(org.terasology.engine.core.modes.StateLoading) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) GameEngine(org.terasology.engine.core.GameEngine) CardLayout(org.terasology.nui.layouts.CardLayout) GameThread(org.terasology.engine.core.GameThread) List(java.util.List) Predicate(com.google.common.base.Predicate) NameVersion(org.terasology.gestalt.naming.NameVersion) UIList(org.terasology.nui.widgets.UIList) ServerInfoService(org.terasology.engine.network.ServerInfoService) PlayerConfig(org.terasology.engine.config.PlayerConfig) Joiner(com.google.common.base.Joiner) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) ModuleManager(org.terasology.engine.core.module.ModuleManager) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ServerInfo(org.terasology.engine.config.ServerInfo) IntToStringBinding(org.terasology.nui.databinding.IntToStringBinding) ArrayList(java.util.ArrayList) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) NUIKeyEvent(org.terasology.nui.events.NUIKeyEvent) WorldTime(org.terasology.engine.world.time.WorldTime) PingService(org.terasology.engine.network.PingService) ActivateEventListener(org.terasology.nui.widgets.ActivateEventListener) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) Keyboard(org.terasology.input.Keyboard) IOException(java.io.IOException) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) ExecutionException(java.util.concurrent.ExecutionException) Config(org.terasology.engine.config.Config) UIButton(org.terasology.nui.widgets.UIButton) JoinStatus(org.terasology.engine.network.JoinStatus) NetworkSystem(org.terasology.engine.network.NetworkSystem) Collections(java.util.Collections) CardLayout(org.terasology.nui.layouts.CardLayout) ActivateEventListener(org.terasology.nui.widgets.ActivateEventListener) ServerInfo(org.terasology.engine.config.ServerInfo)

Example 3 with ServerInfo

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

the class TelemetryScreen method pushAddServerPopupAndStartLogBackAppender.

private void pushAddServerPopupAndStartLogBackAppender() {
    AddServerPopup addServerPopup = nuiManager.pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
    addServerPopup.removeTip();
    ServerInfo serverInfo;
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    if (telemetryConfig.getErrorReportingDestination() != null) {
        try {
            URL url = new URL("http://" + telemetryConfig.getErrorReportingDestination());
            serverInfo = new ServerInfo(telemetryConfig.getErrorReportingServerName(), url.getHost(), url.getPort());
            serverInfo.setOwner(telemetryConfig.getErrorReportingServerOwner());
        } catch (Exception e) {
            logger.error("Exception when get telemetry server information", e);
            serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
            serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
        }
    } else {
        serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
        serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
    }
    addServerPopup.setServerInfo(serverInfo);
    addServerPopup.onSuccess((item) -> {
        String destinationLogstash = item.getAddress() + ":" + item.getPort();
        TelemetryLogstashAppender telemetryLogstashAppender = TelemetryUtils.fetchTelemetryLogstashAppender();
        if (telemetryLogstashAppender != null) {
            telemetryLogstashAppender.addDestination(destinationLogstash);
            telemetryLogstashAppender.start();
        }
        // Save the destination
        telemetryConfig.setErrorReportingDestination(destinationLogstash);
        telemetryConfig.setErrorReportingServerName(item.getName());
        telemetryConfig.setErrorReportingServerOwner(item.getOwner());
    });
    addServerPopup.onCancel((button) -> telemetryConfig.setErrorReportingEnabled(false));
}
Also used : ServerInfo(org.terasology.engine.config.ServerInfo) TelemetryLogstashAppender(org.terasology.engine.telemetry.logstash.TelemetryLogstashAppender) AddServerPopup(org.terasology.engine.rendering.nui.layers.mainMenu.AddServerPopup) URL(java.net.URL) TelemetryConfig(org.terasology.engine.config.TelemetryConfig)

Example 4 with ServerInfo

use of org.terasology.engine.config.ServerInfo 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)

Example 5 with ServerInfo

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

the class ServerListDownloader method download.

private void download(String address) throws IOException {
    status = "${engine:menu#downloading-server-list}";
    URL url = new URL("http", address, "/servers/list");
    try (Reader reader = new InputStreamReader(url.openStream(), charset);
        JsonReader jsonReader = new JsonReader(reader)) {
        status = "${engine:menu#parsing-content}";
        jsonReader.beginArray();
        TypeAdapter<ServerInfo> adapter = GSON.getAdapter(ServerInfo.class);
        while (jsonReader.hasNext()) {
            ServerInfo entry = adapter.read(jsonReader);
            servers.add(entry);
            logger.info("Retrieved game server {}", entry);
            try {
                Thread.sleep(250);
            } catch (InterruptedException e) {
            // ignore - this is just to create an animation anyway
            }
        }
        jsonReader.endArray();
        if (servers.size() == 0) {
            status = String.format("Server Error!");
        } else {
            status = String.format("${engine:menu#server-list-complete}");
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ServerInfo(org.terasology.engine.config.ServerInfo) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JsonReader(com.google.gson.stream.JsonReader) JsonReader(com.google.gson.stream.JsonReader) URL(java.net.URL)

Aggregations

ServerInfo (org.terasology.engine.config.ServerInfo)8 UIButton (org.terasology.nui.widgets.UIButton)4 UILabel (org.terasology.nui.widgets.UILabel)4 URL (java.net.URL)3 ReadOnlyBinding (org.terasology.nui.databinding.ReadOnlyBinding)3 Future (java.util.concurrent.Future)2 TelemetryConfig (org.terasology.engine.config.TelemetryConfig)2 AddServerPopup (org.terasology.engine.rendering.nui.layers.mainMenu.AddServerPopup)2 Joiner (com.google.common.base.Joiner)1 Predicate (com.google.common.base.Predicate)1 Collections2 (com.google.common.collect.Collections2)1 JsonReader (com.google.gson.stream.JsonReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1