Search in sources :

Example 1 with ServerInfo

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

the class AddServerPopup method initialise.

@Override
public void initialise() {
    nameText = find("name", UIText.class);
    ownerText = find("owner", UIText.class);
    addressText = find("address", UIText.class);
    portText = find("port", UIText.class);
    okButton = find("ok", UIButton.class);
    cancelButton = find("cancel", UIButton.class);
    tip = find("tip", UILabel.class);
    okButton.subscribe(button -> {
        String name = nameText.getText();
        String owner = ownerText.getText();
        String address = addressText.getText();
        Integer portBoxed = Ints.tryParse(portText.getText());
        int port = (portBoxed != null) ? portBoxed : TerasologyConstants.DEFAULT_PORT;
        if (serverInfo == null) {
            // create new
            serverInfo = new ServerInfo(name, address, port);
            serverInfo.setOwner(owner);
        } else {
            // update existing
            serverInfo.setName(name);
            serverInfo.setAddress(address);
            serverInfo.setPort(port);
            serverInfo.setOwner(owner);
        }
        if (successFunc != null) {
            successFunc.accept(serverInfo);
        }
        getManager().popScreen();
    });
    okButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return !nameText.getText().isEmpty() && !addressText.getText().isEmpty() && Ints.tryParse(portText.getText()) != null;
        }
    });
    cancelButton.subscribe(button -> getManager().popScreen());
    // copy name to address on ENTER if address is empty
    nameText.subscribe(widget -> {
        if (addressText.getText().isEmpty()) {
            addressText.setText(nameText.getText());
            addressText.setCursorPosition(addressText.getText().length());
        }
        getManager().setFocus(addressText);
    });
    // simulate tabbing behavior
    // TODO: replace with NUI tabbing, once available
    addressText.subscribe(widget -> {
        getManager().setFocus(portText);
    });
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) ServerInfo(org.terasology.config.ServerInfo) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIText(org.terasology.rendering.nui.widgets.UIText)

Example 2 with ServerInfo

use of org.terasology.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;
    };
    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;
    };
    WidgetUtil.trySubscribe(this, "onlineButton", activateOnline);
    bindCustomButtons();
    bindInfoLabels();
    WidgetUtil.trySubscribe(this, "close", button -> {
        config.save();
        triggerBackAnimation();
    });
    activateOnline.onActivated(null);
}
Also used : CoreScreenLayer(org.terasology.rendering.nui.CoreScreenLayer) BindHelper(org.terasology.rendering.nui.databinding.BindHelper) CardLayout(org.terasology.rendering.nui.layouts.CardLayout) LoggerFactory(org.slf4j.LoggerFactory) ServerInfoMessage(org.terasology.network.ServerInfoMessage) IntToStringBinding(org.terasology.rendering.nui.databinding.IntToStringBinding) StringTextRenderer(org.terasology.rendering.nui.itemRendering.StringTextRenderer) Collections2(com.google.common.collect.Collections2) Config(org.terasology.config.Config) WorldTime(org.terasology.world.time.WorldTime) StateLoading(org.terasology.engine.modes.StateLoading) Future(java.util.concurrent.Future) PingService(org.terasology.network.PingService) Map(java.util.Map) WidgetUtil(org.terasology.rendering.nui.WidgetUtil) ServerInfo(org.terasology.config.ServerInfo) FontColor(org.terasology.rendering.FontColor) List(java.util.List) Predicate(com.google.common.base.Predicate) ResourceUrn(org.terasology.assets.ResourceUrn) In(org.terasology.registry.In) Joiner(com.google.common.base.Joiner) ReadOnlyBinding(org.terasology.rendering.nui.databinding.ReadOnlyBinding) MenuAnimationSystems(org.terasology.rendering.nui.animation.MenuAnimationSystems) GameEngine(org.terasology.engine.GameEngine) GameThread(org.terasology.engine.GameThread) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) ServerInfoService(org.terasology.network.ServerInfoService) ModuleRegistry(org.terasology.module.ModuleRegistry) TranslationSystem(org.terasology.i18n.TranslationSystem) NameVersion(org.terasology.naming.NameVersion) UIList(org.terasology.rendering.nui.widgets.UIList) ModuleManager(org.terasology.engine.module.ModuleManager) Logger(org.slf4j.Logger) JoinStatus(org.terasology.network.JoinStatus) Keyboard(org.terasology.input.Keyboard) IOException(java.io.IOException) UILabel(org.terasology.rendering.nui.widgets.UILabel) ExecutionException(java.util.concurrent.ExecutionException) ActivateEventListener(org.terasology.rendering.nui.widgets.ActivateEventListener) NUIKeyEvent(org.terasology.rendering.nui.events.NUIKeyEvent) StorageServiceWorker(org.terasology.identity.storageServiceClient.StorageServiceWorker) Color(org.terasology.rendering.nui.Color) UIButton(org.terasology.rendering.nui.widgets.UIButton) WorldInfo(org.terasology.world.internal.WorldInfo) NetworkSystem(org.terasology.network.NetworkSystem) Collections(java.util.Collections) CardLayout(org.terasology.rendering.nui.layouts.CardLayout) ActivateEventListener(org.terasology.rendering.nui.widgets.ActivateEventListener) ServerInfo(org.terasology.config.ServerInfo)

Example 3 with ServerInfo

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

the class JoinGameScreen method refresh.

public void refresh() {
    ServerInfo i = visibleList.getSelection();
    visibleList.setSelection(null);
    extInfo.clear();
    visibleList.setSelection(i);
}
Also used : ServerInfo(org.terasology.config.ServerInfo)

Example 4 with ServerInfo

use of org.terasology.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.config.ServerInfo) TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender) AddServerPopup(org.terasology.rendering.nui.layers.mainMenu.AddServerPopup) URL(java.net.URL) TelemetryConfig(org.terasology.config.TelemetryConfig)

Example 5 with ServerInfo

use of org.terasology.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.config.ServerInfo) AddServerPopup(org.terasology.rendering.nui.layers.mainMenu.AddServerPopup) URL(java.net.URL) TelemetryConfig(org.terasology.config.TelemetryConfig)

Aggregations

ServerInfo (org.terasology.config.ServerInfo)8 UIButton (org.terasology.rendering.nui.widgets.UIButton)4 UILabel (org.terasology.rendering.nui.widgets.UILabel)4 URL (java.net.URL)3 Future (java.util.concurrent.Future)2 TelemetryConfig (org.terasology.config.TelemetryConfig)2 ReadOnlyBinding (org.terasology.rendering.nui.databinding.ReadOnlyBinding)2 AddServerPopup (org.terasology.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