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.io.InputStreamReader;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.net.IDN;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -84,6 +83,7 @@ import proxy.packet.ServerInfo;
|
||||||
import proxy.util.Config;
|
import proxy.util.Config;
|
||||||
import proxy.util.Formatter;
|
import proxy.util.Formatter;
|
||||||
import proxy.util.User;
|
import proxy.util.User;
|
||||||
|
import proxy.util.ViaProxyProcess;
|
||||||
import proxy.util.Log;
|
import proxy.util.Log;
|
||||||
import proxy.util.Option;
|
import proxy.util.Option;
|
||||||
|
|
||||||
|
@ -115,9 +115,10 @@ public class Proxy {
|
||||||
private final Map<String, Command> commands = Maps.newTreeMap();
|
private final Map<String, Command> commands = Maps.newTreeMap();
|
||||||
private final Thread serverThread;
|
private final Thread serverThread;
|
||||||
private final ServerInfo status = new ServerInfo(NAME + " 1.8.9", 47);
|
private final ServerInfo status = new ServerInfo(NAME + " 1.8.9", 47);
|
||||||
|
private final ViaProxyProcess viaProxy = new ViaProxyProcess(this);
|
||||||
|
|
||||||
@Config
|
@Config
|
||||||
private int compression = -1;
|
private int compression = 256;
|
||||||
@Config
|
@Config
|
||||||
private boolean epoll = true;
|
private boolean epoll = true;
|
||||||
@Config
|
@Config
|
||||||
|
@ -131,9 +132,17 @@ public class Proxy {
|
||||||
@Config
|
@Config
|
||||||
private String forwardHost = "127.0.0.1";
|
private String forwardHost = "127.0.0.1";
|
||||||
@Config
|
@Config
|
||||||
|
private String viaProxyJar = "ViaProxy.jar";
|
||||||
|
@Config
|
||||||
|
private String viaProxyJavaPath = "";
|
||||||
|
@Config
|
||||||
|
private int viaProxyMaxMem = 1024;
|
||||||
|
@Config
|
||||||
private int forwardPort = 25563;
|
private int forwardPort = 25563;
|
||||||
@Config
|
@Config
|
||||||
private String proxyHost = "";
|
private String bindHost = "";
|
||||||
|
@Config
|
||||||
|
private int bindPort = 25565;
|
||||||
@Config
|
@Config
|
||||||
private int proxyPort = 25564;
|
private int proxyPort = 25564;
|
||||||
@Config
|
@Config
|
||||||
|
@ -298,14 +307,18 @@ public class Proxy {
|
||||||
public void run(long time) {
|
public void run(long time) {
|
||||||
this.loadConfig();
|
this.loadConfig();
|
||||||
this.loadUsers();
|
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 {
|
try {
|
||||||
this.addLanEndpoint(this.proxyHost.isEmpty() ? null : InetAddress.getByName(IDN.toASCII(this.proxyHost)), this.proxyPort);
|
this.addLanEndpoint(InetAddress.getLoopbackAddress(), this.proxyPort);
|
||||||
}
|
}
|
||||||
catch(IOException e) {
|
catch(IOException e) {
|
||||||
Log.error(e, "Could not bind to port");
|
Log.error(e, "Could not bind to port");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(!this.viaProxy.start()) {
|
||||||
|
this.terminateEndpoints();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Proxy.this.endProxy();
|
Proxy.this.endProxy();
|
||||||
|
@ -368,6 +381,7 @@ public class Proxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endProxy() {
|
private void endProxy() {
|
||||||
|
this.viaProxy.shutdown();
|
||||||
this.terminateEndpoints();
|
this.terminateEndpoints();
|
||||||
this.saveData();
|
this.saveData();
|
||||||
}
|
}
|
||||||
|
@ -502,6 +516,30 @@ public class Proxy {
|
||||||
return this.forwardHost;
|
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() {
|
public int getForwardPort() {
|
||||||
return this.forwardPort;
|
return this.forwardPort;
|
||||||
}
|
}
|
||||||
|
@ -713,11 +751,8 @@ public class Proxy {
|
||||||
if(args.length == 0)
|
if(args.length == 0)
|
||||||
return false;
|
return false;
|
||||||
Command cmd = this.commands.get(args[0].toLowerCase(Locale.US));
|
Command cmd = this.commands.get(args[0].toLowerCase(Locale.US));
|
||||||
if(cmd == null) {
|
if(cmd == null)
|
||||||
if(player == null)
|
|
||||||
Log.error("Command '%s' not found", args[0]);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
if(!cmd.canUse(player)) {
|
if(!cmd.canUse(player)) {
|
||||||
if(player == null)
|
if(player == null)
|
||||||
Log.error("The console can not use this command");
|
Log.error("The console can not use this command");
|
||||||
|
@ -765,10 +800,16 @@ public class Proxy {
|
||||||
if(args[0].indexOf(':') != -1) {
|
if(args[0].indexOf(':') != -1) {
|
||||||
if(player != null)
|
if(player != null)
|
||||||
player.sendToServer(new C01PacketChatMessage("/"));
|
player.sendToServer(new C01PacketChatMessage("/"));
|
||||||
|
else
|
||||||
|
this.viaProxy.runCommand("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!this.runCommand(player, args, msg) && player != null)
|
if(!this.runCommand(player, args, msg)) {
|
||||||
|
if(player != null)
|
||||||
player.sendToServer(new C01PacketChatMessage(line));
|
player.sendToServer(new C01PacketChatMessage(line));
|
||||||
|
else
|
||||||
|
this.viaProxy.runCommand(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = String.format(Formatter.BLUE + "%s" + Formatter.DARK_GRAY + ": " + Formatter.GRAY + "%s", player != null ? player.getUsername() : "#CONSOLE#", line);
|
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;
|
package proxy.handler;
|
||||||
|
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import proxy.Proxy;
|
import proxy.Proxy;
|
||||||
import proxy.network.Connection;
|
import proxy.network.Connection;
|
||||||
import proxy.packet.L00PacketLoginStart;
|
import proxy.packet.L00PacketLoginStart;
|
||||||
import proxy.packet.L01PacketEncryptionResponse;
|
import proxy.packet.L01PacketEncryptionResponse;
|
||||||
import proxy.packet.R00PacketDisconnect;
|
import proxy.packet.R00PacketDisconnect;
|
||||||
import proxy.packet.R02PacketLoginSuccess;
|
import proxy.packet.R02PacketLoginSuccess;
|
||||||
import proxy.packet.R03PacketEnableCompression;
|
|
||||||
import proxy.util.Formatter;
|
import proxy.util.Formatter;
|
||||||
import proxy.util.Log;
|
import proxy.util.Log;
|
||||||
|
|
||||||
|
@ -61,13 +58,13 @@ public class LoginHandler implements Handler {
|
||||||
}
|
}
|
||||||
this.state = LoginState.DONE;
|
this.state = LoginState.DONE;
|
||||||
|
|
||||||
if(this.proxy.getCompression() >= 0) {
|
// if(this.proxy.getCompression() >= 0) {
|
||||||
this.connection.sendPacket(new R03PacketEnableCompression(this.proxy.getCompression()), new ChannelFutureListener() {
|
// this.connection.sendPacket(new R03PacketEnableCompression(this.proxy.getCompression()), new ChannelFutureListener() {
|
||||||
public void operationComplete(ChannelFuture p_operationComplete_1_) throws Exception {
|
// public void operationComplete(ChannelFuture p_operationComplete_1_) throws Exception {
|
||||||
LoginHandler.this.connection.setCompressionTreshold(LoginHandler.this.proxy.getCompression());
|
// LoginHandler.this.connection.setCompressionTreshold(LoginHandler.this.proxy.getCompression());
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
ProxyHandler handler = new ProxyHandler(this.proxy, this.connection, this.username);
|
ProxyHandler handler = new ProxyHandler(this.proxy, this.connection, this.username);
|
||||||
this.connection.setNetHandler(handler);
|
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