Search in sources :

Example 1 with NameVersion

use of org.terasology.gestalt.naming.NameVersion in project Terasology by MovingBlocks.

the class JoinServer method step.

@Override
public boolean step() {
    if (applyModuleThread != null) {
        if (!applyModuleThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.COMPLETE) {
        Server server = networkSystem.getServer();
        ServerInfoMessage serverInfo = networkSystem.getServer().getInfo();
        // If no GameName, use Server IP Address
        if (serverInfo.getGameName().length() > 0) {
            gameManifest.setTitle(serverInfo.getGameName());
        } else {
            gameManifest.setTitle(server.getRemoteAddress());
        }
        for (WorldInfo worldInfo : serverInfo.getWorldInfoList()) {
            gameManifest.addWorld(worldInfo);
        }
        Map<String, Short> blockMap = Maps.newHashMap();
        for (Entry<Integer, String> entry : serverInfo.getBlockIds().entrySet()) {
            String name = entry.getValue();
            short id = entry.getKey().shortValue();
            Short oldId = blockMap.put(name, id);
            if (oldId != null && oldId != id) {
                logger.warn("Overwriting Id {} for {} with Id {}", oldId, name, id);
            }
        }
        gameManifest.setRegisteredBlockFamilies(serverInfo.getRegisterBlockFamilyList());
        gameManifest.setBlockIdMap(blockMap);
        gameManifest.setTime(networkSystem.getServer().getInfo().getTime());
        ModuleManager moduleManager = context.get(ModuleManager.class);
        Set<Module> moduleSet = Sets.newLinkedHashSet();
        for (NameVersion moduleInfo : networkSystem.getServer().getInfo().getModuleList()) {
            Module module = moduleManager.getRegistry().getModule(moduleInfo.getName(), moduleInfo.getVersion());
            if (module == null) {
                StateMainMenu mainMenu = new StateMainMenu("Missing required module: " + moduleInfo);
                context.get(GameEngine.class).changeState(mainMenu);
                return false;
            } else {
                logger.info("Activating module: {}:{}", moduleInfo.getName(), moduleInfo.getVersion());
                gameManifest.addModule(module.getId(), module.getVersion());
                moduleSet.add(module);
            }
        }
        oldEnvironment = moduleManager.getEnvironment();
        moduleManager.loadEnvironment(moduleSet, true);
        context.get(Game.class).load(gameManifest);
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        applyModuleThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
        applyModuleThread.start();
        return false;
    } else if (joinStatus.getStatus() == JoinStatus.Status.FAILED) {
        StateMainMenu mainMenu = new StateMainMenu("Failed to connect to server: " + joinStatus.getErrorMessage());
        context.get(GameEngine.class).changeState(mainMenu);
        networkSystem.shutdown();
    }
    return false;
}
Also used : Set(java.util.Set) Server(org.terasology.engine.network.Server) NameVersion(org.terasology.gestalt.naming.NameVersion) GameEngine(org.terasology.engine.core.GameEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) Entry(java.util.Map.Entry) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) Module(org.terasology.gestalt.module.Module) Map(java.util.Map) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 2 with NameVersion

use of org.terasology.gestalt.naming.NameVersion in project Terasology by MovingBlocks.

the class GameDetailsScreen method loadGameModules.

private void loadGameModules() {
    final List<ModuleSelectionInfo> sortedGameModules = gameInfo.getManifest().getModules().stream().sorted(Comparator.comparing(NameVersion::getName)).map(nameVersion -> {
        Module module = moduleManager.getRegistry().getModule(nameVersion.getName(), nameVersion.getVersion());
        if (module != null) {
            return ModuleSelectionInfo.strictVersion(module);
        } else {
            logger.warn("Can't find module in your classpath - {}:{}", nameVersion.getName(), nameVersion.getVersion());
            module = moduleManager.getRegistry().getLatestModuleVersion(nameVersion.getName());
            if (module != null) {
                logger.debug("Get the latest available version of module {} in your classpath", nameVersion.getName());
                errors.add(String.format("Can't find module %s:%s in your classpath; " + "loaded description for the latest available version.", nameVersion.getName(), nameVersion.getVersion()));
                return ModuleSelectionInfo.latestVersion(module);
            }
            logger.error("Can't find any versions of module {} in your classpath!", nameVersion.getName());
            errors.add(String.format("Can't find any versions of module %s in your classpath!", nameVersion.getName()));
            return ModuleSelectionInfo.unavailableVersion(nameVersion.getName().toString(), nameVersion.getVersion().toString());
        }
    }).filter(Objects::nonNull).collect(Collectors.toList());
    gameModules.setList(sortedGameModules);
    gameModules.select(0);
}
Also used : NameVersion(org.terasology.gestalt.naming.NameVersion) Module(org.terasology.gestalt.module.Module)

Example 3 with NameVersion

use of org.terasology.gestalt.naming.NameVersion in project Terasology by MovingBlocks.

the class JoinGameScreen method getModulesText.

private String getModulesText(Future<ServerInfoMessage> info) {
    try {
        ServerInfoMessage serverInfoMessage = info.get();
        if (serverInfoMessage == null) {
            return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
        }
        List<String> codedModInfo = new ArrayList<>();
        ModuleRegistry reg = moduleManager.getRegistry();
        for (NameVersion entry : serverInfoMessage.getModuleList()) {
            boolean isInstalled = reg.getModule(entry.getName(), entry.getVersion()) != null;
            Color color = isInstalled ? Color.GREEN : Color.RED;
            codedModInfo.add(FontColor.getColored(entry.toString(), color));
        }
        Collections.sort(codedModInfo, String.CASE_INSENSITIVE_ORDER);
        return Joiner.on('\n').join(codedModInfo);
    } catch (ExecutionException | InterruptedException e) {
        return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
    }
}
Also used : NameVersion(org.terasology.gestalt.naming.NameVersion) Color(org.terasology.nui.Color) FontColor(org.terasology.nui.FontColor) ArrayList(java.util.ArrayList) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with NameVersion

use of org.terasology.gestalt.naming.NameVersion in project Terasology by MovingBlocks.

the class ServerInfoMessageImpl method getModuleList.

@Override
public List<NameVersion> getModuleList() {
    List<NameVersion> result = Lists.newArrayList();
    for (NetData.ModuleInfo moduleInfo : info.getModuleList()) {
        if (!moduleInfo.hasModuleId() || !moduleInfo.hasModuleVersion()) {
            logger.error("Received incomplete module info");
        } else {
            Name id = new Name(moduleInfo.getModuleId());
            Version version = new Version(moduleInfo.getModuleVersion());
            result.add(new NameVersion(id, version));
        }
    }
    return result;
}
Also used : NameVersion(org.terasology.gestalt.naming.NameVersion) NetData(org.terasology.protobuf.NetData) Version(org.terasology.gestalt.naming.Version) NameVersion(org.terasology.gestalt.naming.NameVersion) Name(org.terasology.gestalt.naming.Name)

Aggregations

NameVersion (org.terasology.gestalt.naming.NameVersion)4 ServerInfoMessage (org.terasology.engine.network.ServerInfoMessage)2 Module (org.terasology.gestalt.module.Module)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 GameEngine (org.terasology.engine.core.GameEngine)1 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)1 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 Server (org.terasology.engine.network.Server)1 WorldInfo (org.terasology.engine.world.internal.WorldInfo)1 ModuleRegistry (org.terasology.gestalt.module.ModuleRegistry)1 Name (org.terasology.gestalt.naming.Name)1 Version (org.terasology.gestalt.naming.Version)1 Color (org.terasology.nui.Color)1 FontColor (org.terasology.nui.FontColor)1 NetData (org.terasology.protobuf.NetData)1