aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-02-05 23:27:14 +0100
committernea <nea@nea.moe>2023-02-05 23:27:14 +0100
commit37234e6cfbb121459f37dca64d6f7dca1b639e47 (patch)
treec4cc00e21632527bfcdd753d1c3f688fcc7414d7
parentd0f024a0cd2525bc4a79308c4f7275ea2a308ab2 (diff)
downloadNotEnoughUpdates-37234e6cfbb121459f37dca64d6f7dca1b639e47.tar.gz
NotEnoughUpdates-37234e6cfbb121459f37dca64d6f7dca1b639e47.tar.bz2
NotEnoughUpdates-37234e6cfbb121459f37dca64d6f7dca1b639e47.zip
ApiUtil: Add developer only user agent override
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java5
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java2
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java9
3 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
index 0d882358..71faec9e 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
@@ -254,5 +254,10 @@ public class DevTestCommand extends ClientCommandBase {
MiscUtils.copyToClipboard(builder.toString());
Utils.addChatMessage("§e[NEU] Copied tablist to clipboard!");
}
+ if(args.length >= 1 && args[0].equalsIgnoreCase("useragent")) {
+ String newUserAgent = args.length == 1 ? null : String.join(" ", Arrays.copyOfRange(args, 1, args.length));
+ Utils.addChatMessage("§e[NEU] Changed user agent override to: " + newUserAgent);
+ NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = newUserAgent;
+ }
}
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
index 371d657e..a289ca51 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
@@ -438,6 +438,8 @@ public class NEUConfig extends Config {
@Expose
public int compareMode = 0;
@Expose
+ public String customUserAgent = null;
+ @Expose
public int sortMode = 0;
@Expose
public ArrayList<Boolean> compareAscending = Lists.newArrayList(true, true, true);
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
index c86ac84f..b5e7c587 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java
@@ -61,7 +61,12 @@ import java.util.zip.GZIPInputStream;
public class ApiUtil {
private static final Gson gson = new Gson();
private static final ExecutorService executorService = Executors.newFixedThreadPool(3);
- private static final String USER_AGENT = "NotEnoughUpdates/" + NotEnoughUpdates.VERSION;
+ private static String getUserAgent() {
+ if(NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent != null) {
+ return NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent;
+ }
+ return "NotEnoughUpdates/" + NotEnoughUpdates.VERSION;
+ }
private static SSLContext ctx;
private final Map<String, CompletableFuture<Void>> updateTasks = new HashMap<>();
@@ -169,7 +174,7 @@ public class ApiUtil {
}
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
- conn.setRequestProperty("User-Agent", USER_AGENT);
+ conn.setRequestProperty("User-Agent", getUserAgent());
if (this.postContentType != null) {
conn.setRequestProperty("Content-Type", this.postContentType);
}