-
Notifications
You must be signed in to change notification settings - Fork 42
Login and Sessions
This document describes how to get or create Minecraft sessions using CmlLib.Core.
To connect to online-mode server, you should obtain player's session data. The game session data contains player's username, UUID, and accessToken.
There are some ways to obtain game session using this library:
- Mojang Login
- Microsoft Xbox Login
- Offline Login
This library provides some classes related game session and login process:
-
MLogin
class provides methods to communicate with the Mojang auth server. -
MLoginResult
class represents login result. Methods inMLogin
class return this object. -
MSession
class represents player's session data, containingUsername
,UUID
, andAccessToken
.
After obtaining a session data, you should set the MLaunchOption.Session property to an MSession
instance.
Note: this document will help you to understand basic process of minecraft login.
The basic login process is:
PremiumLogin() in CmlLibCoreSample
var login = new MLogin();
// TryAutoLogin() reads the login cache file and check validation.
// If the cached session is invalid, it refreshes the session automatically.
// Refreshing the session doesn't always succeed, so you have to handle this.
Console.WriteLine("Attempting to automatically log in.");
var response = login.TryAutoLogin();
if (!response.IsSuccess) // if cached session is invalid and failed to refresh token
{
Console.WriteLine("Auto login failed: {0}", response.Result.ToString());
Console.WriteLine("Input your Mojang email: ");
var email = Console.ReadLine();
Console.WriteLine("Input your Mojang password: ");
var pw = Console.ReadLine();
response = login.Authenticate(email, pw);
if (!response.IsSuccess)
{
// session.Message contains a detailed error message. It can be null or an empty string.
Console.WriteLine("failed to login. {0} : {1}", response.Result.ToString(), response.ErrorMessage);
Console.ReadLine();
Environment.Exit(0);
}
}
// The result Session
MSession session = response.Session;
// var launchOption = new MLaunchOption()
// {
// Session = session,
// // launch options
// };
go to Microsoft Xbox Login
This session cannot be used in online-mode server or realm.
MSession session = MSession.GetOfflineSession("username");
MSession session = new MSession("username", "accesstoken", "uuid");
Provides methods to communicate with the Mojang auth server and cache game session.
All methods return MLoginResponse. You can get the result of login and result session from MLoginResponse
.
This class fully implments Yggdrasil authentication scheme.
Initialize object with default login cache file path.
Default path : Path.Combine(MinecraftPath.GetOSDefaultPath(), "logintoken.json")
Initializes object and sets SessionCacheFilePath
.
Type: string
SessionCacheFilePath
Save session data to SessionCacheFilePath
if this true.
Default value is true.
Returns session from cache file.
Login with Mojang email and password, with cached clientToken.
Login with Mojang email and password.
Checks validation of cached session and refresh session if it is not valid session.
Checks validation of the specified session and refresh session if it is not valid session.
Refresh session using cached session.
Refresh the specified session.
Validate session with cached session.
Validate the specified session.
Delete cached session file. This is the easiest way to logout.
Logout with cached session file.
Logout the specified session.
Logout using Mojang email and password.
Represents a Minecraft session.
Creates an empty session.
Creates an MSession with the specified Username, AccessToken, and UUID properties.
Type: string
Type: string
Type: string
Type: string
Return true if Username
, AccessToken
, UUID
is not null or empty.
Creates a new MSession and returns it.
Username=username
, AccessToken="access_token"
, UUID="user_uuid"
Indicates the login response.
Type: bool
Returns true if Result
is MLoginResult.Success
.
Type: MLoginResult
Login Result. If this property is not MLoginResult.Success
, then Session
will be null.
Type: MSession
Result session.
Type: string
Error message. It is set when the Result
property is not MLoginResult.Success
. This property can be empty or a null string when the login result is not successful.
Indicates the login result.
Login successful.
User doesn't purchase minecraft.