Search in sources :

Example 1 with MinecraftSessionService

use of com.mojang.authlib.minecraft.MinecraftSessionService in project SpongeCommon by SpongePowered.

the class MixinPlayerProfileCache method lookupByIds.

@Override
public Map<UUID, Optional<GameProfile>> lookupByIds(Iterable<UUID> uniqueIds) {
    checkNotNull(uniqueIds, "unique ids");
    Map<UUID, Optional<GameProfile>> result = Maps.newHashMap();
    MinecraftSessionService service = SpongeImpl.getServer().getMinecraftSessionService();
    for (UUID uniqueId : uniqueIds) {
        com.mojang.authlib.GameProfile profile = service.fillProfileProperties(new com.mojang.authlib.GameProfile(uniqueId, ""), true);
        if (profile != null && profile.getName() != null && !profile.getName().isEmpty()) {
            this.addEntry(profile, null);
            result.put(uniqueId, Optional.of((GameProfile) profile));
        } else {
            // create a dummy profile to avoid future lookups
            // if actual user logs in, the profile will be updated during PlayerList#initializeConnectionToPlayer
            this.addEntry(new com.mojang.authlib.GameProfile(uniqueId, "[sponge]"), null);
            result.put(uniqueId, Optional.empty());
        }
    }
    return result.isEmpty() ? ImmutableMap.of() : ImmutableMap.copyOf(result);
}
Also used : Optional(java.util.Optional) GameProfile(org.spongepowered.api.profile.GameProfile) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) UUID(java.util.UUID)

Example 2 with MinecraftSessionService

use of com.mojang.authlib.minecraft.MinecraftSessionService in project Citizens2 by CitizensDev.

the class NMSImpl method fillProfileProperties.

@Override
public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Exception {
    if (Bukkit.isPrimaryThread())
        throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread.");
    MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().ay();
    if (!(sessionService instanceof YggdrasilMinecraftSessionService)) {
        return sessionService.fillProfileProperties(profile, requireSecure);
    }
    YggdrasilAuthenticationService auth = ((YggdrasilMinecraftSessionService) sessionService).getAuthenticationService();
    URL url = HttpAuthenticationService.constantURL(getAuthServerBaseUrl() + UUIDTypeAdapter.fromUUID(profile.getId()));
    url = HttpAuthenticationService.concatenateURL(url, "unsigned=" + !requireSecure);
    MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke(auth, url, null, MinecraftProfilePropertiesResponse.class);
    if (response == null)
        return profile;
    GameProfile result = new GameProfile(response.getId(), response.getName());
    result.getProperties().putAll(response.getProperties());
    profile.getProperties().putAll(response.getProperties());
    return result;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) MinecraftProfilePropertiesResponse(com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse) YggdrasilMinecraftSessionService(com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService) YggdrasilMinecraftSessionService(com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) URL(java.net.URL)

Example 3 with MinecraftSessionService

use of com.mojang.authlib.minecraft.MinecraftSessionService in project SpongeVanilla by SpongePowered.

the class SpongeVanilla method start.

private static void start(String[] args) {
    // Attempt to load metadata
    MetadataContainer metadata = MetadataContainer.load();
    // Register Minecraft plugin container
    MinecraftPluginContainer.register();
    OptionSet options = VanillaCommandLine.parse(args);
    // Note: This launches the server instead of MinecraftServer.main
    // Keep command line options up-to-date with Vanilla
    Bootstrap.register();
    File worldDir = options.has(WORLD_DIR) ? options.valueOf(WORLD_DIR) : new File(".");
    YggdrasilAuthenticationService authenticationService = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
    MinecraftSessionService sessionService = authenticationService.createMinecraftSessionService();
    GameProfileRepository profileRepository = authenticationService.createProfileRepository();
    PlayerProfileCache profileCache = new PlayerProfileCache(profileRepository, new File(worldDir, USER_CACHE_FILE.getName()));
    DedicatedServer server = new DedicatedServer(worldDir, DataFixesManager.createFixer(), authenticationService, sessionService, profileRepository, profileCache);
    // We force-load NetHandlerPlayServer here.
    // Otherwise, VanillaChannelRegistrar causes it to be loaded from
    // within the Guice injector (see SpongeVanillaModule), thus swallowing
    // any Mixin exception that occurs.
    // 
    // See https://github.com/SpongePowered/SpongeVanilla/issues/235 for a more
    // in-depth explanation
    NetHandlerPlayServer.class.getName();
    final Stage stage = SpongeGuice.getInjectorStage(VanillaLaunch.ENVIRONMENT == DEVELOPMENT ? Stage.DEVELOPMENT : Stage.PRODUCTION);
    SpongeImpl.getLogger().debug("Creating injector in stage '{}'", stage);
    Guice.createInjector(stage, new SpongeModule(), new SpongeVanillaModule(server, metadata));
    if (options.has(WORLD_NAME)) {
        server.setFolderName(options.valueOf(WORLD_NAME));
    }
    if (options.has(PORT)) {
        server.setServerPort(options.valueOf(PORT));
    }
    if (options.has(BONUS_CHEST)) {
        server.canCreateBonusChest(true);
    }
    server.startServerThread();
    Runtime.getRuntime().addShutdownHook(new Thread(server::stopServer, "Server Shutdown Thread"));
}
Also used : MetadataContainer(org.spongepowered.server.plugin.MetadataContainer) SpongeModule(org.spongepowered.common.inject.SpongeModule) PlayerProfileCache(net.minecraft.server.management.PlayerProfileCache) GameProfileRepository(com.mojang.authlib.GameProfileRepository) Stage(com.google.inject.Stage) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) OptionSet(joptsimple.OptionSet) File(java.io.File) SpongeVanillaModule(org.spongepowered.server.inject.SpongeVanillaModule)

Example 4 with MinecraftSessionService

use of com.mojang.authlib.minecraft.MinecraftSessionService in project Citizens2 by CitizensDev.

the class NMSImpl method fillProfileProperties.

@Override
public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Exception {
    if (Bukkit.isPrimaryThread())
        throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread.");
    MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().aD();
    if (!(sessionService instanceof YggdrasilMinecraftSessionService)) {
        return sessionService.fillProfileProperties(profile, requireSecure);
    }
    YggdrasilAuthenticationService auth = ((YggdrasilMinecraftSessionService) sessionService).getAuthenticationService();
    URL url = HttpAuthenticationService.constantURL(getAuthServerBaseUrl() + UUIDTypeAdapter.fromUUID(profile.getId()));
    url = HttpAuthenticationService.concatenateURL(url, "unsigned=" + !requireSecure);
    MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke(auth, url, null, MinecraftProfilePropertiesResponse.class);
    if (response == null)
        return profile;
    GameProfile result = new GameProfile(response.getId(), response.getName());
    result.getProperties().putAll(response.getProperties());
    profile.getProperties().putAll(response.getProperties());
    return result;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) MinecraftProfilePropertiesResponse(com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse) YggdrasilMinecraftSessionService(com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService) YggdrasilMinecraftSessionService(com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) URL(java.net.URL)

Example 5 with MinecraftSessionService

use of com.mojang.authlib.minecraft.MinecraftSessionService in project Citizens2 by CitizensDev.

the class NMSImpl method fillProfileProperties.

@Override
public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Exception {
    if (Bukkit.isPrimaryThread())
        throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread.");
    MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().az();
    if (!(sessionService instanceof YggdrasilMinecraftSessionService)) {
        return sessionService.fillProfileProperties(profile, requireSecure);
    }
    YggdrasilAuthenticationService auth = ((YggdrasilMinecraftSessionService) sessionService).getAuthenticationService();
    URL url = HttpAuthenticationService.constantURL(getAuthServerBaseUrl() + UUIDTypeAdapter.fromUUID(profile.getId()));
    url = HttpAuthenticationService.concatenateURL(url, "unsigned=" + !requireSecure);
    MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke(auth, url, null, MinecraftProfilePropertiesResponse.class);
    if (response == null)
        return profile;
    GameProfile result = new GameProfile(response.getId(), response.getName());
    result.getProperties().putAll(response.getProperties());
    profile.getProperties().putAll(response.getProperties());
    return result;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) MinecraftProfilePropertiesResponse(com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse) YggdrasilMinecraftSessionService(com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService) YggdrasilMinecraftSessionService(com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) URL(java.net.URL)

Aggregations

MinecraftSessionService (com.mojang.authlib.minecraft.MinecraftSessionService)6 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)5 GameProfile (com.mojang.authlib.GameProfile)4 YggdrasilMinecraftSessionService (com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService)4 MinecraftProfilePropertiesResponse (com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse)4 URL (java.net.URL)4 Stage (com.google.inject.Stage)1 GameProfileRepository (com.mojang.authlib.GameProfileRepository)1 File (java.io.File)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 OptionSet (joptsimple.OptionSet)1 DedicatedServer (net.minecraft.server.dedicated.DedicatedServer)1 PlayerProfileCache (net.minecraft.server.management.PlayerProfileCache)1 GameProfile (org.spongepowered.api.profile.GameProfile)1 SpongeModule (org.spongepowered.common.inject.SpongeModule)1 SpongeVanillaModule (org.spongepowered.server.inject.SpongeVanillaModule)1 MetadataContainer (org.spongepowered.server.plugin.MetadataContainer)1