Skip to content
Merged

Dev #167

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies{

implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.2'

annotationProcessor 'org.projectlombok:lombok:1.18.32'
annotationProcessor "com.github.Anuken:jabel:$jabelVersion"
Expand Down
2 changes: 1 addition & 1 deletion mod.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ description:
[#FAA31B[]]  Reddit: [white[]]r/MindustryTool[[]]
[#EF4444[]]  YouTube: [white[]]Mindustry Tool[[]]
'''
version: v4.45.1-v8
version: v4.46.0-v8

minGameVersion: 154

Expand Down
2 changes: 2 additions & 0 deletions src/mindustrytool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import mindustrytool.features.display.wavepreview.WavePreviewFeature;
import mindustrytool.features.chat.translation.ChatTranslationFeature;
import mindustrytool.features.chat.pretty.PrettyChatFeature;
import mindustrytool.features.savesync.SaveSyncFeature;

public class Main extends Mod {
public static LoadedMod self;
Expand Down Expand Up @@ -114,6 +115,7 @@ public void init() {
new PrettyChatFeature(),
new AutoplayFeature(),
new WavePreviewFeature(),
new SaveSyncFeature(),
// new ItemVisualizerFeature(),
new GodModeFeature(),
new SmartDrillFeature(),
Expand Down
32 changes: 29 additions & 3 deletions src/mindustrytool/Utils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mindustrytool;

import java.io.IOException;

import arc.Core;
import arc.graphics.Texture;
import arc.graphics.g2d.TextureRegion;
Expand All @@ -27,13 +25,16 @@
import mindustry.world.blocks.storage.*;

import java.io.*;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.*;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import static mindustry.Vars.*;

Expand All @@ -44,7 +45,9 @@ public class Utils {
private static final byte[] header = { 'm', 's', 'c', 'h' };

private static final ObjectMapper mapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.registerModule(new JavaTimeModule());

public static synchronized Schematic readSchematic(String data) {
return schematicData.get(data, () -> readBase64(data));
Expand Down Expand Up @@ -223,4 +226,27 @@ public static TextureRegionDrawable icons(String name) {
return Icon.book;
}
}

public static String sha256(File file) throws Exception {
MessageDigest digest = MessageDigest.getInstance("SHA-256");

try (InputStream fis = new FileInputStream(file);
DigestInputStream dis = new DigestInputStream(fis, digest)) {

byte[] buffer = new byte[8192];
while (dis.read(buffer) != -1) {
// just read to update digest
}
}

return bytesToHex(digest.digest());
}

private static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}
19 changes: 13 additions & 6 deletions src/mindustrytool/features/auth/AuthHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public static void get(String url, ConsT<HttpResponse, Exception> success, Cons<
get(url).submit(success, failure);
}

public static void delete(String url, ConsT<HttpResponse, Exception> success, Cons<Throwable> failure) {
delete(url).submit(success, failure);
}

public static AuthRequest delete(String url) {
return new AuthRequest(url, HttpMethod.DELETE);
}
Comment on lines +29 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the full AuthHttp.java file to understand structure
wc -l src/mindustrytool/features/auth/AuthHttp.java

Repository: MindustryTool/MindustryToolMod

Length of output: 123


🏁 Script executed:

#!/bin/bash
# Look for AuthRequest class definition and submit method
rg -n 'class AuthRequest|public.*submit|HttpMethod|Http\.post|Http\.get|Http\.delete' src/mindustrytool/features/auth/AuthHttp.java -A 2

Repository: MindustryTool/MindustryToolMod

Length of output: 1355


🏁 Script executed:

#!/bin/bash
# Find where AuthRequest is defined (might be in same file or separate)
find . -name "*.java" -type f | xargs rg -l "class AuthRequest" 2>/dev/null | head -5

Repository: MindustryTool/MindustryToolMod

Length of output: 121


🏁 Script executed:

#!/bin/bash
# Read the submit() method completely to confirm the routing logic
sed -n '64,85p' src/mindustrytool/features/auth/AuthHttp.java

Repository: MindustryTool/MindustryToolMod

Length of output: 955


delete() sends POST requests instead of DELETE.

The delete() method creates an AuthRequest with HttpMethod.DELETE (lines 34–35), but the submit() method only routes based on if (method == HttpMethod.GET), falling through to Http.post(...) for all non-GET requests (lines 73–77). Add explicit handling for HttpMethod.DELETE to use Http.delete(...) instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/mindustrytool/features/auth/AuthHttp.java` around lines 29 - 35, The
AuthRequest.submit logic currently treats every non-GET as POST causing
AuthHttp.delete(...) to send POST; update the submit method in AuthRequest to
explicitly handle HttpMethod.DELETE by adding a branch similar to the existing
POST branch that calls Http.delete(...) with the same parameters and
headers/exception handling you use for POST, while preserving the existing GET
and POST paths (refer to HttpMethod.GET, HttpMethod.DELETE and the
AuthRequest.submit method).


public static class AuthRequest {
String url;
HttpMethod method;
Expand Down Expand Up @@ -61,12 +69,11 @@ public void submit(ConsT<HttpResponse, Exception> listener, Cons<Throwable> erro
AuthService.getInstance().refreshTokenIfNeeded()
.thenRun(() -> {

HttpRequest req;
if (method == HttpMethod.GET) {
req = Http
.get(url).timeout(10000);
} else {
req = Http.post(url, content).timeout(10000);
HttpRequest req = Http.request(method, url)
.timeout(10000);

if (content != null) {
req.content(content);
}

String token = AuthService.getInstance().getAccessToken();
Expand Down
Loading
Loading