Skip to content

Commit ff7373a

Browse files
noramibuWide-Cat
andauthored
Prefer UUIDs for friend info lookups over usernames (#5728)
Should make the friends system more consistent and alleviate issues caused by mojang rate limiting one of their api endpoints. Updating the friends list may cause a small lag spike on startup depending on how many friends you have (the only reason this didn't happen before is because of the aformentioned rate limiting issues). Co-authored-by: Wide_Cat <[email protected]>
1 parent 36f3268 commit ff7373a

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/FriendsTab.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
2121
import net.minecraft.client.gui.screen.Screen;
2222

23+
import static meteordevelopment.meteorclient.MeteorClient.mc;
24+
2325
public class FriendsTab extends Tab {
2426
public FriendsTab() {
2527
super("Friends");
@@ -64,7 +66,7 @@ public void initWidgets() {
6466

6567
MeteorExecutor.execute(() -> {
6668
friend.updateInfo();
67-
reload();
69+
mc.execute(this::reload);
6870
});
6971
}
7072
};
@@ -80,7 +82,6 @@ private void initTable(WTable table) {
8082
MeteorExecutor.execute(() -> {
8183
if (friend.headTextureNeedsUpdate()) {
8284
friend.updateInfo();
83-
reload();
8485
}
8586
})
8687
);

src/main/java/meteordevelopment/meteorclient/systems/friends/Friend.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
package meteordevelopment.meteorclient.systems.friends;
77

88
import com.mojang.util.UndashedUuid;
9+
import meteordevelopment.meteorclient.MeteorClient;
910
import meteordevelopment.meteorclient.utils.misc.ISerializable;
11+
import meteordevelopment.meteorclient.utils.network.FailedHttpResponse;
1012
import meteordevelopment.meteorclient.utils.network.Http;
1113
import meteordevelopment.meteorclient.utils.render.PlayerHeadTexture;
1214
import meteordevelopment.meteorclient.utils.render.PlayerHeadUtils;
@@ -15,6 +17,7 @@
1517
import org.jetbrains.annotations.NotNull;
1618

1719
import javax.annotation.Nullable;
20+
import java.net.http.HttpResponse;
1821
import java.util.Objects;
1922
import java.util.UUID;
2023

@@ -49,11 +52,32 @@ public PlayerHeadTexture getHead() {
4952

5053
public void updateInfo() {
5154
updating = true;
52-
APIResponse res = Http.get("https://api.mojang.com/users/profiles/minecraft/" + name).sendJson(APIResponse.class);
53-
if (res == null || res.name == null || res.id == null) return;
54-
name = res.name;
55-
id = UndashedUuid.fromStringLenient(res.id);
56-
mc.execute(() -> headTexture = PlayerHeadUtils.fetchHead(id));
55+
HttpResponse<APIResponse> res = null;
56+
57+
if (id != null) {
58+
res = Http.get("https://sessionserver.mojang.com/session/minecraft/profile/" + UndashedUuid.toString(id))
59+
.exceptionHandler(e -> MeteorClient.LOG.error("Error while trying to connect session server for friend '{}'", name))
60+
.sendJsonResponse(APIResponse.class);
61+
}
62+
63+
// Fallback to name-based lookup
64+
if (res == null || res.statusCode() != 200) {
65+
res = Http.get("https://api.mojang.com/users/profiles/minecraft/" + name)
66+
.exceptionHandler(e -> MeteorClient.LOG.error("Error while trying to update info for friend '{}'", name))
67+
.sendJsonResponse(APIResponse.class);
68+
}
69+
70+
if (res != null && res.statusCode() == 200) {
71+
name = res.body().name;
72+
id = UndashedUuid.fromStringLenient(res.body().id);
73+
mc.execute(() -> headTexture = PlayerHeadUtils.fetchHead(id));
74+
}
75+
76+
// cracked accounts shouldn't be assigned ids
77+
else if (!(res instanceof FailedHttpResponse)) {
78+
id = null;
79+
}
80+
5781
updating = false;
5882
}
5983

@@ -91,7 +115,7 @@ public int hashCode() {
91115

92116
@Override
93117
public int compareTo(@NotNull Friend friend) {
94-
return name.compareTo(friend.name);
118+
return name.compareToIgnoreCase(friend.name);
95119
}
96120

97121
private static class APIResponse {

0 commit comments

Comments
 (0)