use of com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService 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;
}
use of com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService in project MinecraftForge by MinecraftForge.
the class Yggdrasil method login.
public static void login(Map<String, String> args) {
if (!args.containsKey("--username") || !args.containsKey("--password"))
return;
YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "1").createUserAuthentication(Agent.MINECRAFT);
auth.setUsername(args.get("--username"));
auth.setPassword(args.remove("--password"));
try {
auth.logIn();
} catch (AuthenticationException e) {
LogManager.getLogger("FMLTWEAK").error("-- Login failed! " + e.getMessage());
Throwables.propagate(e);
// don't set other variables
return;
}
args.put("--username", auth.getSelectedProfile().getName());
args.put("--uuid", auth.getSelectedProfile().getId().toString().replace("-", ""));
args.put("--accessToken", auth.getAuthenticatedToken());
args.put("--userProperties", auth.getUserProperties().toString());
}
use of com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService 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"));
}
use of com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService in project Wurst-MC-1.12 by Wurst-Imperium.
the class LoginManager method login.
public static String login(String email, String password) {
YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "").createUserAuthentication(Agent.MINECRAFT);
auth.setUsername(email);
auth.setPassword(password);
try {
auth.logIn();
Minecraft.getMinecraft().session = new Session(auth.getSelectedProfile().getName(), auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "mojang");
return "";
} catch (AuthenticationUnavailableException e) {
return "�4�lCannot contact authentication server!";
} catch (AuthenticationException e) {
e.printStackTrace();
if (e.getMessage().contains("Invalid username or password.") || e.getMessage().toLowerCase().contains("account migrated"))
return "�4�lWrong password!";
else
return "�4�lCannot contact authentication server!";
} catch (NullPointerException e) {
return "�4�lWrong password!";
}
}
use of com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService 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;
}
Aggregations