add proxy server support
This commit is contained in:
parent
432521daad
commit
0be8dd502b
410420
javascript/classes.js
410420
javascript/classes.js
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -1,10 +1,16 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import java.security.Key;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.*;
|
||||
import me.ayunami2000.ayuncraft.CryptManager;
|
||||
|
@ -24,12 +30,58 @@ public class WebsocketNetworkManager implements INetworkManager {
|
|||
|
||||
private NetHandler netHandler;
|
||||
|
||||
Pattern ipPattern = Pattern.compile("^"
|
||||
+ "(((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}" // Domain name
|
||||
+ "|"
|
||||
+ "localhost" // localhost
|
||||
+ "|"
|
||||
+ "(([0-9]{1,3}\\.){3})[0-9]{1,3})" // Ip
|
||||
+ "(:"
|
||||
+ "[0-9]{1,5})?$"); // Port
|
||||
|
||||
public WebsocketNetworkManager(String uri, String eagler, NetHandler netHandler) throws IOException {
|
||||
this.netHandler = netHandler;
|
||||
this.sharedKeyForEncryption = null;
|
||||
this.isInputBeingDecrypted = false;
|
||||
this.isOutputEncrypted = false;
|
||||
if(!EaglerAdapter.startConnection(uri)) {
|
||||
String proxyUrl=Minecraft.getMinecraft().gameSettings.proxy;
|
||||
boolean stillConnect=true;
|
||||
if(!proxyUrl.equals("")){
|
||||
stillConnect=false;
|
||||
if(uri.startsWith("ws://"))uri=uri.substring(5);
|
||||
if(uri.startsWith("wss://"))uri=uri.substring(6);
|
||||
if(uri.contains("/"))uri=uri.split("/",2)[0];
|
||||
if (ipPattern.matcher(proxyUrl).matches()&&ipPattern.matcher(uri).matches()) {
|
||||
String ip = uri;
|
||||
String port = "25565";
|
||||
if (uri.contains(":")) {
|
||||
String[] ipPort = uri.split(":", 2);
|
||||
ip = ipPort[0];
|
||||
port = ipPort[1];
|
||||
}
|
||||
//send initial request (lag client)
|
||||
URL url = new URL("http"+(EaglerAdapter.isSSLPage()?"s":"")+"://"+proxyUrl+"/api/vm/net/connect");
|
||||
URLConnection con = url.openConnection();
|
||||
HttpURLConnection http = (HttpURLConnection)con;
|
||||
http.setRequestMethod("POST");
|
||||
http.setDoOutput(true);
|
||||
byte[] out = ("{\"port\":\""+port+"\",\"host\":\""+ip+"\"}").getBytes(StandardCharsets.UTF_8);
|
||||
http.setFixedLengthStreamingMode(out.length);
|
||||
http.setRequestProperty("Content-Type","application/json; charset=UTF-8");
|
||||
http.connect();
|
||||
http.getOutputStream().write(out);
|
||||
Reader in = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int c; (c = in.read()) >= 0;)
|
||||
sb.append((char)c);
|
||||
String response = sb.toString();
|
||||
response=response.substring(10);
|
||||
response=response.split("\"",2)[0];
|
||||
uri="ws"+(EaglerAdapter.isSSLPage()?"s":"")+"://"+proxyUrl+"/api/vm/net/socket?token="+response;
|
||||
stillConnect=true;
|
||||
}
|
||||
}
|
||||
if(!stillConnect||!EaglerAdapter.startConnection(uri)) {
|
||||
throw new IOException("websocket to "+uri+" failed");
|
||||
}
|
||||
EaglerAdapter.setDebugVar("minecraftServer", uri);
|
||||
|
|
|
@ -10,6 +10,7 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
|
||||
private GuiScreen parent;
|
||||
private GuiTextField username;
|
||||
private GuiTextField proxy;
|
||||
|
||||
private boolean dropDownOpen = false;
|
||||
private String[] dropDownOptions;
|
||||
|
@ -76,6 +77,8 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
this.username = new GuiTextField(this.fontRenderer, this.width / 2 - 20 + 1, this.height / 6 + 24 + 1, 138, 20);
|
||||
this.username.setFocused(true);
|
||||
this.username.setText(EaglerProfile.username);
|
||||
this.proxy = new GuiTextField(this.fontRenderer, this.width / 2 - 20 + 1, this.height / 6 + 1, 138, 20);
|
||||
this.proxy.setText(this.mc.gameSettings.proxy);
|
||||
selectedSlot = EaglerProfile.presetSkinId == -1 ? EaglerProfile.customSkinId : (EaglerProfile.presetSkinId + EaglerProfile.skinNames.size());
|
||||
//this.buttonList.add(new GuiButton(0, this.width / 2 - 100, 140, "eeeee"));
|
||||
this.buttonList.add(button0 = new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, var1.translateKey("gui.done")));
|
||||
|
@ -103,8 +106,9 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
|
||||
drawRect(skinX, skinY, skinX + skinWidth, skinY + skinHeight, -6250336);
|
||||
drawRect(skinX + 1, skinY + 1, skinX + skinWidth - 1, skinY + skinHeight - 1, 0xff000015);
|
||||
|
||||
|
||||
this.username.drawTextBox();
|
||||
this.proxy.drawTextBox();
|
||||
if(dropDownOpen) {
|
||||
super.drawScreen(0, 0, par3);
|
||||
}else {
|
||||
|
@ -184,6 +188,7 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
if(!dropDownOpen) {
|
||||
if(par1GuiButton.id == 200) {
|
||||
EaglerProfile.username = this.username.getText().length() == 0 ? "null" : this.username.getText();
|
||||
this.mc.gameSettings.proxy=proxy.getText();
|
||||
EaglerProfile.presetSkinId = selectedSlot - EaglerProfile.skinNames.size();
|
||||
if(EaglerProfile.presetSkinId < 0) {
|
||||
EaglerProfile.presetSkinId = -1;
|
||||
|
@ -226,6 +231,7 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
|
||||
public void updateScreen() {
|
||||
this.username.updateCursorCounter();
|
||||
this.proxy.updateCursorCounter();
|
||||
|
||||
if(dropDownOpen) {
|
||||
if(EaglerAdapter.mouseIsButtonDown(0)) {
|
||||
|
@ -274,7 +280,8 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
this.username.textboxKeyTyped(par1, par2);
|
||||
|
||||
this.proxy.textboxKeyTyped(par1, par2);
|
||||
|
||||
String text = username.getText();
|
||||
if(text.length() > 16) text = text.substring(0, 16);
|
||||
text = text.replaceAll("[^A-Za-z0-9\\-_]", "_");
|
||||
|
@ -293,6 +300,7 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
protected void mouseClicked(int par1, int par2, int par3) {
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
this.username.mouseClicked(par1, par2, par3);
|
||||
this.proxy.mouseClicked(par1, par2, par3);
|
||||
|
||||
if (par3 == 0) {
|
||||
int skinX = this.width / 2 + 140 - 40;
|
||||
|
@ -330,7 +338,4 @@ public class GuiScreenEditProfile extends GuiScreen {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft;
|
|||
|
||||
public class GameSettings {
|
||||
public static boolean useDefaultProtocol = false;
|
||||
public static String proxy = "pproxy.rom1504.fr";
|
||||
|
||||
|
||||
private static final String[] RENDER_DISTANCES = new String[] { "options.renderDistance.far", "options.renderDistance.normal", "options.renderDistance.short", "options.renderDistance.tiny" };
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import me.ayunami2000.ayuncraft.java.security.Key;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -11,6 +16,8 @@ import me.ayunami2000.ayuncraft.CryptManager;
|
|||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
|
||||
import me.ayunami2000.ayuncraft.javax.crypto.SecretKey;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.json.JSON;
|
||||
|
||||
public class WebsocketNetworkManager implements INetworkManager {
|
||||
private boolean isInputBeingDecrypted;
|
||||
|
@ -24,12 +31,58 @@ public class WebsocketNetworkManager implements INetworkManager {
|
|||
|
||||
private NetHandler netHandler;
|
||||
|
||||
Pattern ipPattern = Pattern.compile("^"
|
||||
+ "(((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}" // Domain name
|
||||
+ "|"
|
||||
+ "localhost" // localhost
|
||||
+ "|"
|
||||
+ "(([0-9]{1,3}\\.){3})[0-9]{1,3})" // Ip
|
||||
+ "(:"
|
||||
+ "[0-9]{1,5})?$"); // Port
|
||||
|
||||
public WebsocketNetworkManager(String uri, String eagler, NetHandler netHandler) throws IOException {
|
||||
this.netHandler = netHandler;
|
||||
this.sharedKeyForEncryption = null;
|
||||
this.isInputBeingDecrypted = false;
|
||||
this.isOutputEncrypted = false;
|
||||
if(!EaglerAdapter.startConnection(uri)) {
|
||||
String proxyUrl=Minecraft.getMinecraft().gameSettings.proxy;
|
||||
boolean stillConnect=true;
|
||||
if(!proxyUrl.equals("")){
|
||||
stillConnect=false;
|
||||
if(uri.startsWith("ws://"))uri=uri.substring(5);
|
||||
if(uri.startsWith("wss://"))uri=uri.substring(6);
|
||||
if(uri.contains("/"))uri=uri.split("/",2)[0];
|
||||
if (ipPattern.matcher(proxyUrl).matches()&&ipPattern.matcher(uri).matches()) {
|
||||
String ip = uri;
|
||||
String port = "25565";
|
||||
if (uri.contains(":")) {
|
||||
String[] ipPort = uri.split(":", 2);
|
||||
ip = ipPort[0];
|
||||
port = ipPort[1];
|
||||
}
|
||||
//send initial request (lag client)
|
||||
URL url = new URL("http"+(EaglerAdapter.isSSLPage()?"s":"")+"://"+proxyUrl+"/api/vm/net/connect");
|
||||
URLConnection con = url.openConnection();
|
||||
HttpURLConnection http = (HttpURLConnection)con;
|
||||
http.setRequestMethod("POST");
|
||||
http.setDoOutput(true);
|
||||
byte[] out = ("{\"port\":\""+port+"\",\"host\":\""+ip+"\"}").getBytes(StandardCharsets.UTF_8);
|
||||
http.setFixedLengthStreamingMode(out.length);
|
||||
http.setRequestProperty("Content-Type","application/json; charset=UTF-8");
|
||||
http.connect();
|
||||
http.getOutputStream().write(out);
|
||||
Reader in = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int c; (c = in.read()) >= 0;)
|
||||
sb.append((char)c);
|
||||
String response = sb.toString();
|
||||
response=response.substring(10);
|
||||
response=response.split("\"",2)[0];
|
||||
uri="ws"+(EaglerAdapter.isSSLPage()?"s":"")+"://"+proxyUrl+"/api/vm/net/socket?token="+response;
|
||||
stillConnect=true;
|
||||
}
|
||||
}
|
||||
if(!stillConnect||!EaglerAdapter.startConnection(uri)) {
|
||||
throw new IOException("websocket to "+uri+" failed");
|
||||
}
|
||||
EaglerAdapter.setDebugVar("minecraftServer", uri);
|
||||
|
|
Loading…
Reference in New Issue
Block a user