diff --git a/src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatus.java b/src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatus.java new file mode 100644 index 0000000..57cd081 --- /dev/null +++ b/src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatus.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * DarkForge a Forge Hacked Client + * Copyright (C) 2017 Hexeption (Keir Davis) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ******************************************************************************/ + +package uk.co.hexeption.darkforge.gui.screen; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; + +import java.io.IOException; + +/** + * Created by Hexeption on 09/04/2017. + */ +public class GuiStatus extends GuiScreen { + + private GuiScreen lastScreen; + + private GuiStatusSlot slots; + + + public GuiStatus(GuiScreen lastScreen) { + + this.lastScreen = lastScreen; + } + + @Override + public void initGui() { + + this.slots = new GuiStatusSlot(this); + this.slots.registerScrollButtons(7, 8); + this.slots.elementClicked(-1, false, 0, 0); + this.buttonList.clear(); + this.buttonList.add(new GuiButton(0, width / 2 - 67, height - 26, 65, 20, "Back")); + this.buttonList.add(new GuiButton(1, width / 2 + 2, height - 26, 65, 20, "Refresh")); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + + this.drawDefaultBackground(); + this.slots.drawScreen(mouseX, mouseY, partialTicks); + this.drawCenteredString(this.fontRendererObj, "Status", this.width / 2, 6, 16777215); + this.drawCenteredString(this.fontRendererObj, "Check if a certain services is online.", this.width / 2, 16, 16777215); + super.drawScreen(mouseX, mouseY, partialTicks); + + } + + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + + if (keyCode == 28 || keyCode == 156) { + actionPerformed(buttonList.get(0)); + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + + if (mouseY >= 36 && mouseY <= height - 46) + if (mouseX >= width / 2 + 140 || mouseX <= width / 2 - 126) { + this.slots.elementClicked(-1, false, 0, 0); + } + + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + public void handleMouseInput() throws IOException { + + super.handleMouseInput(); + this.slots.handleMouseInput(); + } + + @Override + protected void actionPerformed(GuiButton button) throws IOException { + + switch (button.id) { + case 0: + this.mc.displayGuiScreen(lastScreen); + break; + case 1: + this.slots.updateList(); + break; + } + } +} diff --git a/src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatusSlot.java b/src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatusSlot.java new file mode 100644 index 0000000..d7e7086 --- /dev/null +++ b/src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatusSlot.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * DarkForge a Forge Hacked Client + * Copyright (C) 2017 Hexeption (Keir Davis) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ******************************************************************************/ + +package uk.co.hexeption.darkforge.gui.screen; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiSlot; + +import java.awt.*; +import java.util.ArrayList; + +/** + * Created by Hexeption on 09/04/2017. + */ +public class GuiStatusSlot extends GuiSlot { + + private ArrayList statusItems = new ArrayList(); + + public GuiStatusSlot(GuiStatus gui) { + + super(Minecraft.getMinecraft(), gui.width, gui.height, 32, gui.height - 45, 35); + + this.statusItems.add(new StatusItem("Minecraft.net", "minecraft.net")); + this.statusItems.add(new StatusItem("Mojang.com", "mojang.com")); + this.statusItems.add(new StatusItem("Sessions", "session.minecraft.net")); + this.statusItems.add(new StatusItem("Accounts", "account.mojang.com")); + this.statusItems.add(new StatusItem("Auth", "auth.mojang.com")); + this.statusItems.add(new StatusItem("Auth Server", "authserver.mojang.com")); + this.statusItems.add(new StatusItem("Session Server", "sessionserver.mojang.com")); + this.statusItems.add(new StatusItem("Skins", "skins.minecraft.net")); + this.statusItems.add(new StatusItem("CDN", "textures.minecraft.net")); + this.statusItems.add(new StatusItem("API", "api.mojang.com")); + + updateList(); + + } + + public void updateList() { + + for (StatusItem item : this.statusItems) + item.check(); + } + + @Override + protected int getSize() { + + return this.statusItems.size(); + } + + @Override + protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY) { + + if (isDoubleClick) { + this.statusItems.get(slotIndex).check(); + } + } + + @Override + protected boolean isSelected(int slotIndex) { + + return false; + } + + @Override + protected void drawBackground() { + + } + + @Override + protected void drawSlot(int entryID, int insideLeft, int yPos, int insideSlotHeight, int mouseXIn, int mouseYIn) { + + StatusItem item = this.statusItems.get(entryID); + mc.ingameGUI.drawCenteredString(mc.fontRendererObj, item.getName(), width / 2, yPos + 2, Color.white.hashCode()); + yPos += 10; + mc.ingameGUI.drawCenteredString(mc.fontRendererObj, "Status: " + item.getStatus(), width / 2, yPos + 2, Color.white.hashCode()); + + yPos += 10; + mc.ingameGUI.drawCenteredString(mc.fontRendererObj, "Ping: " + item.getPing(), width / 2, yPos + 2, Color.white.hashCode()); + + } +} diff --git a/src/main/java/uk/co/hexeption/darkforge/gui/screen/StatusItem.java b/src/main/java/uk/co/hexeption/darkforge/gui/screen/StatusItem.java new file mode 100644 index 0000000..4547396 --- /dev/null +++ b/src/main/java/uk/co/hexeption/darkforge/gui/screen/StatusItem.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * DarkForge a Forge Hacked Client + * Copyright (C) 2017 Hexeption (Keir Davis) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ******************************************************************************/ + +package uk.co.hexeption.darkforge.gui.screen; + +import net.minecraft.util.text.TextFormatting; +import uk.co.hexeption.darkforge.utils.URLUtils; + +import java.net.URL; + +/** + * Created by Hexeption on 09/04/2017. + */ +public class StatusItem { + + private String name; + + private String service; + + private int status; + + private long ping; + + public StatusItem(String name, String service) { + + this.name = name; + this.service = service; + this.status = 3; + this.ping = -1L; + } + + public void check() { + + new Thread(() -> { + + try { + long startTime = System.currentTimeMillis(); + StatusItem.this.status = 3; + if (((String) URLUtils.getWebsiteContents(new URL("http://status.mojang.com/check?service=" + StatusItem.this.service)).get(0)).contains("green")) { + StatusItem.this.status = 1; + StatusItem.this.ping = (System.currentTimeMillis() - startTime); + } else { + StatusItem.this.status = 0; + } + } catch (Exception e) { + StatusItem.this.status = 2; + } + + }).start(); + } + + public String getStatus() { + + if (this.status == 0) { + return TextFormatting.RED + "Offline"; + + } + if (this.status == 1) { + return TextFormatting.GREEN + "Online"; + + } + if (this.status == 2) { + return TextFormatting.RED + "Error"; + + } + return TextFormatting.GOLD + "Loading.."; + } + + public String getPing() { + + if (this.ping == -1L) { + return "N/A"; + } + if (this.ping >= 1000L) { + return Long.toString(this.ping / 1000L) + "s"; + } + + return Long.toString(this.ping) + "ms"; + } + + public String getName() { + + return name; + } + + public String getService() { + + return service; + } +} diff --git a/src/main/java/uk/co/hexeption/darkforge/utils/URLUtils.java b/src/main/java/uk/co/hexeption/darkforge/utils/URLUtils.java new file mode 100644 index 0000000..4ab0c96 --- /dev/null +++ b/src/main/java/uk/co/hexeption/darkforge/utils/URLUtils.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * DarkForge a Forge Hacked Client + * Copyright (C) 2017 Hexeption (Keir Davis) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ******************************************************************************/ + +package uk.co.hexeption.darkforge.utils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; + +/** + * Created by Hexeption on 09/04/2017. + */ +public class URLUtils { + + public static ArrayList getWebsiteContents(URL url) throws Exception { + + ArrayList fileContents = new ArrayList(); + BufferedReader fileReader = new BufferedReader(new InputStreamReader(url.openStream())); + + String fileLine = ""; + while ((fileLine = fileReader.readLine()) != null) { + if (!fileLine.equals("")) { + fileContents.add(fileLine); + } + } + + fileReader.close(); + return fileContents; + } + +} diff --git a/src/main/java/uk/co/hexeption/mcwrapper/mixin/client/gui/MixinGuiMultiplayer.java b/src/main/java/uk/co/hexeption/mcwrapper/mixin/client/gui/MixinGuiMultiplayer.java new file mode 100644 index 0000000..ac8ff69 --- /dev/null +++ b/src/main/java/uk/co/hexeption/mcwrapper/mixin/client/gui/MixinGuiMultiplayer.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * DarkForge a Forge Hacked Client + * Copyright (C) 2017 Hexeption (Keir Davis) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + ******************************************************************************/ + +package uk.co.hexeption.mcwrapper.mixin.client.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiMultiplayer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import uk.co.hexeption.darkforge.gui.screen.GuiStatus; + +/** + * Created by Hexeption on 09/04/2017. + */ +@Mixin(GuiMultiplayer.class) +public class MixinGuiMultiplayer extends GuiScreen { + + + @Inject(method = "initGui", at = @At("RETURN")) + public void init(CallbackInfo callbackInfo) { + + ScaledResolution scaledResolution = new ScaledResolution(mc); + int right = scaledResolution.getScaledWidth() - 3; + this.buttonList.add(new GuiButton(100, 5, 3, 100, 20, "MC Status")); + this.buttonList.add(new GuiButton(101, right - 103, 3, 100, 20, "Proxy")); + } + + @Inject(method = "actionPerformed", at = @At("HEAD")) + public void onButtonClick(GuiButton button, CallbackInfo callbackInfo) { + + if (button.id == 100) { + mc.displayGuiScreen(new GuiStatus(this)); + } + + if (button.id == 101) { + + } + } + +} diff --git a/src/main/resources/mixins.mcwrapper.json b/src/main/resources/mixins.mcwrapper.json index fd02f04..5348ce6 100644 --- a/src/main/resources/mixins.mcwrapper.json +++ b/src/main/resources/mixins.mcwrapper.json @@ -6,6 +6,7 @@ "mixins": [ "MixinMinecraft", "client.gui.MixinGuiInGame", + "client.gui.MixinGuiMultiplayer", "entity.MixinEntity", "entity.living.MixinEntityLiving", "entity.living.player.MixinEntityPlayer",