Skip to content

Commit

Permalink
Fix Login Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
CADIndie committed Nov 5, 2024
1 parent 24350d2 commit 2c18978
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/assets/lwjgl/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1730624021613
1730783037751
13 changes: 7 additions & 6 deletions src/main/java/pojlib/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class API {
public static String memoryValue = "1800";
public static boolean developerMods;
public static MinecraftAccount currentAcc;
public static boolean isDemoMode;
public static MinecraftInstances.Instance currentInstance;

public static boolean advancedDebugger;
Expand Down Expand Up @@ -186,19 +187,19 @@ public static void launchInstance(Activity activity, MinecraftAccount account, M
* Removes the user account
*
* @param activity The base directory where minecraft should be setup
* @param username The username of the profile to remove
* @param uuid The uuid of the profile to remove
* @return True if removal was successful
*/
public static boolean removeAccount(Activity activity, String username) {
return MinecraftAccount.removeAccount(activity, username);
public static boolean removeAccount(Activity activity, String uuid) {
return MinecraftAccount.removeAccount(activity, uuid);
}

/**
* Start the login process
*
* @param activity Android activity object
*/
public static void login(Activity activity, @Nullable String accountName)
public static void login(Activity activity, @Nullable String accountUUID)
{
ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkCapabilities capabilities = connManager.getNetworkCapabilities(connManager.getActiveNetwork());
Expand All @@ -209,15 +210,15 @@ public static void login(Activity activity, @Nullable String accountName)
hasWifi = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
}

MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts", accountName);
MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts", accountUUID);
if(acc != null && (acc.expiresOn >= System.currentTimeMillis() || !hasWifi || acc.isDemoMode)) {
currentAcc = acc;
API.profileImage = MinecraftAccount.getSkinFaceUrl(API.currentAcc);
API.profileName = API.currentAcc.username;
API.profileUUID = API.currentAcc.uuid;
return;
} else if(acc != null && acc.expiresOn < System.currentTimeMillis()) {
currentAcc = LoginHelper.refreshAccount(activity, currentAcc.username);
currentAcc = LoginHelper.refreshAccount(activity, accountUUID);
if(currentAcc == null) {
LoginHelper.login(activity);
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/pojlib/account/Msa.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class Msa {
}

/* Fields used to fill the account */
public static String mcName;
public String mcName;
public String mcToken;
public static String mcUuid;
public String mcUuid;
public static boolean doesOwnGame;
private Activity activity;
private long mcExpiresOn;
Expand All @@ -66,20 +66,22 @@ public MinecraftAccount performLogin(String msToken) throws MSAException {
fetchOwnedItems(mcToken);
checkMcProfile(mcToken);

MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts", mcName);
MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts", mcUuid);
if (acc == null) acc = new MinecraftAccount();
if (doesOwnGame) {
acc.accessToken = mcToken;
acc.username = mcName;
acc.uuid = mcUuid;
acc.expiresOn = mcExpiresOn;
acc.isDemoMode = false;
API.isDemoMode = false;
} else {
acc.accessToken = "0";
acc.username = "Player";
acc.uuid = "00000000-0000-0000-0000-000000000000";
acc.expiresOn = 0;
acc.isDemoMode = true;
API.isDemoMode = true;
}

return acc;
Expand Down Expand Up @@ -204,7 +206,7 @@ private void fetchOwnedItems(String mcAccessToken) throws MSAException, IOExcept
}

// Returns false for failure //
public static boolean checkMcProfile(String mcAccessToken) throws IOException, MSAException, JSONException {
public boolean checkMcProfile(String mcAccessToken) throws IOException, MSAException, JSONException {
URL url = new URL(Constants.MC_PROFILE_URL);

HttpURLConnection conn = (HttpURLConnection)url.openConnection();
Expand Down

0 comments on commit 2c18978

Please sign in to comment.