Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for MapTool registry errors in 1.13.0 #4036

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/main/java/net/rptools/maptool/client/MapToolRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,34 @@ private MapToolRegistry() {}

public SeverConnectionDetails findInstance(String id) {
OkHttpClient client = new OkHttpClient();
String requestUrl =
HttpUrl.parse(SERVER_DETAILS).newBuilder().addQueryParameter("name", id).build().toString();

String requestUrl;
try {
requestUrl =
HttpUrl.parse(SERVER_DETAILS)
.newBuilder()
.addQueryParameter("name", id)
.build()
.toString();
} catch (Exception e) {
log.error("Error building request url", e);
MapTool.showError("msg.error.fetchingRegistryInformation", e);
return new SeverConnectionDetails();
}

Request request = new Request.Builder().url(requestUrl).build();

try (Response response = client.newCall(request).execute()) {

// Check if we got an actual response. If we did not, just do an early return,
// the server isn't real.
if (response.body().string().isEmpty()) {
var responseString = response.body().string();
if (responseString.isEmpty()) {
MapTool.showError("msg.error.fetchingRegistryInformation");
return new SeverConnectionDetails();
}

JsonObject json = JsonParser.parseString(response.body().string()).getAsJsonObject();
JsonObject json = JsonParser.parseString(responseString).getAsJsonObject();
SeverConnectionDetails details = new SeverConnectionDetails();

details.address = json.getAsJsonPrimitive("address").getAsString();
Expand All @@ -114,8 +128,9 @@ public SeverConnectionDetails findInstance(String id) {

return details;

} catch (IOException | NullPointerException e) {
} catch (Exception e) {
log.error("Error fetching instance from server registry", e);
MapTool.showError("msg.error.fetchingRegistryInformation", e);
return new SeverConnectionDetails();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,7 @@ msg.error.failedAddingDefaultImages = Could not restore default images
msg.error.failedAddingDefaultTables = Could not restore default tables.
msg.error.failedCannotRegisterServer = Unable to register your server.
msg.error.failedConnect = Could not connect to server.
msg.error.fetchingRegistryInformation = Error fetching server information from registry.
msg.error.initializeCrypto = Failed to initialize Cryptology library.
msg.error.initializePlayerDatabase = Failed to initialize Player Database.
msg.error.failedExportingCampaignRepo = Could not export campaign repository file.
Expand Down