proxy work + custom settings

This commit is contained in:
ayunami2000 2022-02-01 17:01:42 -05:00
parent a2e2ca0a5f
commit 62c1ae2f8b
9 changed files with 17020 additions and 17031 deletions

File diff suppressed because it is too large Load Diff

View File

@ -15,8 +15,10 @@
<script type="text/javascript" src="music.js"></script> <script type="text/javascript" src="music.js"></script>
<script type="text/javascript" src="classes.js?t=updateme5"></script> <script type="text/javascript" src="classes.js?t=updateme6"></script>
<script type="text/javascript"> <script type="text/javascript">
//window.eag_self_proxy=true;//set to true to set the default proxy to the current url
//window.eag_proxy_list="";//set to a string of comma-separated proxy ip:port combinations for a custom proxy list
var name="PixelCraft",motd="A public 1.5.2 server",ip="pixelcraft.me"; var name="PixelCraft",motd="A public 1.5.2 server",ip="pixelcraft.me";
window.addEventListener("load", function(){ window.addEventListener("load", function(){
document.requestPointerLock=document.requestPointerLock||function(){}; document.requestPointerLock=document.requestPointerLock||function(){};

View File

@ -65,6 +65,7 @@ public class WebsocketNetworkManager implements INetworkManager {
byte[] out = ("{\"port\":\""+port+"\",\"host\":\""+ip+"\"}").getBytes(StandardCharsets.UTF_8); byte[] out = ("{\"port\":\""+port+"\",\"host\":\""+ip+"\"}").getBytes(StandardCharsets.UTF_8);
http.setFixedLengthStreamingMode(out.length); http.setFixedLengthStreamingMode(out.length);
http.setRequestProperty("Content-Type","application/json; charset=UTF-8"); http.setRequestProperty("Content-Type","application/json; charset=UTF-8");
http.setConnectTimeout(5000);
http.connect(); http.connect();
http.getOutputStream().write(out); http.getOutputStream().write(out);
Reader in = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8")); Reader in = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8"));

View File

@ -89,6 +89,19 @@ public class EaglerAdapterImpl2 {
public static final String _wgetShaderHeader() { public static final String _wgetShaderHeader() {
return "#version 150"; return "#version 150";
} }
public static final boolean getSelfProxy(){
//todo: implement local proxy for desktop mode??
return true;
}
public static final String[] getCustomProxyList(){
return new String[]{};
}
public static final String getHostString(){
return "localhost";
}
public static final InputStream loadResource(String path) { public static final InputStream loadResource(String path) {
byte[] file = loadResourceBytes(path); byte[] file = loadResourceBytes(path);

View File

@ -7,7 +7,7 @@ public class ConfigConstants {
public static boolean profanity = false; public static boolean profanity = false;
public static final String version = "22w04b"; public static final String version = "22w04b";
public static final String mainMenuString = "eaglercraft " + version; public static final String mainMenuString = "ayuncraft " + version;
public static final String forkMe = "https://github.com/ayunami2000/ayuncraft"; public static final String forkMe = "https://github.com/ayunami2000/ayuncraft";

View File

@ -6,7 +6,10 @@ import net.minecraft.src.GuiTextField;
import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.StringTranslate; import net.minecraft.src.StringTranslate;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@ -211,8 +214,9 @@ public class GuiScreenEditProfile extends GuiScreen {
URL url = new URL("http" + (EaglerAdapter.isSSLPage() ? "s" : "") + "://" + this.mc.gameSettings.proxy + "/api/vm/net/connect"); URL url = new URL("http" + (EaglerAdapter.isSSLPage() ? "s" : "") + "://" + this.mc.gameSettings.proxy + "/api/vm/net/connect");
URLConnection con = url.openConnection(); URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection) con; HttpURLConnection http = (HttpURLConnection) con;
http.setConnectTimeout(5000);
http.connect(); http.connect();
if(http.getResponseCode()!=HttpURLConnection.HTTP_OK&&http.getResponseCode()!=HttpURLConnection.HTTP_NOT_FOUND){ if(http.getResponseCode()!=HttpURLConnection.HTTP_NOT_FOUND){
http.disconnect(); http.disconnect();
throw new IOException("lol"); throw new IOException("lol");
} }

View File

@ -5,16 +5,22 @@ import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.LocalStorageManager; import net.lax1dude.eaglercraft.LocalStorageManager;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import java.util.Arrays;
public class GameSettings { public class GameSettings {
public static boolean useDefaultProtocol = true; public static boolean useDefaultProtocol = true;
public static String proxy = ""; public static String proxy = "";
public static String getNewProxy(){ public static String getNewProxy(){
if(ConfigConstants.proxies.length==1)return ConfigConstants.proxies[0];
String res=proxy; String res=proxy;
//inefficient but i dont care
while(res.equals(proxy)) res = ConfigConstants.proxies[(int) Math.floor(Math.random() * ConfigConstants.proxies.length)]; while(res.equals(proxy)) res = ConfigConstants.proxies[(int) Math.floor(Math.random() * ConfigConstants.proxies.length)];
return res; return res;
} }
static { static {
proxy = getNewProxy(); String[] proxyList = EaglerAdapter.getCustomProxyList();
if(proxyList.length!=0&&!proxyList[0].equals(""))ConfigConstants.proxies=proxyList;
proxy = EaglerAdapter.getSelfProxy()?EaglerAdapter.getHostString():getNewProxy();
} }

View File

@ -57,6 +57,7 @@ public class WebsocketNetworkManager implements INetworkManager {
byte[] out = ("{\"port\":\""+port+"\",\"host\":\""+ip+"\"}").getBytes(StandardCharsets.UTF_8); byte[] out = ("{\"port\":\""+port+"\",\"host\":\""+ip+"\"}").getBytes(StandardCharsets.UTF_8);
http.setFixedLengthStreamingMode(out.length); http.setFixedLengthStreamingMode(out.length);
http.setRequestProperty("Content-Type","application/json; charset=UTF-8"); http.setRequestProperty("Content-Type","application/json; charset=UTF-8");
http.setConnectTimeout(5000);
http.connect(); http.connect();
http.getOutputStream().write(out); http.getOutputStream().write(out);
Reader in = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8")); Reader in = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8"));

View File

@ -83,7 +83,20 @@ public class EaglerAdapterImpl2 {
public static final String _wgetShaderHeader() { public static final String _wgetShaderHeader() {
return "#version 300 es"; return "#version 300 es";
} }
@JSBody(params = { }, script = "return !!window.eag_self_proxy;")
public static native boolean getSelfProxy();
@JSBody(params = { }, script = "return (window.eag_proxy_list+\"\")||\"\";")
private static native String getCustomProxyListString();
public static String[] getCustomProxyList(){
return getCustomProxyListString().split(",");
}
@JSBody(params = { }, script = "return window.location.host;")
public static native String getHostString();
@JSBody(params = { }, script = "return window.location.href;") @JSBody(params = { }, script = "return window.location.href;")
private static native String getLocationString(); private static native String getLocationString();