mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Add UPnP Forwarding Option
This commit is contained in:
parent
e5ba821754
commit
3911b6e867
@ -29,6 +29,12 @@
|
|||||||
<version>0.8.16</version>
|
<version>0.8.16</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.dosse.upnp</groupId>
|
||||||
|
<artifactId>WaifUPnP</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
<groupId>com.imaginarycode.minecraft</groupId>
|
||||||
<artifactId>RedisBungee</artifactId>
|
<artifactId>RedisBungee</artifactId>
|
||||||
|
@ -86,7 +86,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
clean = true;
|
clean = true;
|
||||||
}
|
}
|
||||||
for (SubServer server : servers.values()) {
|
for (SubServer server : servers.values()) {
|
||||||
client.get().sendPacket(new PacketExAddServer(server.getName(), server.isEnabled(), server.isLogging(), server.getPath(), ((ExternalSubServer) server).exec, server.getStopCommand(), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
client.get().sendPacket(new PacketExAddServer(server.getName(), server.isEnabled(), server.getAddress().getPort(), server.isLogging(), server.getPath(), ((ExternalSubServer) server).exec, server.getStopCommand(), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
||||||
}
|
}
|
||||||
while (queue.size() != 0) {
|
while (queue.size() != 0) {
|
||||||
client.get().sendPacket(queue.get(0));
|
client.get().sendPacket(queue.get(0));
|
||||||
@ -148,7 +148,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
||||||
plugin.getPluginManager().callEvent(event);
|
plugin.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
queue(new PacketExAddServer(name, enabled, log, directory, executable, stopcmd, (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
queue(new PacketExAddServer(name, enabled, port, log, directory, executable, stopcmd, (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
||||||
servers.put(name.toLowerCase(), server);
|
servers.put(name.toLowerCase(), server);
|
||||||
return server;
|
return server;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Bungee.Host.Internal;
|
package net.ME1312.SubServers.Bungee.Host.Internal;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Host.Executable;
|
import net.ME1312.SubServers.Bungee.Host.Executable;
|
||||||
@ -101,6 +102,7 @@ public class InternalHost extends Host {
|
|||||||
plugin.getPluginManager().callEvent(event);
|
plugin.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
servers.put(name.toLowerCase(), server);
|
servers.put(name.toLowerCase(), server);
|
||||||
|
if (UPnP.isUPnPAvailable() && plugin.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(port);
|
||||||
return server;
|
return server;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -118,6 +120,8 @@ public class InternalHost extends Host {
|
|||||||
getSubServer(server).stop();
|
getSubServer(server).stop();
|
||||||
getSubServer(server).waitFor();
|
getSubServer(server).waitFor();
|
||||||
}
|
}
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(getSubServer(server).getAddress().getPort()))
|
||||||
|
UPnP.closePortTCP(getSubServer(server).getAddress().getPort());
|
||||||
servers.remove(server.toLowerCase());
|
servers.remove(server.toLowerCase());
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else return false;
|
||||||
@ -132,6 +136,8 @@ public class InternalHost extends Host {
|
|||||||
if (getSubServer(server).isRunning()) {
|
if (getSubServer(server).isRunning()) {
|
||||||
getSubServer(server).terminate();
|
getSubServer(server).terminate();
|
||||||
}
|
}
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(getSubServer(server).getAddress().getPort()))
|
||||||
|
UPnP.closePortTCP(getSubServer(server).getAddress().getPort());
|
||||||
servers.remove(server.toLowerCase());
|
servers.remove(server.toLowerCase());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,10 @@ Settings:
|
|||||||
Version: '2.11.2a+'
|
Version: '2.11.2a+'
|
||||||
Log-Creator: true
|
Log-Creator: true
|
||||||
Override-Bungee-Commands: true
|
Override-Bungee-Commands: true
|
||||||
|
UPnP:
|
||||||
|
Forward-Proxy: true
|
||||||
|
Forward-SubData: false
|
||||||
|
Forward-Servers: false
|
||||||
SubData:
|
SubData:
|
||||||
Address: '127.0.0.1:4391'
|
Address: '127.0.0.1:4391'
|
||||||
Password: 'default'
|
Password: 'default'
|
||||||
|
@ -19,6 +19,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||||
private String name;
|
private String name;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
private int port;
|
||||||
private boolean log;
|
private boolean log;
|
||||||
private String directory;
|
private String directory;
|
||||||
private Executable executable;
|
private Executable executable;
|
||||||
@ -41,10 +42,11 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
* @param executable Executable
|
* @param executable Executable
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketExAddServer(String name, boolean enabled, boolean log, String directory, Executable executable, String stopcmd, UUID running, Callback<YAMLSection>... callback) {
|
public PacketExAddServer(String name, boolean enabled, int port, boolean log, String directory, Executable executable, String stopcmd, UUID running, Callback<YAMLSection>... callback) {
|
||||||
if (Util.isNull(name, enabled, log, directory, executable, callback)) throw new NullPointerException();
|
if (Util.isNull(name, enabled, log, directory, executable, callback)) throw new NullPointerException();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
|
this.port = port;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
this.executable = executable;
|
this.executable = executable;
|
||||||
@ -61,6 +63,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
YAMLSection server = new YAMLSection();
|
YAMLSection server = new YAMLSection();
|
||||||
server.set("name", name);
|
server.set("name", name);
|
||||||
server.set("enabled", enabled);
|
server.set("enabled", enabled);
|
||||||
|
server.set("port", port);
|
||||||
server.set("log", log);
|
server.set("log", log);
|
||||||
server.set("dir", directory);
|
server.set("dir", directory);
|
||||||
server.set("exec", executable.toString());
|
server.set("exec", executable.toString());
|
||||||
@ -78,6 +81,6 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public Version getVersion() {
|
||||||
return new Version("2.11.0a");
|
return new Version("2.13.1b");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Bungee.Network;
|
package net.ME1312.SubServers.Bungee.Network;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkConnectEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubNetworkConnectEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
|
||||||
@ -56,6 +57,7 @@ public final class SubDataServer {
|
|||||||
server = new ServerSocket(port, MAX_QUEUE, address);
|
server = new ServerSocket(port, MAX_QUEUE, address);
|
||||||
allowConnection(address.getHostAddress());
|
allowConnection(address.getHostAddress());
|
||||||
}
|
}
|
||||||
|
if (UPnP.isUPnPAvailable() && plugin.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-SubData", false)) UPnP.openPortTCP(port);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.cipher = (cipher != null)?cipher:new Cipher() {
|
this.cipher = (cipher != null)?cipher:new Cipher() {
|
||||||
@Override
|
@Override
|
||||||
@ -478,6 +480,7 @@ public final class SubDataServer {
|
|||||||
removeClient((Client) clients.values().toArray()[0]);
|
removeClient((Client) clients.values().toArray()[0]);
|
||||||
}
|
}
|
||||||
server.close();
|
server.close();
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getLocalPort())) UPnP.closePortTCP(server.getLocalPort());
|
||||||
System.out.println("SubServers > The SubData Listener has been closed");
|
System.out.println("SubServers > The SubData Listener has been closed");
|
||||||
plugin.subdata = null;
|
plugin.subdata = null;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Bungee;
|
package net.ME1312.SubServers.Bungee;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubAddProxyEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubAddProxyEvent;
|
||||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveProxyEvent;
|
import net.ME1312.SubServers.Bungee.Event.SubRemoveProxyEvent;
|
||||||
@ -11,24 +12,19 @@ import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
|||||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||||
import net.ME1312.SubServers.Bungee.Library.Version.VersionType;
|
|
||||||
import net.ME1312.SubServers.Bungee.Network.Cipher;
|
import net.ME1312.SubServers.Bungee.Network.Cipher;
|
||||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutReload;
|
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutReload;
|
||||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.BungeeServerInfo;
|
import net.md_5.bungee.BungeeServerInfo;
|
||||||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||||
import net.md_5.bungee.api.event.ServerKickEvent;
|
import net.md_5.bungee.api.event.ServerKickEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@ -61,7 +57,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
public final SubAPI api = new SubAPI(this);
|
public final SubAPI api = new SubAPI(this);
|
||||||
public SubDataServer subdata = null;
|
public SubDataServer subdata = null;
|
||||||
public SubServer sudo = null;
|
public SubServer sudo = null;
|
||||||
public static final Version version = Version.fromString("2.13.1a");
|
public static final Version version = Version.fromString("2.13.1b");
|
||||||
|
|
||||||
public Proxy redis = null;
|
public Proxy redis = null;
|
||||||
public boolean canSudo = false;
|
public boolean canSudo = false;
|
||||||
@ -519,6 +515,13 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
for (Server server : api.getServers().values()) if (server.getSubData() != null) server.getSubData().sendPacket(new PacketOutReload(null));
|
for (Server server : api.getServers().values()) if (server.getSubData() != null) server.getSubData().sendPacket(new PacketOutReload(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (UPnP.isUPnPAvailable()) {
|
||||||
|
if (config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Proxy", true)) for (ListenerInfo listener : getConfig().getListeners()) {
|
||||||
|
UPnP.openPortTCP(listener.getHost().getPort());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getLogger().warning("UPnP is currently unavailable; Ports may not be automatically forwarded on this device");
|
||||||
|
}
|
||||||
System.out.println("SubServers > " + ((plugins > 0)?plugins+" Plugin"+((plugins == 1)?"":"s")+", ":"") + ((proxies > 1)?proxies+" Proxies, ":"") + hosts + " Host"+((hosts == 1)?"":"s")+", " + servers + " Server"+((servers == 1)?"":"s")+", and " + subservers + " SubServer"+((subservers == 1)?"":"s")+" "+((status)?"re":"")+"loaded in " + new DecimalFormat("0.000").format((Calendar.getInstance().getTime().getTime() - begin) / 1000D) + "s");
|
System.out.println("SubServers > " + ((plugins > 0)?plugins+" Plugin"+((plugins == 1)?"":"s")+", ":"") + ((proxies > 1)?proxies+" Proxies, ":"") + hosts + " Host"+((hosts == 1)?"":"s")+", " + servers + " Server"+((servers == 1)?"":"s")+", and " + subservers + " SubServer"+((subservers == 1)?"":"s")+" "+((status)?"re":"")+"loaded in " + new DecimalFormat("0.000").format((Calendar.getInstance().getTime().getTime() - begin) / 1000D) + "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,6 +595,10 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
shutdown();
|
shutdown();
|
||||||
|
|
||||||
subdata.destroy();
|
subdata.destroy();
|
||||||
|
|
||||||
|
for (ListenerInfo listener : getConfig().getListeners()) {
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -614,6 +621,10 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
getPluginManager().callEvent(new SubRemoveProxyEvent(proxies.get(proxy)));
|
getPluginManager().callEvent(new SubRemoveProxyEvent(proxies.get(proxy)));
|
||||||
}
|
}
|
||||||
proxies.clear();
|
proxies.clear();
|
||||||
|
|
||||||
|
for (ListenerInfo listener : getConfig().getListeners()) {
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getNewSignature() {
|
String getNewSignature() {
|
||||||
@ -709,7 +720,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = Byte.MAX_VALUE)
|
@EventHandler(priority = Byte.MIN_VALUE)
|
||||||
public void fallback(ServerKickEvent e) {
|
public void fallback(ServerKickEvent e) {
|
||||||
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: 'SubServers-Client-Bukkit'
|
name: 'SubServers-Client-Bukkit'
|
||||||
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
|
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
|
||||||
version: '2.13.1a'
|
version: '2.13.1b'
|
||||||
authors: [ME1312]
|
authors: [ME1312]
|
||||||
softdepend: [Vault, TitleManager]
|
softdepend: [Vault, TitleManager]
|
||||||
website: 'https://github.com/ME1312/SubServers-2'
|
website: 'https://github.com/ME1312/SubServers-2'
|
||||||
|
@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
/**
|
/**
|
||||||
* SubServers Client Plugin Class
|
* SubServers Client Plugin Class
|
||||||
*/
|
*/
|
||||||
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13.1a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
|
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13.1b", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
|
||||||
public final class SubPlugin {
|
public final class SubPlugin {
|
||||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||||
public YAMLConfig config;
|
public YAMLConfig config;
|
||||||
|
@ -29,6 +29,12 @@
|
|||||||
<version>0.8.16</version>
|
<version>0.8.16</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.dosse.upnp</groupId>
|
||||||
|
<artifactId>WaifUPnP</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Host;
|
package net.ME1312.SubServers.Host;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||||
@ -32,7 +33,7 @@ import java.util.jar.Manifest;
|
|||||||
/**
|
/**
|
||||||
* SubServers.Host Main Class
|
* SubServers.Host Main Class
|
||||||
*/
|
*/
|
||||||
@Plugin(name = "SubServers.Host", version = "2.13.1a", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
|
@Plugin(name = "SubServers.Host", version = "2.13.1b", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
|
||||||
public final class ExHost {
|
public final class ExHost {
|
||||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||||
public HashMap<String, SubCreator.ServerTemplate> templates = new HashMap<String, SubCreator.ServerTemplate>();
|
public HashMap<String, SubCreator.ServerTemplate> templates = new HashMap<String, SubCreator.ServerTemplate>();
|
||||||
@ -209,6 +210,10 @@ public final class ExHost {
|
|||||||
});
|
});
|
||||||
|
|
||||||
engine.start(this::stop);
|
engine.start(this::stop);
|
||||||
|
|
||||||
|
if (!UPnP.isUPnPAvailable()) {
|
||||||
|
log.warn.println("UPnP is currently unavailable; Ports may not be automatically forwarded on this device");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error.println(e);
|
log.error.println(e);
|
||||||
stop();
|
stop();
|
||||||
@ -256,6 +261,7 @@ public final class ExHost {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error.println(e);
|
log.error.println(e);
|
||||||
}
|
}
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(servers.get(server).getPort())) UPnP.closePortTCP(servers.get(server).getPort());
|
||||||
}
|
}
|
||||||
servers.clear();
|
servers.clear();
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ public class SubServer {
|
|||||||
private ExHost host;
|
private ExHost host;
|
||||||
private String name;
|
private String name;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
private int port;
|
||||||
private Container<Boolean> log;
|
private Container<Boolean> log;
|
||||||
private String dir;
|
private String dir;
|
||||||
private File directory;
|
private File directory;
|
||||||
@ -46,11 +47,12 @@ public class SubServer {
|
|||||||
* @param stopcmd Stop Command
|
* @param stopcmd Stop Command
|
||||||
* @throws InvalidServerException
|
* @throws InvalidServerException
|
||||||
*/
|
*/
|
||||||
public SubServer(ExHost host, String name, boolean enabled, boolean log, String directory, Executable executable, String stopcmd) throws InvalidServerException {
|
public SubServer(ExHost host, String name, boolean enabled, int port, boolean log, String directory, Executable executable, String stopcmd) throws InvalidServerException {
|
||||||
if (Util.isNull(host, name, enabled, log, directory, executable)) throw new NullPointerException();
|
if (Util.isNull(host, name, enabled, log, directory, executable)) throw new NullPointerException();
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
|
this.port = port;
|
||||||
this.log = new Container<Boolean>(log);
|
this.log = new Container<Boolean>(log);
|
||||||
this.dir = directory;
|
this.dir = directory;
|
||||||
this.directory = new File(host.host.getRawString("Directory"), directory);
|
this.directory = new File(host.host.getRawString("Directory"), directory);
|
||||||
@ -237,6 +239,15 @@ public class SubServer {
|
|||||||
enabled = value;
|
enabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Port of the Server
|
||||||
|
*
|
||||||
|
* @return Server Port Number
|
||||||
|
*/
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the Server is Logging
|
* If the Server is Logging
|
||||||
*
|
*
|
||||||
|
@ -3,6 +3,8 @@ Settings:
|
|||||||
Console-Log: true
|
Console-Log: true
|
||||||
Network-Log: true
|
Network-Log: true
|
||||||
Server-Bind: '127.0.0.1'
|
Server-Bind: '127.0.0.1'
|
||||||
|
UPnP:
|
||||||
|
Forward-Servers: false
|
||||||
SubData:
|
SubData:
|
||||||
Name: 'undefined'
|
Name: 'undefined'
|
||||||
Address: '127.0.0.1:4391'
|
Address: '127.0.0.1:4391'
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Host.Network.Packet;
|
package net.ME1312.SubServers.Host.Network.Packet;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||||
import net.ME1312.Galaxi.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
@ -69,9 +70,10 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
if (host.servers.keySet().contains(data.getSection("server").getRawString("name").toLowerCase())) {
|
if (host.servers.keySet().contains(data.getSection("server").getRawString("name").toLowerCase())) {
|
||||||
host.subdata.sendPacket(new PacketExAddServer(0, "Server Already Added", (data.contains("id"))?data.getRawString("id"):null));
|
host.subdata.sendPacket(new PacketExAddServer(0, "Server Already Added", (data.contains("id"))?data.getRawString("id"):null));
|
||||||
} else {
|
} else {
|
||||||
SubServer server = new SubServer(host, data.getSection("server").getRawString("name"), data.getSection("server").getBoolean("enabled"), data.getSection("server").getBoolean("log"),
|
SubServer server = new SubServer(host, data.getSection("server").getRawString("name"), data.getSection("server").getBoolean("enabled"), data.getSection("server").getInt("port"), data.getSection("server").getBoolean("log"),
|
||||||
data.getSection("server").getRawString("dir"), new Executable(data.getSection("server").getRawString("exec")), data.getSection("server").getRawString("stopcmd"));
|
data.getSection("server").getRawString("dir"), new Executable(data.getSection("server").getRawString("exec")), data.getSection("server").getRawString("stopcmd"));
|
||||||
host.servers.put(data.getSection("server").getRawString("name").toLowerCase(), server);
|
host.servers.put(data.getSection("server").getRawString("name").toLowerCase(), server);
|
||||||
|
if (UPnP.isUPnPAvailable() && host.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getPort());
|
||||||
log.info.println("Added SubServer: " + data.getSection("server").getRawString("name"));
|
log.info.println("Added SubServer: " + data.getSection("server").getRawString("name"));
|
||||||
if (data.getSection("server").contains("running")) server.start(UUID.fromString(data.getSection("server").getRawString("running")));
|
if (data.getSection("server").contains("running")) server.start(UUID.fromString(data.getSection("server").getRawString("running")));
|
||||||
host.subdata.sendPacket(new PacketExAddServer(0, "Server Added Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
host.subdata.sendPacket(new PacketExAddServer(0, "Server Added Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
||||||
@ -84,6 +86,6 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public Version getVersion() {
|
||||||
return new Version("2.11.0a");
|
return new Version("2.13.1b");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Host.Network.Packet;
|
package net.ME1312.SubServers.Host.Network.Packet;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||||
@ -102,6 +103,7 @@ public class PacketExDeleteServer implements PacketIn, PacketOut {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getPort())) UPnP.closePortTCP(server.getPort());
|
||||||
log.info.println("Deleted SubServer: " + data.getRawString("server"));
|
log.info.println("Deleted SubServer: " + data.getRawString("server"));
|
||||||
host.subdata.sendPacket(new PacketExDeleteServer(0, "Server Deleted Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
host.subdata.sendPacket(new PacketExDeleteServer(0, "Server Deleted Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
||||||
}).start();
|
}).start();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Host.Network.Packet;
|
package net.ME1312.SubServers.Host.Network.Packet;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||||
import net.ME1312.Galaxi.Library.Log.Logger;
|
import net.ME1312.Galaxi.Library.Log.Logger;
|
||||||
import net.ME1312.Galaxi.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
@ -68,6 +69,8 @@ public class PacketExRemoveServer implements PacketIn, PacketOut {
|
|||||||
} else if (host.servers.get(data.getRawString("server").toLowerCase()).isRunning()) {
|
} else if (host.servers.get(data.getRawString("server").toLowerCase()).isRunning()) {
|
||||||
host.subdata.sendPacket(new PacketExRemoveServer(2, "That server is still running.", (data.contains("id"))?data.getRawString("id"):null));
|
host.subdata.sendPacket(new PacketExRemoveServer(2, "That server is still running.", (data.contains("id"))?data.getRawString("id"):null));
|
||||||
} else {
|
} else {
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(host.servers.get(data.getRawString("server").toLowerCase()).getPort()))
|
||||||
|
UPnP.closePortTCP(host.servers.get(data.getRawString("server").toLowerCase()).getPort());
|
||||||
host.servers.remove(data.getRawString("server").toLowerCase());
|
host.servers.remove(data.getRawString("server").toLowerCase());
|
||||||
log.info.println("Removed SubServer: " + data.getRawString("server"));
|
log.info.println("Removed SubServer: " + data.getRawString("server"));
|
||||||
host.subdata.sendPacket(new PacketExRemoveServer(0, "Server Removed Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
host.subdata.sendPacket(new PacketExRemoveServer(0, "Server Removed Successfully", (data.contains("id"))?data.getRawString("id"):null));
|
||||||
|
@ -37,6 +37,12 @@
|
|||||||
<version>0.8.16</version>
|
<version>0.8.16</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.dosse.upnp</groupId>
|
||||||
|
<artifactId>WaifUPnP</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
<groupId>com.imaginarycode.minecraft</groupId>
|
||||||
<artifactId>RedisBungee</artifactId>
|
<artifactId>RedisBungee</artifactId>
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
Settings:
|
Settings:
|
||||||
Version: '2.11.2a+'
|
Version: '2.11.2a+'
|
||||||
Override-Bungee-Commands: true
|
Override-Bungee-Commands: true
|
||||||
|
UPnP:
|
||||||
|
Forward-Proxy: true
|
||||||
SubData:
|
SubData:
|
||||||
Address: '127.0.0.1:4391'
|
Address: '127.0.0.1:4391'
|
||||||
Password: 'default'
|
Password: 'default'
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.ME1312.SubServers.Sync;
|
package net.ME1312.SubServers.Sync;
|
||||||
|
|
||||||
|
import com.dosse.upnp.UPnP;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import net.ME1312.SubServers.Sync.Event.*;
|
import net.ME1312.SubServers.Sync.Event.*;
|
||||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLConfig;
|
import net.ME1312.SubServers.Sync.Library.Config.YAMLConfig;
|
||||||
@ -16,6 +17,7 @@ import net.ME1312.SubServers.Sync.Network.SubDataClient;
|
|||||||
import net.ME1312.SubServers.Sync.Server.Server;
|
import net.ME1312.SubServers.Sync.Server.Server;
|
||||||
import net.ME1312.SubServers.Sync.Server.SubServer;
|
import net.ME1312.SubServers.Sync.Server.SubServer;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||||
import net.md_5.bungee.api.event.ServerKickEvent;
|
import net.md_5.bungee.api.event.ServerKickEvent;
|
||||||
@ -50,7 +52,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
public boolean redis = false;
|
public boolean redis = false;
|
||||||
public final SubAPI api = new SubAPI(this);
|
public final SubAPI api = new SubAPI(this);
|
||||||
public SubDataClient subdata = null;
|
public SubDataClient subdata = null;
|
||||||
public static final Version version = Version.fromString("2.13.1a");
|
public static final Version version = Version.fromString("2.13.1b");
|
||||||
|
|
||||||
public final boolean isPatched;
|
public final boolean isPatched;
|
||||||
public long lastReload = -1;
|
public long lastReload = -1;
|
||||||
@ -110,6 +112,15 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
|
Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
|
||||||
|
|
||||||
super.startListeners();
|
super.startListeners();
|
||||||
|
|
||||||
|
if (UPnP.isUPnPAvailable()) {
|
||||||
|
if (config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Proxy", true)) for (ListenerInfo listener : getConfig().getListeners()) {
|
||||||
|
UPnP.openPortTCP(listener.getHost().getPort());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getLogger().warning("UPnP is currently unavailable; Ports may not be automatically forwarded on this device");
|
||||||
|
}
|
||||||
|
|
||||||
if (!posted) {
|
if (!posted) {
|
||||||
posted = true;
|
posted = true;
|
||||||
post();
|
post();
|
||||||
@ -224,6 +235,10 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
servers.clear();
|
servers.clear();
|
||||||
|
|
||||||
subdata.destroy(0);
|
subdata.destroy(0);
|
||||||
|
|
||||||
|
for (ListenerInfo listener : getConfig().getListeners()) {
|
||||||
|
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -245,7 +260,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = Byte.MAX_VALUE)
|
@EventHandler(priority = Byte.MIN_VALUE)
|
||||||
public void fallback(ServerKickEvent e) {
|
public void fallback(ServerKickEvent e) {
|
||||||
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
if (e.getPlayer().getPendingConnection().getListener().isForceDefault()) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user