This repository has been archived by the owner on Feb 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
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; | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/java/uk/co/hexeption/darkforge/gui/screen/GuiStatusSlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
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<StatusItem> 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()); | ||
|
||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/main/java/uk/co/hexeption/darkforge/gui/screen/StatusItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
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; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/uk/co/hexeption/darkforge/utils/URLUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
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; | ||
} | ||
|
||
} |
Oops, something went wrong.