Skip to content

Commit

Permalink
Fix getting a server address
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Jul 5, 2023
1 parent cb4e1a1 commit 475cb05
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.netty.buffer.Unpooled;
import io.netty.channel.local.LocalAddress;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import net.minecraft.client.network.ClientPlayerEntity;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -46,6 +47,13 @@ public BinaryWebSocketFrame toWebSocketFrame() {
}

private static String getIP(SocketAddress address) {
return ((InetSocketAddress) address).getAddress().getHostAddress();
if (address instanceof LocalAddress) {
return "localhost";

} else if (address instanceof InetSocketAddress inetSocketAddress) {
return inetSocketAddress.getAddress().getHostAddress();
}

return address.toString();
}
}

0 comments on commit 475cb05

Please sign in to comment.