Skip to content

Commit c69d19d

Browse files
author
adam
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 40fe01c + 8ce0665 commit c69d19d

6 files changed

Lines changed: 97 additions & 34 deletions

File tree

common/src/main/java/com/adamcalculator/dynamicpack/Mod.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Mod {
2121
ALLOWED_HOSTS.add("github.com");
2222
ALLOWED_HOSTS.add("github.io");
2323
ALLOWED_HOSTS.add("githubusercontent.com");
24-
if (!isRelease()) {
24+
if (isLocalHostAllowed()) {
2525
ALLOWED_HOSTS.add("localhost");
2626
}
2727
}
@@ -60,4 +60,24 @@ private static long megabyte(long mb) {
6060
public static boolean isRelease() {
6161
return true;
6262
}
63+
64+
// localhost allowed
65+
private static boolean isLocalHostAllowed() {
66+
return false;
67+
}
68+
69+
// file_debug_only:// allowed
70+
public static boolean isFileDebugSchemeAllowed() {
71+
return false;
72+
}
73+
74+
// http:// allowed
75+
public static boolean isHTTPTrafficAllowed() {
76+
return false;
77+
}
78+
79+
// DebugScreen allowed
80+
public static boolean isDebugScreenAllowed() {
81+
return true;
82+
}
6383
}

common/src/main/java/com/adamcalculator/dynamicpack/SyncingTask.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void run() {
2222
try {
2323
pack.sync(createSyncProgressForPack(pack), manually);
2424
} catch (Exception e) {
25+
onError(pack, e);
2526
Out.error("error while process pack: " + pack.getLocation().getName(), e);
2627
}
2728
}
@@ -33,6 +34,10 @@ public void syncDone(boolean reloadRequired) {
3334
// to override
3435
}
3536

37+
public void onError(Pack pack, Exception e) {
38+
// to override
39+
}
40+
3641
public boolean isReloadRequired() {
3742
return reloadRequired;
3843
}

common/src/main/java/com/adamcalculator/dynamicpack/util/Urls.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
import java.util.zip.GZIPInputStream;
1515

1616
public class Urls {
17-
public static boolean isFileDebugScheme() {
18-
return !Mod.isRelease();
17+
public static boolean isFileDebugSchemeAllowed() {
18+
return Mod.isFileDebugSchemeAllowed();
19+
}
20+
21+
public static boolean isHTTPTrafficAllowed() {
22+
return Mod.isHTTPTrafficAllowed();
1923
}
2024

2125
public static String parseContentAndVerify(String signatureUrl, String url, String publicKeyBase64, long maxLimit) throws IOException {
@@ -99,8 +103,13 @@ private static InputStream _getInputStreamOfUrl(String url, long sizeLimit) thro
99103
}
100104

101105
private static InputStream _getInputStreamOfUrl(String url, long sizeLimit, /*@Nullable*/ LongConsumer progress) throws IOException {
106+
if (url.contains(" ")) {
107+
throw new IOException("URL can't contains spaces!");
108+
}
109+
110+
102111
if (url.startsWith("file_debug_only://")) {
103-
if (!isFileDebugScheme()) {
112+
if (!isFileDebugSchemeAllowed()) {
104113
throw new RuntimeException("Not allowed scheme.");
105114
}
106115

@@ -113,7 +122,26 @@ private static InputStream _getInputStreamOfUrl(String url, long sizeLimit, /*@N
113122

114123

115124
} else if (url.startsWith("http://")) {
116-
throw new RuntimeException("HTTP (not secure) not allowed scheme.");
125+
if (!isHTTPTrafficAllowed()) {
126+
throw new RuntimeException("HTTP (not secure) not allowed scheme.");
127+
}
128+
129+
if (!Mod.isUrlHostTrusted(url)) {
130+
if (Mod.isBlockAllNotTrustedNetworks()) {
131+
throw new SecurityException("Url host is not trusted!");
132+
}
133+
}
134+
135+
URL urlObj = new URL(url);
136+
URLConnection connection = urlObj.openConnection();
137+
long length = connection.getContentLengthLong();
138+
if (length > sizeLimit) {
139+
throw new RuntimeException("[HTTP] File at " + url+ " so bigger. " + length + " > " + sizeLimit);
140+
}
141+
if (progress != null){
142+
progress.accept(length);
143+
}
144+
return connection.getInputStream();
117145

118146

119147
} else if (url.startsWith("https://")) {
@@ -123,9 +151,6 @@ private static InputStream _getInputStreamOfUrl(String url, long sizeLimit, /*@N
123151
}
124152
}
125153

126-
if (url.contains(" ")) {
127-
Out.warn("URL " + url + " contains not encoded spaced! Use %20 for space symbol in links!");
128-
}
129154
URL urlObj = new URL(url);
130155
URLConnection connection = urlObj.openConnection();
131156
long length = connection.getContentLengthLong();

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ loader_version=0.15.7
1212
fabric_version=0.92.0+1.20.1
1313

1414
# Mod Properties
15-
mod_version=1.0.5-mc1.20.1
15+
mod_version=1.0.6-mc1.20.1
1616
maven_group=com.adamcalculator
1717
archives_base_name=dynamicpack

src/client/java/com/adamcalculator/dynamicpack/DebugScreen.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,49 @@ protected void init() {
4040
SystemToast toast = new SystemToast(SystemToast.Type.NARRATOR_TOGGLE, Text.literal("T"), Text.literal("d"));
4141
MinecraftClient.getInstance().getToastManager().add(toast);
4242

43-
try {
44-
pack.sync(new SyncProgress() {
45-
@Override
46-
public void textLog(String s) {
47-
toast.setContent(Text.literal("Log"), Text.literal(s));
48-
}
43+
var task = new SyncingTask(true) {
44+
@Override
45+
public void syncDone(boolean reloadRequired) {
46+
toast.setContent(Text.literal("Error"), Text.literal("rel_req="+reloadRequired));
47+
}
4948

50-
@Override
51-
public void done(boolean b) {
52-
if (b) {
53-
toast.setContent(Text.literal("Done. Reload!"), Text.literal("Reload required!!!"));
54-
} else {
55-
toast.setContent(Text.literal("Done!"), Text.literal(""));
56-
}
57-
}
49+
@Override
50+
public void onError(Pack pack, Exception e) {
51+
toast.setContent(Text.literal("Error"), Text.literal(e.getMessage()));
52+
}
5853

59-
@Override
60-
public void downloading(String name, float percentage) {
54+
@Override
55+
public SyncProgress createSyncProgressForPack(Pack pack) {
56+
return new SyncProgress() {
57+
@Override
58+
public void textLog(String s) {
59+
toast.setContent(Text.literal("Log"), Text.literal(s));
60+
}
6161

62-
}
62+
@Override
63+
public void done(boolean b) {
64+
if (b) {
65+
toast.setContent(Text.literal("Done. Reload!"), Text.literal("Reload required!!!"));
66+
} else {
67+
toast.setContent(Text.literal("Done!"), Text.literal(""));
68+
}
69+
}
6370

64-
@Override
65-
public void start() {
71+
@Override
72+
public void downloading(String name, float percentage) {
73+
toast.setContent(Text.literal("Download " + Math.round(percentage) + "%"), Text.literal(name));
74+
}
6675

67-
}
68-
}, true);
69-
} catch (Exception e) {
70-
Out.e(e);
71-
}
76+
@Override
77+
public void start() {
78+
toast.setContent(Text.literal("Started!"), Text.literal(""));
79+
}
80+
};
81+
}
82+
};
83+
new Thread(task, "DynamicPack-ManuallyCheckThread").start();
7284
}).size(50, 20).position(190, height).build());
85+
7386
} catch (Exception e) {
7487
addDrawableChild(ButtonWidget.builder(Text.of(e + ""), button -> {
7588
}).size(500, 20).position(10, height).build());

src/client/java/com/adamcalculator/dynamicpack/ModMenu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
public class ModMenu implements ModMenuApi {
77
@Override
88
public ConfigScreenFactory<?> getModConfigScreenFactory() {
9-
return Mod.isRelease() ? null : parent -> new DebugScreen();
9+
return Mod.isDebugScreenAllowed() ? parent -> new DebugScreen() : null;
1010
}
1111
}

0 commit comments

Comments
 (0)