Skip to content

Commit

Permalink
Added more fixes
Browse files Browse the repository at this point in the history
* replaced help text
* using sha256 for file (rat) checks
* Send purse as -1 outside of skyblock
  • Loading branch information
Ekwav committed Jun 26, 2024
1 parent c3b0763 commit c010942
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 174 deletions.
26 changes: 3 additions & 23 deletions src/main/java/de/torui/coflsky/CoflSkyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,10 @@ public List getCommandAliases() {

@Override
public String getCommandUsage(ICommandSender sender) {
return HelpText;
return "Sends sub-arguments to the SkyCofl command server\n"
+ "§b/cofl §7will request help text with more info\n";
}

public static final String HelpText = "Available local sub-commands:\n"
+ "§bstart: §7starts a new connection\n"
+ "§bstop: §7stops the connection\n"
+ "§bconnect: §7Connects to a different server\n"
+ "§breset: §7resets all local session information and stops the connection\n"
+ "§bstatus: §7Emits status information\n"
+ "§bsetgui: §7Changes the auction purchase GUI\nServer-Only Commands:";

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
new Thread(() -> {
Expand All @@ -74,7 +67,7 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
//todo: start
//possible workaround for https://github.com/Coflnet/SkyblockMod/issues/48
CoflSky.Wrapper.stop();
sender.addChatMessage(new ChatComponentText("starting connection..."));
sender.addChatMessage(new ChatComponentText("starting SkyCofl connection..."));
CoflSky.Wrapper.startConnection();
break;
case "stop":
Expand All @@ -90,12 +83,6 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
.setChatStyle(new ChatStyle().setChatClickEvent(new ClickEvent(Action.RUN_COMMAND, "/cofl start")))
);
break;
case "debug":
// WSCommandHandler.HandleCommand(new Command(CommandType.Execute, "/me hewwo"), sender.getCommandSenderEntity());
// WSCommandHandler.HandleCommand(new Command(CommandType.WriteToChat, " {\"type\":\"writeToChat\",\"data\":\"{\\\"text\\\":\\\"\\\\nFLIP: º9Goblin Eg\r\n"
// + "g º87,000 -> 13,999 ºg[BUY]\\\",\\\"onClick\\\":\\\"/viewauction f7d7295ca72f43e9876bf6da7424000c\\\",\\\"hover\\\":\\\"\\\"}\"}"), sender.getCommandSenderEntity());
//WSCommandHandler.HandleCommand(new Command(CommandType.PlaySound, "{\"name\":\"random.orb\",\"pitch\":0.5}"), sender.getCommandSenderEntity());
break;
case "callback":
CallbackCommand(args);
break;
Expand Down Expand Up @@ -247,11 +234,6 @@ private static synchronized void SendAfterStart(ICommandSender sender, RawComman
CoflSky.Wrapper.SendMessage(rc);
}

public void ListHelp(ICommandSender sender) {
sender.addChatMessage(new ChatComponentText(HelpText));
sender.addChatMessage(new ChatComponentText(QueryServerCommands.QueryCommands()));
}

public void CallbackCommand(String[] args) {

String command = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
Expand All @@ -263,7 +245,5 @@ public void CallbackCommand(String[] args) {

System.out.println("Sent!");
//}).start();

}

}
2 changes: 1 addition & 1 deletion src/main/java/de/torui/coflsky/WSCommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void cacheMods() {
for (File mods : modFolder.listFiles()) {
modListData.addFilename(mods.getName());
try {
modListData.addFileHashes(FileUtils.getMD5Checksum(mods));
modListData.addFileHashes(FileUtils.getSha256Checksum(mods));
} catch (Exception exception) {
// Highly less likely to happen unless something goes wrong
exception.printStackTrace();
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/de/torui/coflsky/handlers/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ public static void ScoreboardData() {

List<String> scoreBoardLines = getScoreboard();
int size = scoreBoardLines.size() - 1;
boolean foundPurse = false;
for (int i = 0; i < scoreBoardLines.size(); i++) {
String line = EnumChatFormatting.getTextWithoutFormattingCodes(scoreBoardLines.get(size - i).toLowerCase());
if (Configuration.getInstance().collectScoreboard) {
ProcessScoreboard(line);
if(ProcessScoreboard(line))
foundPurse = true;
}
if (line.contains("⏣") && !line.equals(location)) {
location = line;
Expand All @@ -87,6 +89,14 @@ public static void ScoreboardData() {
}
}
}
if(!foundPurse && purse != -1)
{
purse = -1; // no purse found, sync that to server
Command<Long> data = new Command<>(CommandType.updatePurse, purse);
CoflSky.Wrapper.SendMessage(data);
UploadScoreboardData();
UploadTabData();
}
}

private static void UploadLocation() {
Expand Down Expand Up @@ -178,7 +188,7 @@ private static void checkIfInSkyblock(String s) {
}
}

private static void ProcessScoreboard(String line) {
private static boolean ProcessScoreboard(String line) {
if (line.contains("purse") || line.contains("piggy")) {
long purse_ = 0;
try {
Expand All @@ -193,6 +203,7 @@ private static void ProcessScoreboard(String line) {
CoflSky.Wrapper.SendMessage(data);
UploadLocation();
}
return true;
} else if (line.contains("bits")) {
long bits_ = 0;
try {
Expand All @@ -205,6 +216,8 @@ private static void ProcessScoreboard(String line) {
Command<Long> data = new Command<>(CommandType.updateBits, bits);
CoflSky.Wrapper.SendMessage(data);
}
return true;
}
return false;
}
}
143 changes: 0 additions & 143 deletions src/main/java/de/torui/coflsky/network/QueryServerCommands.java

This file was deleted.

9 changes: 4 additions & 5 deletions src/main/java/de/torui/coflsky/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

public class FileUtils {

public static byte[] createChecksum(File file) throws Exception {
private static byte[] createChecksum(File file) throws Exception {
InputStream fis = new FileInputStream(file);

byte[] buffer = new byte[1024];
MessageDigest complete = MessageDigest.getInstance("MD5");
MessageDigest complete = MessageDigest.getInstance("SHA-256");
int numRead;

do {
Expand All @@ -25,16 +25,15 @@ public static byte[] createChecksum(File file) throws Exception {
return complete.digest();
}


public static String getMD5Checksum(File file) throws Exception {
public static String getSha256Checksum(File file) throws Exception {
byte[] b = createChecksum(file);
String result = "";

for (int i=0; i < b.length; i++) {
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
}
System.out.println("MD5: "+result);
return result;
}


}

0 comments on commit c010942

Please sign in to comment.