make program a viaproxy wrapper
This commit is contained in:
parent
6bead101d3
commit
f2022c091f
4 changed files with 146 additions and 23 deletions
|
@ -1,3 +1,3 @@
|
|||
# VLoginProxy
|
||||
# VProxy
|
||||
|
||||
Ein Proxy für das Minecraft®™ 1.8.x Protokoll für die Verwendung zwischen ViaProxy oder direkter Verbindung und Bungeecord, Waterfall, Velocity u.A.
|
||||
Ein Proxy für das Minecraft®™ 1.8.x Protokoll für die Verwendung mit ViaProxy und PandaSpigot, Bungeecord, Waterfall, Velocity u.A.
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.IDN;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -84,6 +83,7 @@ import proxy.packet.ServerInfo;
|
|||
import proxy.util.Config;
|
||||
import proxy.util.Formatter;
|
||||
import proxy.util.User;
|
||||
import proxy.util.ViaProxyProcess;
|
||||
import proxy.util.Log;
|
||||
import proxy.util.Option;
|
||||
|
||||
|
@ -115,9 +115,10 @@ public class Proxy {
|
|||
private final Map<String, Command> commands = Maps.newTreeMap();
|
||||
private final Thread serverThread;
|
||||
private final ServerInfo status = new ServerInfo(NAME + " 1.8.9", 47);
|
||||
private final ViaProxyProcess viaProxy = new ViaProxyProcess(this);
|
||||
|
||||
@Config
|
||||
private int compression = -1;
|
||||
private int compression = 256;
|
||||
@Config
|
||||
private boolean epoll = true;
|
||||
@Config
|
||||
|
@ -131,9 +132,17 @@ public class Proxy {
|
|||
@Config
|
||||
private String forwardHost = "127.0.0.1";
|
||||
@Config
|
||||
private String viaProxyJar = "ViaProxy.jar";
|
||||
@Config
|
||||
private String viaProxyJavaPath = "";
|
||||
@Config
|
||||
private int viaProxyMaxMem = 1024;
|
||||
@Config
|
||||
private int forwardPort = 25563;
|
||||
@Config
|
||||
private String proxyHost = "";
|
||||
private String bindHost = "";
|
||||
@Config
|
||||
private int bindPort = 25565;
|
||||
@Config
|
||||
private int proxyPort = 25564;
|
||||
@Config
|
||||
|
@ -298,14 +307,18 @@ public class Proxy {
|
|||
public void run(long time) {
|
||||
this.loadConfig();
|
||||
this.loadUsers();
|
||||
Log.info("Hosting proxy on %s:%d", this.proxyHost.isEmpty() ? "0.0.0.0" : this.proxyHost, this.proxyPort);
|
||||
Log.info("Hosting proxy on localhost:%d", this.proxyPort);
|
||||
try {
|
||||
this.addLanEndpoint(this.proxyHost.isEmpty() ? null : InetAddress.getByName(IDN.toASCII(this.proxyHost)), this.proxyPort);
|
||||
this.addLanEndpoint(InetAddress.getLoopbackAddress(), this.proxyPort);
|
||||
}
|
||||
catch(IOException e) {
|
||||
Log.error(e, "Could not bind to port");
|
||||
return;
|
||||
}
|
||||
if(!this.viaProxy.start()) {
|
||||
this.terminateEndpoints();
|
||||
return;
|
||||
}
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Proxy.this.endProxy();
|
||||
|
@ -368,6 +381,7 @@ public class Proxy {
|
|||
}
|
||||
|
||||
private void endProxy() {
|
||||
this.viaProxy.shutdown();
|
||||
this.terminateEndpoints();
|
||||
this.saveData();
|
||||
}
|
||||
|
@ -502,6 +516,30 @@ public class Proxy {
|
|||
return this.forwardHost;
|
||||
}
|
||||
|
||||
public String getBindHost() {
|
||||
return this.bindHost;
|
||||
}
|
||||
|
||||
public int getBindPort() {
|
||||
return this.bindPort;
|
||||
}
|
||||
|
||||
public int getProxyPort() {
|
||||
return this.proxyPort;
|
||||
}
|
||||
|
||||
public String getViaProxyJar() {
|
||||
return this.viaProxyJar;
|
||||
}
|
||||
|
||||
public String getViaProxyJavaPath() {
|
||||
return this.viaProxyJavaPath;
|
||||
}
|
||||
|
||||
public int getViaProxyMaxMem() {
|
||||
return this.viaProxyMaxMem;
|
||||
}
|
||||
|
||||
public int getForwardPort() {
|
||||
return this.forwardPort;
|
||||
}
|
||||
|
@ -713,11 +751,8 @@ public class Proxy {
|
|||
if(args.length == 0)
|
||||
return false;
|
||||
Command cmd = this.commands.get(args[0].toLowerCase(Locale.US));
|
||||
if(cmd == null) {
|
||||
if(player == null)
|
||||
Log.error("Command '%s' not found", args[0]);
|
||||
if(cmd == null)
|
||||
return false;
|
||||
}
|
||||
if(!cmd.canUse(player)) {
|
||||
if(player == null)
|
||||
Log.error("The console can not use this command");
|
||||
|
@ -765,10 +800,16 @@ public class Proxy {
|
|||
if(args[0].indexOf(':') != -1) {
|
||||
if(player != null)
|
||||
player.sendToServer(new C01PacketChatMessage("/"));
|
||||
else
|
||||
this.viaProxy.runCommand("");
|
||||
return;
|
||||
}
|
||||
if(!this.runCommand(player, args, msg) && player != null)
|
||||
player.sendToServer(new C01PacketChatMessage(line));
|
||||
if(!this.runCommand(player, args, msg)) {
|
||||
if(player != null)
|
||||
player.sendToServer(new C01PacketChatMessage(line));
|
||||
else
|
||||
this.viaProxy.runCommand(msg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
msg = String.format(Formatter.BLUE + "%s" + Formatter.DARK_GRAY + ": " + Formatter.GRAY + "%s", player != null ? player.getUsername() : "#CONSOLE#", line);
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package proxy.handler;
|
||||
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import proxy.Proxy;
|
||||
import proxy.network.Connection;
|
||||
import proxy.packet.L00PacketLoginStart;
|
||||
import proxy.packet.L01PacketEncryptionResponse;
|
||||
import proxy.packet.R00PacketDisconnect;
|
||||
import proxy.packet.R02PacketLoginSuccess;
|
||||
import proxy.packet.R03PacketEnableCompression;
|
||||
import proxy.util.Formatter;
|
||||
import proxy.util.Log;
|
||||
|
||||
|
@ -61,13 +58,13 @@ public class LoginHandler implements Handler {
|
|||
}
|
||||
this.state = LoginState.DONE;
|
||||
|
||||
if(this.proxy.getCompression() >= 0) {
|
||||
this.connection.sendPacket(new R03PacketEnableCompression(this.proxy.getCompression()), new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture p_operationComplete_1_) throws Exception {
|
||||
LoginHandler.this.connection.setCompressionTreshold(LoginHandler.this.proxy.getCompression());
|
||||
}
|
||||
});
|
||||
}
|
||||
// if(this.proxy.getCompression() >= 0) {
|
||||
// this.connection.sendPacket(new R03PacketEnableCompression(this.proxy.getCompression()), new ChannelFutureListener() {
|
||||
// public void operationComplete(ChannelFuture p_operationComplete_1_) throws Exception {
|
||||
// LoginHandler.this.connection.setCompressionTreshold(LoginHandler.this.proxy.getCompression());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
ProxyHandler handler = new ProxyHandler(this.proxy, this.connection, this.username);
|
||||
this.connection.setNetHandler(handler);
|
||||
|
|
85
proxy/src/main/java/proxy/util/ViaProxyProcess.java
Normal file
85
proxy/src/main/java/proxy/util/ViaProxyProcess.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package proxy.util;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.util.Locale;
|
||||
|
||||
import proxy.Proxy;
|
||||
|
||||
public class ViaProxyProcess {
|
||||
private final Proxy proxy;
|
||||
|
||||
private Process process;
|
||||
private PrintWriter writer;
|
||||
|
||||
public ViaProxyProcess(Proxy proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
private static String getJavaDir() {
|
||||
String separator = System.getProperty("file.separator");
|
||||
String path = System.getProperty("java.home") + separator + "bin" + separator;
|
||||
return System.getProperty("os.name").toLowerCase(Locale.US).contains("win") && (new File(path + "javaw.exe")).isFile() ? path + "javaw.exe" : path + "java";
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
if(!new File(this.proxy.getViaProxyJar()).exists()) {
|
||||
Log.error("The file %s could not be found in the current directory. Please download the lastest Version of ViaProxy and place it at %s.",
|
||||
this.proxy.getViaProxyJar(), new File(this.proxy.getViaProxyJar()).getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
this.process = new ProcessBuilder(
|
||||
this.proxy.getViaProxyJavaPath().isEmpty() ? getJavaDir() : this.proxy.getViaProxyJavaPath(),
|
||||
"-Xmx" + this.proxy.getViaProxyMaxMem() + "m",
|
||||
"-jar", this.proxy.getViaProxyJar(),
|
||||
"cli",
|
||||
"--proxy-online-mode", "false",
|
||||
"--chat-signing", "false",
|
||||
"--target-version", "1.8.x",
|
||||
"--compression-threshold", "" + this.proxy.getCompression(),
|
||||
"--target-address", "127.0.0.1:" + this.proxy.getProxyPort(),
|
||||
"--bind-address", (this.proxy.getBindHost().isEmpty() ? "0.0.0.0" : this.proxy.getBindHost()) + ":" + this.proxy.getBindPort()
|
||||
).redirectOutput(Redirect.INHERIT).redirectError(Redirect.INHERIT).redirectInput(Redirect.PIPE).start();
|
||||
}
|
||||
catch(IOException e) {
|
||||
Log.error(e, "Could not start ViaProxy process");
|
||||
return false;
|
||||
}
|
||||
this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new BufferedOutputStream(this.process.getOutputStream()))), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
if(this.writer != null) {
|
||||
try {
|
||||
this.writer.println("exit");
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
}
|
||||
if(this.process != null) {
|
||||
try {
|
||||
this.process.waitFor();
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
Log.error(e, "Interrupted while waiting for ViaProxy to terminate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void runCommand(String cmd) {
|
||||
if(this.writer != null) {
|
||||
try {
|
||||
this.writer.println(cmd);
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue