Skip to content

Commit

Permalink
Fix crash on invalid server addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jul 5, 2024
1 parent d24a377 commit 9d180a3
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ public final class ProtocolClient implements AutoCloseable, ProxyPassthrough {

public ProtocolClient(String host, boolean successToast, boolean failureToast) {
this.originalHost = host;
final HostAndPort target = HostAndPort.fromString(host).withDefaultPort(9646);
CONNECTION_THREAD_BUILDER.start(() -> {
HostAndPort target = null;
Socket socket = null;
try {
target = HostAndPort.fromString(host).withDefaultPort(9646);
socket = new Socket(target.getHost(), target.getPort());

final User user = authUser.join();
authUser = null;

performHandshake(socket, user, connectionId);
} catch (Exception e) {
WorldHost.LOGGER.error("Failed to connect to {}.", target, e);
WorldHost.LOGGER.error("Failed to connect to {} ({}).", originalHost, target, e);
if (failureToast) {
WHToast.builder("world-host.wh_connect.connect_failed")
.description(Component.nullToEmpty(e.getLocalizedMessage()))
Expand Down

0 comments on commit 9d180a3

Please sign in to comment.