Only update id of the profile the user uses next when using the pid tool

This commit is contained in:
kuroppoi 2023-08-11 05:18:37 +02:00
parent 306b9e6db6
commit 3224f6312a
4 changed files with 22 additions and 34 deletions

View File

@ -15,7 +15,6 @@ import com.formdev.flatlaf.extras.components.FlatTextField;
import entralinked.Entralinked;
import entralinked.model.user.User;
import entralinked.model.user.UserManager;
import entralinked.utility.SwingUtility;
public class PidToolDialog {
@ -56,8 +55,7 @@ public class PidToolDialog {
return;
}
UserManager userManager = entralinked.getUserManager();
User user = userManager.getUser(userId.substring(0, 13));
User user = entralinked.getUserManager().getUser(userId.substring(0, 13));
int profileId = (int)(Long.parseLong(friendCode) & 0x7FFFFFFF);
// Make sure user exists
@ -66,17 +64,9 @@ public class PidToolDialog {
return;
}
// Show warning if this user has multiple profiles
if(user.getProfiles().size() > 1) {
if(JOptionPane.showConfirmDialog(dialog, "Multiple profiles detected. Do you want to update all of them?\n"
+ "This may cause error 60000 to occur on your other game cartridges.",
"Attention", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
return;
}
}
userManager.updateProfileIdForUser(user, profileId);
JOptionPane.showMessageDialog(dialog, "Profile has been updated. Please restart your game and use Game Sync.");
user.setProfileIdOverride(profileId);
JOptionPane.showMessageDialog(dialog,
"All done! Please restart your game and use Game Sync.\nGame profile data will be updated and saved once you do so.");
});
// Create content panel

View File

@ -13,6 +13,7 @@ public class User {
private final String password; // I debated hashing it, but.. it's a 3-digit password...
private final Map<String, GameProfile> profiles = new HashMap<>();
private final Map<String, Dlc> dlcOverrides = new HashMap<>();
private int profileIdOverride; // For making it easier for the user to fix error 60000
public User(String id, String password) {
this.id = id;
@ -70,4 +71,12 @@ public class User {
public Dlc getDlcOverride(String type) {
return dlcOverrides.get(type);
}
public void setProfileIdOverride(int profileIdOverride) {
this.profileIdOverride = profileIdOverride;
}
public int getProfileIdOverride() {
return profileIdOverride;
}
}

View File

@ -233,26 +233,6 @@ public class UserManager {
return profile;
}
/**
* This will forcibly set the profile id of all profiles of this user to the specified one.
* Potentially a destructive operation; use with caution.
*
* @return {@code true} if the operation was successful, otherwise {@code false}.
*/
public boolean updateProfileIdForUser(User user, int profileId) {
// Set the id of all profiles
for(GameProfile profile : user.getProfiles()) {
profile.setId(profileId);
}
// Try to save user
if(!saveUser(user)) {
return false;
}
return true;
}
/**
* @return {@code true} if a user with the specified ID exists, otherwise {@code false}.
*/

View File

@ -119,6 +119,15 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
}
}
// Update profile id if an override is set
int profileIdOverride = user.getProfileIdOverride();
if(profileIdOverride > 0) {
profile.setId(profileIdOverride);
user.setProfileIdOverride(0);
userManager.saveUser(user); // It's not too big of a deal if this fails for some reason
}
// Prepare and send response
sessionKey = secureRandom.nextInt(Integer.MAX_VALUE);
String proof = createCredentialHash(partnerChallengeHash, authToken, serverChallenge, clientChallenge);