Skip to content

Commit

Permalink
Add useSSL flag to ServerAddress.Tcp
Browse files Browse the repository at this point in the history
This also adds support for rptools-maptool+tcps URIs to connect to SSL
servers over the command-line.

This adds the useSSL flag to an existing variant as the minimal change.
  • Loading branch information
fishface60 committed Feb 11, 2025
1 parent b0ba178 commit b0a193a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package/linux/launcher.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Icon=/opt/maptool/lib/${projectName}${developerRelease}.png
Terminal=false
Type=Application
Categories=Game
MimeType=application/maptool;x-scheme-handler/rptools-maptool+registry;x-scheme-handler/rptools-maptool+lan;x-scheme-handler/rptools-maptool+tcp
MimeType=application/maptool;x-scheme-handler/rptools-maptool+registry;x-scheme-handler/rptools-maptool+lan;x-scheme-handler/rptools-maptool+tcp;x-scheme-handler/rptools-maptool+tcps
StartupWMClass=net-rptools-maptool-client-LaunchInstructions
13 changes: 13 additions & 0 deletions package/windows/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@
<RegistryValue Type="string" Value="&quot;[INSTALLDIR]$(var.JpAppName).exe&quot; &quot;%1&quot;" />
</RegistryKey>
</RegistryKey>
<RegistryKey Root="HKCR"
Key="rptools-maptool+tcps"
ForceCreateOnInstall="yes"
ForceDeleteOnUninstall="yes">
<RegistryValue Type="string" Name="URL Protocol" Value=""/>
<RegistryValue Type="string" Value="URL:MapTool SSL connect"/>
<RegistryKey Key="DefaultIcon">
<RegistryValue Type="string" Value="[INSTALLDIR]$(var.JpAppName).exe" />
</RegistryKey>
<RegistryKey Key="shell\open\command">
<RegistryValue Type="string" Value="&quot;[INSTALLDIR]$(var.JpAppName).exe&quot; &quot;%1&quot;" />
</RegistryKey>
</RegistryKey>
<?endif?>
</Component>

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/rptools/clientserver/ConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
package net.rptools.clientserver;

import java.awt.EventQueue;
import java.net.ServerSocket;
import java.net.Socket;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocketFactory;
import net.rptools.clientserver.simple.connection.Connection;
import net.rptools.clientserver.simple.connection.SocketConnection;
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/net/rptools/maptool/client/ServerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,28 @@ public URI toUri() {
}
}

record Tcp(@Nonnull String address, int port) implements ServerAddress {
record Tcp(@Nonnull String address, int port, boolean useSSL) implements ServerAddress {
@Override
@Nonnull
public RemoteServerConfig findServer() {
return new RemoteServerConfig.Socket(
address(), port() == -1 ? ServerConfig.DEFAULT_PORT : port());
var port = port();
if (port == -1) {
port = ServerConfig.DEFAULT_PORT;
}

if (useSSL) {
return new RemoteServerConfig.SSLSocket(address(), port);
}

return new RemoteServerConfig.Socket(address(), port);
}

@Override
@Nonnull
public URI toUri() {
try {
return new URI("rptools-maptool+tcp", null, address(), port(), "/", null, null);
var scheme = useSSL() ? "rptools-maptool+tcps" : "rptools-maptool+tcp";
return new URI(scheme, null, address(), port(), "/", null, null);
} catch (URISyntaxException e) {
throw new AssertionError(
"Scheme and path are given and the path is absolute and IP address authorities are all valid so this should be infallible",
Expand Down Expand Up @@ -173,14 +182,14 @@ static ServerAddress parse(@Nonnull String s)
return new ServerAddress.Lan(serviceIdentifier);

case "rptools-maptool+tcp":
case "rptools-maptool+tcps":
if (host == null) {
throw new IllegalArgumentException("rptools-maptool+tcp URIs must have a host");
throw new IllegalArgumentException(scheme + " URIs must have a host");
}
if (path != null && !path.isEmpty() && !path.equals("/")) {
throw new IllegalArgumentException(
"rptools-maptool+tcp URIs must have no path or just /");
throw new IllegalArgumentException(scheme + " URIs must have no path or just /");
}
return new ServerAddress.Tcp(host, port);
return new ServerAddress.Tcp(host, port, scheme.endsWith("s"));

case null:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public ConnectionInfoDialog(MapToolServer server) {
return null;
}
return new ServerAddress.Tcp(
NetUtil.formatAddress(localAddresses.ipv4().get(0)), server.getPort());
NetUtil.formatAddress(localAddresses.ipv4().get(0)),
server.getPort(),
false);
});
Supplier<CompletableFuture<ServerAddress.Tcp>> getLocalV6 =
() ->
Expand All @@ -119,7 +121,9 @@ public ConnectionInfoDialog(MapToolServer server) {
return null;
}
return new ServerAddress.Tcp(
NetUtil.formatAddress(localAddresses.ipv6().get(0)), server.getPort());
NetUtil.formatAddress(localAddresses.ipv6().get(0)),
server.getPort(),
false);
});
Supplier<CompletableFuture<ServerAddress.Tcp>> getExternal =
() ->
Expand All @@ -131,7 +135,7 @@ public ConnectionInfoDialog(MapToolServer server) {
return null;
}
return new ServerAddress.Tcp(
NetUtil.formatAddress(address), server.getPort());
NetUtil.formatAddress(address), server.getPort(), false);
});
registerCopyButton(panel, "registryUriCopyButton", getServerName, ServerAddress::toUri);
registerCopyButton(panel, "registryHttpUrlCopyButton", getServerName, ServerAddress::toHttpUrl);
Expand Down

0 comments on commit b0a193a

Please sign in to comment.