Try-catch MojangUtils#getName and a portion of POST /server/heartbeat to make debugging easier
This commit is contained in:
parent
27b98d3b69
commit
3bc703384b
@ -107,32 +107,36 @@ public final class POSTServerHeartbeat implements Handler<RoutingContext> {
|
||||
if (result.failed()) {
|
||||
callback.fail(result.cause());
|
||||
} else {
|
||||
Map<UUID, User> users = result.result().result(0);
|
||||
Map<UUID, List<Grant>> grants = result.result().result(1);
|
||||
Map<UUID, List<Punishment>> punishments = result.result().result(2);
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
try {
|
||||
Map<UUID, User> users = result.result().result(0);
|
||||
Map<UUID, List<Grant>> grants = result.result().result(1);
|
||||
Map<UUID, List<Punishment>> punishments = result.result().result(2);
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
for (Map.Entry<UUID, User> userEntry : users.entrySet()) {
|
||||
UUID uuid = userEntry.getKey();
|
||||
User user = userEntry.getValue();
|
||||
for (Map.Entry<UUID, User> userEntry : users.entrySet()) {
|
||||
UUID uuid = userEntry.getKey();
|
||||
User user = userEntry.getValue();
|
||||
|
||||
if (user == null) {
|
||||
String username = playerNames.get(uuid);
|
||||
user = new User(uuid, username);
|
||||
user.insert();
|
||||
users.put(uuid, user);
|
||||
if (user == null) {
|
||||
String username = playerNames.get(uuid);
|
||||
user = new User(uuid, username);
|
||||
user.insert();
|
||||
users.put(uuid, user);
|
||||
}
|
||||
|
||||
// Only save if needed
|
||||
if (user.seenOnServer(server)) {
|
||||
user.save();
|
||||
}
|
||||
|
||||
// TODO: Provide IPs for ip ban lookup
|
||||
response.put(uuid.toString(), user.createLoginInfo(server, punishments.get(uuid), ImmutableList.of(), grants.get(uuid)));
|
||||
}
|
||||
|
||||
// Only save if needed
|
||||
if (user.seenOnServer(server)) {
|
||||
user.save();
|
||||
}
|
||||
|
||||
// TODO: Provide IPs for ip ban lookup
|
||||
response.put(uuid.toString(), user.createLoginInfo(server, punishments.get(uuid), ImmutableList.of(), grants.get(uuid)));
|
||||
callback.complete(response);
|
||||
} catch (Exception ex) {
|
||||
callback.fail(ex);
|
||||
}
|
||||
|
||||
callback.complete(response);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.mongodb.async.SingleResultCallback;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import org.bson.Document;
|
||||
import org.bson.json.JsonParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
@ -14,13 +15,17 @@ public class MojangUtils {
|
||||
public static void getName(UUID id, SingleResultCallback<String> callback) {
|
||||
APIv3.getHttpClient().get("sessionserver.mojang.com", "/session/minecraft/profile/" + id.toString().replace("-", ""), (response) -> {
|
||||
response.bodyHandler((body) -> {
|
||||
Document resJson = Document.parse(body.toString());
|
||||
String name = resJson.getString("name");
|
||||
try {
|
||||
Document resJson = Document.parse(body.toString());
|
||||
String name = resJson.getString("name");
|
||||
|
||||
if (name == null) {
|
||||
callback.onResult(null, new IOException("Hit Mojang API rate limit: " + resJson.toJson()));
|
||||
} else {
|
||||
callback.onResult(name, null);
|
||||
if (name == null) {
|
||||
callback.onResult(null, new IOException("Hit Mojang API rate limit: " + resJson.toJson()));
|
||||
} else {
|
||||
callback.onResult(name, null);
|
||||
}
|
||||
} catch (JsonParseException ex) {
|
||||
callback.onResult(null, new RuntimeException(body.toString(), ex));
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user