-
Notifications
You must be signed in to change notification settings - Fork 17
API Guide: Login
This API Guide will conclude how to login using mclauncher-api.
To start with any login, you need to get a profile. Either load it or get it from GUI text fields, it's up to you. On this page, I assume you've loaded a profile to profile
variable. Everything you learn on this page is obtaining the Session object.
Minecraft contains 2 login systems. First one is the legacy login and the other one is called yggdrassil. Yggdrassil is newer, so I recommend you use it.
Yggdrassil supports 2 types of logging in:
- Using password
- Using session ID
Session ID usage is however limited, since session IDs expire through time(idk how long is one session), which is why password login always works and session ID login doesn't. However, for both logins, you need to do the same stuff.
YDLoginService loginService = new YDLoginService();
loginService.load(Platform.getCurrentPlatform().getWorkingDirectory());
ISession session = loginService.login(profile);
You should try to perform session ID login first, because it's faster and if it fails, you can do password login. The type of login depends on type of your profile
variable. For LegacyProfile, YDLoginSystem will always do password login and for YDProfile, YDLoginSystem will always do session ID login. If you want to do password based login say from data from a text field, you need to create a LegacyProfile with that username and password and then pass the profile to YDLoginService.login
method.
Also, if you loaded the profile from a file, you will want to overwrite your file with the profile you passed into the login method. That's because your new session ID will be used for next login.
PLEASE NOTE: If you're testing login and actually type your password in .java
source file, please make sure to save the source file as UTF-8
, otherwise you might get a Bad Request
error from Mojang server. I recommend loading your password from a UTF-8 plain text file in case you really want to test like this...
Legacy login with the API is extremely simple. All you need to do is this:
LegacyLoginService loginService = new LegacyLoginService();
ISession session = loginService.login(profile);
-
Find your home - Where is the
.minecraft
folder?
- MinecraftLauncherBackend & GlobalAuthenticationSystem - Logging in, Updating, Running the game
- Login - Logging in with password or session ID
- Profile I/O - Saving/Loading login credentials
- LAN Server Discovery - Discovering servers which are running on LAN
- Loading saved servers - Loading servers from servers.dat