Use username from Mojang for offline IDs

Affected systems: BungeeCord after name change
Effects: Carry on items, permissions, etc. from the old user account without access to the new one

After a name change it could happen that the client still only
knows the old username and will send it to the server. Mojang will provide us with an up-to-date username that we should use instead.

The username is also sent to Mojang, so that they could verify the use. Therefore exploiting this behavior extensively for arbitrary usernames is not possible.

Related #344
This commit is contained in:
games647
2020-05-25 13:41:41 +02:00
parent 286b755ee3
commit 2bd339b0bf
5 changed files with 51 additions and 34 deletions
@@ -101,25 +101,26 @@ public class ConnectListener implements Listener {
final PendingConnection connection = loginEvent.getConnection();
final InitialHandler initialHandler = (InitialHandler) connection;
final String username = initialHandler.getLoginRequest().getData();
if (connection.isOnlineMode()) {
LoginSession session = plugin.getSession().get(connection);
session.setUuid(connection.getUniqueId());
LoginResult loginProfile = initialHandler.getLoginProfile();
UUID verifiedUUID = connection.getUniqueId();
session.setUuid(verifiedUUID);
session.setVerifiedUsername(loginProfile.getName());
StoredProfile playerProfile = session.getProfile();
playerProfile.setId(connection.getUniqueId());
playerProfile.setId(verifiedUUID);
//bungeecord will do this automatically so override it on disabled option
if (!plugin.getCore().getConfig().get("premiumUuid", true)) {
String username = loginProfile.getName();
setOfflineId(initialHandler, username);
}
if (!plugin.getCore().getConfig().get("forwardSkin", true)) {
// this is null on offline mode
LoginResult loginProfile = initialHandler.getLoginProfile();
if (loginProfile != null) {
loginProfile.setProperties(emptyProperties);
}
loginProfile.setProperties(emptyProperties);
}
}
}