playit-cloud / playit-minecraft-plugin

A Minecraft plugin to make your server public without port forwarding using playit.gg
https://playit.gg
33 stars 7 forks source link

[FEATURE] Add automatic tunnel setup for Dynmap #15

Open loriopatrick opened 1 year ago

loriopatrick commented 1 year ago

Dynmap users Jetty, we should be able to get the jetty server instance via

getPlugin(DynmapPlugin).core: https://github.com/webbukkit/dynmap/blob/66fe5d4a8b75660f99183cc4e1e2948407a386ec/fabric-1.14.4/src/main/java/org/dynmap/fabric_1_14_4/DynmapPlugin.java#L69

DynmapCore.webServer: https://github.com/webbukkit/dynmap/blob/66fe5d4a8b75660f99183cc4e1e2948407a386ec/DynmapCore/src/main/java/org/dynmap/DynmapCore.java#L102

Then add a custom connector using an AbstractConnector that goes over the TCP tunnel https://github.com/eclipse/jetty.project/blob/1c242a6849619b46f9a2b4a45d809c37d4f0e419/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java#L138

Example implementation https://github.com/eclipse/jetty.project/blob/1c242a6849619b46f9a2b4a45d809c37d4f0e419/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java#L112

Should be able to use a ProxyEndpoint that is connected to the playit TCP tunnel https://www.eclipse.org/jetty/javadoc/jetty-10/org/eclipse/jetty/server/ProxyConnectionFactory.ProxyEndPoint.html

so create an Endpoint connection the playit TCP client, send the claim token and do the handshake. Then fold into a ProxyEndpoint and add to the connector using getDefaultConnectionFactory().newConnection(this, endPoint);

https://github.com/eclipse/jetty.project/blob/1c242a6849619b46f9a2b4a45d809c37d4f0e419/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java#L118

AndrewChqng commented 1 year ago

And for squaremap if possible please https://github.com/jpenilla/squaremap/ port 8080