From a91336f03e66927c50f5612767f8ac2dbe2b4ba6 Mon Sep 17 00:00:00 2001 From: LAX1DUDE Date: Thu, 14 Apr 2022 23:28:49 -0700 Subject: [PATCH] Added 2FA command for ayonull's server list, added 'hide_down' flag to default server list --- .../main/java/net/md_5/bungee/BungeeCord.java | 2 ++ .../eaglercraft/QueryConnectionImpl.java | 2 ++ .../bungee/eaglercraft/WebSocketListener.java | 9 ++++-- .../lax1dude/eaglercraft/ConfigConstants.java | 2 +- .../java/net/minecraft/client/Minecraft.java | 2 +- .../net/minecraft/src/GuiMultiplayer.java | 6 ++-- .../java/net/minecraft/src/ItemRenderer.java | 4 +-- .../java/net/minecraft/src/ServerData.java | 6 ++-- .../java/net/minecraft/src/ServerList.java | 28 +++++++++++++++---- 9 files changed, 44 insertions(+), 17 deletions(-) diff --git a/eaglercraftbungee/src/main/java/net/md_5/bungee/BungeeCord.java b/eaglercraftbungee/src/main/java/net/md_5/bungee/BungeeCord.java index ebc4177..2eead0f 100644 --- a/eaglercraftbungee/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/eaglercraftbungee/src/main/java/net/md_5/bungee/BungeeCord.java @@ -60,6 +60,7 @@ import net.md_5.bungee.command.CommandSend; import net.md_5.bungee.command.CommandPerms; import net.md_5.bungee.command.CommandBungee; import net.md_5.bungee.command.CommandClearRatelimit; +import net.md_5.bungee.command.CommandConfirmCode; import net.md_5.bungee.command.CommandAlert; import net.md_5.bungee.command.CommandIP; import net.md_5.bungee.command.CommandServer; @@ -154,6 +155,7 @@ public class BungeeCord extends ProxyServer { this.getPluginManager().registerCommand(null, new CommandSend()); this.getPluginManager().registerCommand(null, new CommandFind()); this.getPluginManager().registerCommand(null, new CommandClearRatelimit()); + this.getPluginManager().registerCommand(null, new CommandConfirmCode()); this.registerChannel("BungeeCord"); Log.setOutput(new PrintStream(ByteStreams.nullOutputStream())); AnsiConsole.systemInstall(); diff --git a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/QueryConnectionImpl.java b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/QueryConnectionImpl.java index a9d5955..04fd2b2 100644 --- a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/QueryConnectionImpl.java +++ b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/QueryConnectionImpl.java @@ -19,6 +19,8 @@ public class QueryConnectionImpl implements QueryConnection { protected List packetBuffer = new LinkedList(); protected long creationTime; protected boolean keepAlive = false; + + public static String confirmHash = null; public QueryConnectionImpl(ListenerInfo listener, InetAddress addr, WebSocket socket, String accept) { this.listener = listener; diff --git a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/WebSocketListener.java b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/WebSocketListener.java index bc0815e..776224e 100644 --- a/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/WebSocketListener.java +++ b/eaglercraftbungee/src/main/java/net/md_5/bungee/eaglercraft/WebSocketListener.java @@ -95,9 +95,9 @@ public class WebSocketListener extends WebSocketServer { if(o instanceof PendingSocket) { InetAddress realAddr = ((PendingSocket)o).realAddress; arg1 = arg1.trim().toLowerCase(); + QueryConnectionImpl con; if(arg1.startsWith("accept:")) { arg1 = arg1.substring(7).trim(); - QueryConnectionImpl con; WebsocketQueryEvent evt; if(arg1.startsWith("motd")) { if(info.isAllowMOTD()) { @@ -121,7 +121,12 @@ public class WebSocketListener extends WebSocketServer { return; } }else { - if(info.isAllowQuery()) { + if(QueryConnectionImpl.confirmHash != null && arg1.equalsIgnoreCase(QueryConnectionImpl.confirmHash)) { + QueryConnectionImpl.confirmHash = null; + arg0.send("OK"); + arg0.close(); + return; + }else if(info.isAllowQuery()) { if(ratelimitQuery != null && !BanList.isBlockedBan(realAddr)) { RateLimit l = ratelimitQuery.rateLimit(realAddr); if(l.blocked()) { diff --git a/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java b/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java index f4085e5..96f9eee 100644 --- a/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java +++ b/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java @@ -4,7 +4,7 @@ public class ConfigConstants { public static boolean profanity = false; - public static final String version = "22w14d"; + public static final String version = "22w15a"; public static final String mainMenuString = "eaglercraft " + version; public static final String forkMe = "https://github.com/LAX1DUDE/eaglercraft"; diff --git a/src/main/java/net/minecraft/client/Minecraft.java b/src/main/java/net/minecraft/client/Minecraft.java index ee0c258..6525adb 100644 --- a/src/main/java/net/minecraft/client/Minecraft.java +++ b/src/main/java/net/minecraft/client/Minecraft.java @@ -248,7 +248,7 @@ public class Minecraft implements Runnable { String s = EaglerAdapter.getServerToJoinOnLaunch(); if(s != null) { - this.displayGuiScreen(new GuiScreenEditProfile(new GuiConnecting(new GuiMainMenu(), this, new ServerData("Eaglercraft Server", s)))); + this.displayGuiScreen(new GuiScreenEditProfile(new GuiConnecting(new GuiMainMenu(), this, new ServerData("Eaglercraft Server", s, false)))); }else { this.displayGuiScreen(new GuiScreenEditProfile(new GuiMainMenu())); } diff --git a/src/main/java/net/minecraft/src/GuiMultiplayer.java b/src/main/java/net/minecraft/src/GuiMultiplayer.java index 06f2f7e..bce83ab 100644 --- a/src/main/java/net/minecraft/src/GuiMultiplayer.java +++ b/src/main/java/net/minecraft/src/GuiMultiplayer.java @@ -174,14 +174,14 @@ public class GuiMultiplayer extends GuiScreen { this.joinServer(this.selectedServer); } else if (par1GuiButton.id == 4) { this.directClicked = true; - this.mc.displayGuiScreen(new GuiScreenServerList(this, this.theServerData = new ServerData(StatCollector.translateToLocal("selectServer.defaultName"), ""))); + this.mc.displayGuiScreen(new GuiScreenServerList(this, this.theServerData = new ServerData(StatCollector.translateToLocal("selectServer.defaultName"), "", false))); } else if (par1GuiButton.id == 3) { this.addClicked = true; - this.mc.displayGuiScreen(new GuiScreenAddServer(this, this.theServerData = new ServerData(StatCollector.translateToLocal("selectServer.defaultName"), ""))); + this.mc.displayGuiScreen(new GuiScreenAddServer(this, this.theServerData = new ServerData(StatCollector.translateToLocal("selectServer.defaultName"), "", false))); } else if (par1GuiButton.id == 7) { this.editClicked = true; ServerData var9 = this.internetServerList.getServerData(this.selectedServer); - this.theServerData = new ServerData(var9.serverName, var9.serverIP); + this.theServerData = new ServerData(var9.serverName, var9.serverIP, false); this.theServerData.setHideAddress(var9.isHidingAddress()); this.mc.displayGuiScreen(new GuiScreenAddServer(this, this.theServerData)); } else if (par1GuiButton.id == 0) { diff --git a/src/main/java/net/minecraft/src/ItemRenderer.java b/src/main/java/net/minecraft/src/ItemRenderer.java index d26138a..71359ae 100644 --- a/src/main/java/net/minecraft/src/ItemRenderer.java +++ b/src/main/java/net/minecraft/src/ItemRenderer.java @@ -108,9 +108,9 @@ public class ItemRenderer { } EaglerAdapter.glDisable(EaglerAdapter.GL_RESCALE_NORMAL); + + EaglerAdapter.flipLightMatrix(); } - - EaglerAdapter.flipLightMatrix(); EaglerAdapter.glPopMatrix(); } diff --git a/src/main/java/net/minecraft/src/ServerData.java b/src/main/java/net/minecraft/src/ServerData.java index f55b093..9505a3c 100644 --- a/src/main/java/net/minecraft/src/ServerData.java +++ b/src/main/java/net/minecraft/src/ServerData.java @@ -46,13 +46,15 @@ public class ServerData { public boolean hasError = false; public List playerList = new ArrayList(); public int serverIconGL = -1; + public final boolean isDefault; /** Whether to hide the IP address for this server. */ private boolean hideAddress = false; - public ServerData(String par1Str, String par2Str) { + public ServerData(String par1Str, String par2Str, boolean isDefault) { this.serverName = par1Str; this.serverIP = par2Str; + this.isDefault = isDefault; } /** @@ -94,7 +96,7 @@ public class ServerData { * instance. */ public static ServerData getServerDataFromNBTCompound(NBTTagCompound par0NBTTagCompound) { - ServerData var1 = new ServerData(par0NBTTagCompound.getString("name"), par0NBTTagCompound.getString("ip")); + ServerData var1 = new ServerData(par0NBTTagCompound.getString("name"), par0NBTTagCompound.getString("ip"), par0NBTTagCompound.getBoolean("default")); var1.hideAddress = par0NBTTagCompound.getBoolean("hideAddress"); return var1; } diff --git a/src/main/java/net/minecraft/src/ServerList.java b/src/main/java/net/minecraft/src/ServerList.java index 4e42114..5d39abf 100644 --- a/src/main/java/net/minecraft/src/ServerList.java +++ b/src/main/java/net/minecraft/src/ServerList.java @@ -3,6 +3,7 @@ package net.minecraft.src; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -20,9 +21,12 @@ public class ServerList { /** List of ServerData instances. */ private final List servers = new ArrayList(); + private final List allServers = new ArrayList(); public static final List forcedServers = new ArrayList(); private static final Set motdLocks = new HashSet(); + + public static boolean hideDownDefaultServers = false; public ServerList(Minecraft par1Minecraft) { this.mc = par1Minecraft; @@ -32,13 +36,14 @@ public class ServerList { public static void loadDefaultServers(String base64) { try { NBTTagCompound nbt = CompressedStreamTools.readUncompressed(Base64.decodeBase64(base64)); - if(nbt.getBoolean("profanity")) { - ConfigConstants.profanity = true; - } + ConfigConstants.profanity = nbt.getBoolean("profanity"); + hideDownDefaultServers = nbt.getBoolean("hide_down"); forcedServers.clear(); NBTTagList list = nbt.getTagList("servers"); for (int i = 0; i < list.tagCount(); ++i) { - forcedServers.add(ServerData.getServerDataFromNBTCompound((NBTTagCompound) list.tagAt(i))); + NBTTagCompound tag = (NBTTagCompound) list.tagAt(i); + tag.setBoolean("default", true); + forcedServers.add(ServerData.getServerDataFromNBTCompound(tag)); } } catch (IOException e) { e.printStackTrace(); @@ -53,14 +58,18 @@ public class ServerList { public void loadServerList() { freeServerIcons(); this.servers.clear(); + this.allServers.clear(); for(ServerData dat : forcedServers) { dat.pingSentTime = -1l; dat.hasPing = false; this.servers.add(dat); + this.allServers.add(dat); } NBTTagList servers = LocalStorageManager.gameSettingsStorage.getTagList("servers"); for (int i = 0; i < servers.tagCount(); ++i) { - this.servers.add(ServerData.getServerDataFromNBTCompound((NBTTagCompound) servers.tagAt(i))); + ServerData dat = ServerData.getServerDataFromNBTCompound((NBTTagCompound) servers.tagAt(i)); + this.servers.add(dat); + this.allServers.add(dat); } } @@ -142,6 +151,8 @@ public class ServerList { } public void refreshServerPing() { + this.servers.clear(); + this.servers.addAll(this.allServers); for(ServerData dat : servers) { if(dat.currentQuery != null && dat.currentQuery.isQueryOpen()) { dat.currentQuery.close(); @@ -153,7 +164,9 @@ public class ServerList { public void updateServerPing() { int total = 0; - for(ServerData dat : servers) { + Iterator itr = servers.iterator(); + while(itr.hasNext()) { + ServerData dat = itr.next(); if(dat.pingSentTime <= 0l) { dat.pingToServer = -2l; String addr = dat.serverIP; @@ -218,6 +231,9 @@ public class ServerList { dat.pingToServer = -1l; dat.hasPing = true; } + if(ServerList.hideDownDefaultServers && dat.isDefault && dat.pingToServer == -1l && dat.hasPing == true) { + itr.remove(); + } } if(total >= 4) { break;