finished the relay list (not including ping)

This commit is contained in:
LAX1DUDE 2022-08-12 22:09:38 -07:00
parent 6d06b5f7e9
commit 19bd727b93
10 changed files with 321 additions and 46 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -266,6 +266,17 @@ networkSettings.default=Set Primary
networkSettings.refresh=Refresh
networkSettings.loadDefaults=Load Defaults
addRelay.title=Add New Relay
addRelay.name=Relay Comment
addRelay.address=Relay Address
addRelay.add=Add Relay
addRelay.primary=Set Primary
addRelay.removeText1=Do you want to remove this relay?
noRelay.title=No Relays are Configured!
noRelay.noRelay1=LAN Unavailable: No Relays Configured!
noRelay.noRelay2=Click '§nNetwork Settings§r' to fix
multiplayer.title=Play Multiplayer
multiplayer.connect=Connect
multiplayer.info1=Minecraft Multiplayer is currently not finished, but there

View File

@ -0,0 +1,37 @@
package net.lax1dude.eaglercraft;
import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.StringTranslate;
public class GuiNoRelays extends GuiScreen {
private GuiScreen parent;
public GuiNoRelays(GuiScreen parent) {
this.parent = parent;
}
public void initGui() {
StringTranslate var1 = StringTranslate.getInstance();
buttonList.clear();
buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 - 60 + 145, var1.translateKey("gui.cancel")));
buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 - 60 + 115, var1.translateKey("directConnect.lanWorldRelay")));
}
public void drawScreen(int par1, int par2, float par3) {
StringTranslate var4 = StringTranslate.getInstance();
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, var4.translateKey("noRelay.title"), this.width / 2, this.height / 4 - 60 + 70, 16777215);
super.drawScreen(par1, par2, par3);
}
protected void actionPerformed(GuiButton par1GuiButton) {
if(par1GuiButton.id == 0) {
mc.displayGuiScreen(parent);
}else if(par1GuiButton.id == 1) {
mc.displayGuiScreen(new GuiScreenRelay(parent));
}
}
}

View File

@ -1,13 +1,129 @@
package net.lax1dude.eaglercraft;
import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.GuiTextField;
import net.minecraft.src.ServerData;
import net.minecraft.src.StringTranslate;
public class GuiScreenAddRelay extends GuiScreen {
private final GuiScreenRelay screen;
public GuiScreenAddRelay(GuiScreenRelay screen) {
this.screen = screen;
/** This GUI's parent GUI. */
private GuiScreenRelay parentGui;
private GuiTextField serverAddress;
private GuiTextField serverName;
public GuiScreenAddRelay(GuiScreenRelay par1GuiScreen) {
this.parentGui = par1GuiScreen;
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen() {
this.serverName.updateCursorCounter();
this.serverAddress.updateCursorCounter();
}
/**
* Adds the buttons (and other controls) to the screen in question.
*/
public void initGui() {
StringTranslate var1 = StringTranslate.getInstance();
EaglerAdapter.enableRepeatEvents(true);
this.buttonList.clear();
int sslOff = EaglerAdapter.isSSLPage() ? 36 : 0;
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12 + sslOff, var1.translateKey("addRelay.add")));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12 + sslOff, var1.translateKey("gui.cancel")));
this.buttonList.add(new GuiButton(2, this.width / 2 - 100, 142, var1.translateKey("addRelay.primary") + ": " + var1.translateKey("gui.no")));
this.serverName = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 106, 200, 20);
this.serverName.setFocused(true);
this.serverAddress = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 66, 200, 20);
this.serverAddress.setMaxStringLength(128);
((GuiButton) this.buttonList.get(0)).enabled = this.serverAddress.getText().length() > 0 && this.serverAddress.getText().split(":").length > 0 && this.serverName.getText().length() > 0;
this.parentGui.addNewName = IntegratedServer.relayManager.makeNewRelayName();
this.parentGui.addNewAddr = "";
this.parentGui.addNewPrimary = IntegratedServer.relayManager.count() == 0;
this.serverName.setText(this.parentGui.addNewName);
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed() {
EaglerAdapter.enableRepeatEvents(false);
}
/**
* Fired when a control is clicked. This is the equivalent of
* ActionListener.actionPerformed(ActionEvent e).
*/
protected void actionPerformed(GuiButton par1GuiButton) {
if (par1GuiButton.enabled) {
if (par1GuiButton.id == 1) {
this.parentGui.confirmClicked(false, 0);
} else if (par1GuiButton.id == 0) {
this.parentGui.addNewName = this.serverName.getText();
this.parentGui.addNewAddr = this.serverAddress.getText();
this.parentGui.confirmClicked(true, 0);
} else if (par1GuiButton.id == 2) {
StringTranslate var2 = StringTranslate.getInstance();
this.parentGui.addNewPrimary = !this.parentGui.addNewPrimary;
((GuiButton) this.buttonList.get(2)).displayString = var2.translateKey("addRelay.primary") + ": " + (this.parentGui.addNewPrimary ? var2.translateKey("gui.yes") : var2.translateKey("gui.no"));
}
}
}
/**
* Fired when a key is typed. This is the equivalent of
* KeyListener.keyTyped(KeyEvent e).
*/
protected void keyTyped(char par1, int par2) {
this.serverName.textboxKeyTyped(par1, par2);
this.serverAddress.textboxKeyTyped(par1, par2);
if (par1 == 9) {
if (this.serverName.isFocused()) {
this.serverName.setFocused(false);
this.serverAddress.setFocused(true);
} else {
this.serverName.setFocused(true);
this.serverAddress.setFocused(false);
}
}
if (par1 == 13) {
this.actionPerformed((GuiButton) this.buttonList.get(0));
}
((GuiButton) this.buttonList.get(0)).enabled = this.serverAddress.getText().length() > 0 && this.serverAddress.getText().split(":").length > 0 && this.serverName.getText().length() > 0;
}
/**
* Called when the mouse is clicked.
*/
protected void mouseClicked(int par1, int par2, int par3) {
super.mouseClicked(par1, par2, par3);
this.serverAddress.mouseClicked(par1, par2, par3);
this.serverName.mouseClicked(par1, par2, par3);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int par1, int par2, float par3) {
StringTranslate var4 = StringTranslate.getInstance();
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, var4.translateKey("addRelay.title"), this.width / 2, 17, 16777215);
this.drawString(this.fontRenderer, var4.translateKey("addRelay.address"), this.width / 2 - 100, 53, 10526880);
this.drawString(this.fontRenderer, var4.translateKey("addRelay.name"), this.width / 2 - 100, 94, 10526880);
if(EaglerAdapter.isSSLPage()) {
this.drawCenteredString(this.fontRenderer, var4.translateKey("addServer.SSLWarn1"), this.width / 2, 169, 0xccccff);
this.drawCenteredString(this.fontRenderer, var4.translateKey("addServer.SSLWarn2"), this.width / 2, 181, 0xccccff);
}
this.serverName.drawTextBox();
this.serverAddress.drawTextBox();
super.drawScreen(par1, par2, par3);
}
}

View File

@ -35,7 +35,12 @@ public class GuiScreenConnectOption extends GuiScreen {
}else if(par1GuiButton.id == 1) {
mc.displayGuiScreen(new GuiScreenDirectConnect(guiScreen, guiScreen.getTheServerData()));
}else if(par1GuiButton.id == 2) {
mc.displayGuiScreen(new GuiScreenLANConnect(guiScreen));
GuiScreen scn = new GuiScreenLANConnect(guiScreen);
if(IntegratedServer.relayManager.count() == 0) {
mc.displayGuiScreen(new GuiNoRelays(guiScreen));
}else {
mc.displayGuiScreen(scn);
}
}
}

View File

@ -1,9 +1,11 @@
package net.lax1dude.eaglercraft;
import net.minecraft.client.Minecraft;
import net.minecraft.src.EnumChatFormatting;
import net.minecraft.src.Gui;
import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.GuiScreenConfirmation;
import net.minecraft.src.StringTranslate;
public class GuiScreenRelay extends GuiScreen {
@ -11,13 +13,12 @@ public class GuiScreenRelay extends GuiScreen {
private final GuiScreen screen;
private GuiSlotRelay slots;
private boolean hasPinged;
private boolean addingNew = false;
private boolean deleting = false;
int selected;
private GuiButton addRelay;
private GuiButton deleteRelay;
private GuiButton setPrimary;
private GuiButton refresh;
private GuiButton loadDefault;
private String tooltipString = null;
@ -29,12 +30,12 @@ public class GuiScreenRelay extends GuiScreen {
selected = -1;
StringTranslate var1 = StringTranslate.getInstance();
buttonList.clear();
buttonList.add(new GuiButton(0, this.width / 2 + 54, this.height - 28, 100, 20, var1.translateKey("gui.cancel")));
buttonList.add(addRelay = new GuiButton(1, this.width / 2 - 154, this.height - 52, 100, 20, var1.translateKey("networkSettings.add")));
buttonList.add(new GuiButton(0, this.width / 2 + 54, this.height - 28, 100, 20, var1.translateKey("gui.done")));
buttonList.add(new GuiButton(1, this.width / 2 - 154, this.height - 52, 100, 20, var1.translateKey("networkSettings.add")));
buttonList.add(deleteRelay = new GuiButton(2, this.width / 2 - 50, this.height - 52, 100, 20, var1.translateKey("networkSettings.delete")));
buttonList.add(setPrimary = new GuiButton(3, this.width / 2 + 54, this.height - 52, 100, 20, var1.translateKey("networkSettings.default")));
buttonList.add(refresh = new GuiButton(4, this.width / 2 - 50, this.height - 28, 100, 20, var1.translateKey("networkSettings.refresh")));
buttonList.add(loadDefault = new GuiButton(5, this.width / 2 - 154, this.height - 28, 100, 20, var1.translateKey("networkSettings.loadDefaults")));
buttonList.add(new GuiButton(4, this.width / 2 - 50, this.height - 28, 100, 20, var1.translateKey("networkSettings.refresh")));
buttonList.add(new GuiButton(5, this.width / 2 - 154, this.height - 28, 100, 20, var1.translateKey("networkSettings.loadDefaults")));
updateButtons();
this.slots = new GuiSlotRelay(this);
if(!hasPinged) {
@ -45,28 +46,37 @@ public class GuiScreenRelay extends GuiScreen {
void updateButtons() {
if(selected < 0) {
addRelay.enabled = false;
deleteRelay.enabled = false;
setPrimary.enabled = false;
loadDefault.enabled = false;
}else {
addRelay.enabled = true;
deleteRelay.enabled = true;
setPrimary.enabled = true;
loadDefault.enabled = true;
}
}
public void actionPerformed(GuiButton btn) {
if(btn.id == 0) {
mc.displayGuiScreen(screen);
} else if(btn.id == 4) {
slots.relayManager.ping();
} else if(btn.id == 1) {
addingNew = true;
mc.displayGuiScreen(new GuiScreenAddRelay(this));
} else if(btn.id == 2) {
StringTranslate var1 = StringTranslate.getInstance();
if(selected >= 0) {
RelayServer srv = IntegratedServer.relayManager.get(selected);
mc.displayGuiScreen(new GuiScreenConfirmation(this, var1.translateKey("networkSettings.delete"), var1.translateKey("addRelay.removeText1"),
EnumChatFormatting.GRAY + "'" + srv.comment + "' (" + srv.address + ")", selected));
deleting = true;
}
} else if(btn.id == 3) {
if(selected >= 0) {
slots.relayManager.setPrimary(selected);
selected = 0;
}
} else if(btn.id == 4) {
slots.relayManager.ping();
} else if(btn.id == 5) {
slots.relayManager.loadDefaults();
}
}
@ -107,6 +117,30 @@ public class GuiScreenRelay extends GuiScreen {
void setToolTip(String str) {
tooltipString = str;
}
String addNewName;
String addNewAddr;
boolean addNewPrimary;
public void confirmClicked(boolean par1, int par2) {
if(par1) {
if(addingNew) {
IntegratedServer.relayManager.addNew(addNewAddr, addNewName, addNewPrimary);
addNewAddr = null;
addNewName = null;
addNewPrimary = false;
selected = -1;
updateButtons();
}else if(deleting) {
IntegratedServer.relayManager.remove(par2);
selected = -1;
updateButtons();
}
}
addingNew = false;
deleting = false;
this.mc.displayGuiScreen(this);
}
static Minecraft getMinecraft(GuiScreenRelay screen) {
return screen.mc;

View File

@ -13,18 +13,12 @@ public class RelayManager {
private final List<RelayServer> relays = new ArrayList();
private long lastPingThrough = 0l;
public RelayManager() {
relays.add(new RelayServer("wss://addr1/", "relay #1", true));
relays.add(new RelayServer("wss://addr2/", "relay #2", false));
relays.add(new RelayServer("wss://addr3/", "relay #3", false));
}
public void load(NBTTagList relayConfig) {
relays.clear();
if(relayConfig.tagCount() > 0) {
boolean gotAPrimary = false;
for(int i = 0, l = relayConfig.tagCount(); i < l; ++i) {
NBTBase relay = relayConfig.tagAt(l);
NBTBase relay = relayConfig.tagAt(i);
if(relay instanceof NBTTagCompound) {
NBTTagCompound relayee = (NBTTagCompound) relay;
boolean p = relayee.getBoolean("primary");
@ -47,6 +41,20 @@ public class RelayManager {
sort();
}
public void save() {
NBTTagList lst = new NBTTagList();
for(int i = 0, l = relays.size(); i < l; ++i) {
RelayServer srv = relays.get(i);
NBTTagCompound etr = new NBTTagCompound();
etr.setString("addr", srv.address);
etr.setString("comment", srv.comment);
etr.setBoolean("primary", srv.isPrimary());
lst.appendTag(etr);
}
LocalStorageManager.gameSettingsStorage.setTag("relays", lst);
LocalStorageManager.saveStorageG();
}
private void sort() {
if(relays.size() == 0) {
return;
@ -112,11 +120,30 @@ public class RelayManager {
int i = relays.size();
relays.add(new RelayServer(addr, comment, false));
if(primary) {
setPrimary(i);
setPrimary0(i);
}
save();
}
public void addNew(String addr, String comment, boolean primary) {
lastPingThrough = 0l;
int i = relays.size();
int j = primary || i == 0 ? 0 : 1;
RelayServer newServer = new RelayServer(addr, comment, false);
relays.add(j, newServer);
newServer.ping();
if(primary) {
setPrimary0(j);
}
save();
}
public void setPrimary(int idx) {
setPrimary0(idx);
save();
}
public void setPrimary(int idx) {
private void setPrimary0(int idx) {
if(idx >= 0 && idx < relays.size()) {
for(int i = 0, l = relays.size(); i < l; ++i) {
RelayServer srv = relays.get(i);
@ -134,6 +161,7 @@ public class RelayManager {
RelayServer srv = relays.remove(idx);
srv.close();
sort();
save();
}
public RelayServer getPrimary() {
@ -145,6 +173,7 @@ public class RelayManager {
}
}
sort();
save();
return getPrimary();
}else {
return null;
@ -198,4 +227,36 @@ public class RelayManager {
}
}
public void loadDefaults() {
int setPrimary = relays.size();
eee: for(RelayEntry etr : ConfigConstants.relays) {
for(RelayServer exEtr : relays) {
if(exEtr.address.equalsIgnoreCase(etr.address)) {
continue eee;
}
}
relays.add(new RelayServer(etr));
}
setPrimary(setPrimary);
}
public String makeNewRelayName() {
String str = "Relay Server #" + (relays.size() + 1);
for(int i = relays.size() + 2, l = relays.size() + 50; i < l; ++i) {
if(str.equalsIgnoreCase("Relay Server #" + i)) {
str = "Relay Server #" + (i + 1);
}
}
eee: while(true) {
for(int i = 0, l = relays.size(); i < l; ++i) {
if(str.equalsIgnoreCase(relays.get(i).comment)) {
str = str + "_";
continue eee;
}
}
break;
}
return str;
}
}

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.IntegratedServer;
import net.lax1dude.eaglercraft.TextureLocation;
import net.lax1dude.eaglercraft.adapter.Tessellator;
import net.minecraft.client.Minecraft;
@ -74,26 +75,33 @@ class GuiSlotServer extends GuiSlot {
}
private void func_77249_c(int par1, int par2, int par3, int par4, Tessellator par5Tessellator) {
this.parentGui.drawCenteredString(this.parentGui.fontRenderer,
StatCollector.translateToLocal("lanServer.scanning"), this.parentGui.width / 2, par3 + 6, 16777215);
String var6;
switch (GuiMultiplayer.getTicksOpened(this.parentGui) / 3 % 4) {
case 0:
default:
var6 = "O o o";
break;
case 1:
case 3:
var6 = "o O o";
break;
case 2:
var6 = "o o O";
if(IntegratedServer.relayManager.count() == 0) {
this.parentGui.drawCenteredString(this.parentGui.fontRenderer,
StatCollector.translateToLocal("noRelay.noRelay1"), this.parentGui.width / 2, par3 + 6, 16777215);
this.parentGui.drawCenteredString(this.parentGui.fontRenderer,
StatCollector.translateToLocal("noRelay.noRelay2"), this.parentGui.width / 2, par3 + 18, 0xFFAAAAAA);
}else {
this.parentGui.drawCenteredString(this.parentGui.fontRenderer,
StatCollector.translateToLocal("lanServer.scanning"), this.parentGui.width / 2, par3 + 6, 16777215);
String var6;
switch (GuiMultiplayer.getTicksOpened(this.parentGui) / 3 % 4) {
case 0:
default:
var6 = "O o o";
break;
case 1:
case 3:
var6 = "o O o";
break;
case 2:
var6 = "o o O";
}
this.parentGui.drawCenteredString(this.parentGui.fontRenderer, var6, this.parentGui.width / 2, par3 + 18, 8421504);
}
this.parentGui.drawCenteredString(this.parentGui.fontRenderer, var6, this.parentGui.width / 2, par3 + 18, 8421504);
}
private static final TextureLocation icons = new TextureLocation("/gui/icons.png");

View File

@ -13,6 +13,7 @@ import org.json.JSONObject;
import net.lax1dude.eaglercraft.Base64;
import net.lax1dude.eaglercraft.ConfigConstants;
import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.IntegratedServer;
import net.lax1dude.eaglercraft.LocalStorageManager;
import net.lax1dude.eaglercraft.RelayEntry;
import net.lax1dude.eaglercraft.ServerQuery.QueryResponse;
@ -67,6 +68,7 @@ public class ServerList {
tag.setBoolean("default", true);
forcedServers.add(ServerData.getServerDataFromNBTCompound(tag));
}
ConfigConstants.relays = new ArrayList();
} catch (IOException e) {
e.printStackTrace();
}
@ -162,6 +164,7 @@ public class ServerList {
this.servers.add(dat);
this.allServers.add(dat);
}
IntegratedServer.relayManager.load(LocalStorageManager.gameSettingsStorage.getTagList("relays"));
}
/**