Skip to content

Commit

Permalink
更改HTTP User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamVoid committed Aug 13, 2024
1 parent 08ad3ce commit 09365be
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions MiraiMC-Base/src/main/java/me/dreamvoid/miraimc/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface Platform {
PluginConfig getPluginConfig();

LibraryLoader getLibraryLoader();

String getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import me.dreamvoid.miraimc.LifeCycle;
import me.dreamvoid.miraimc.internal.config.PluginConfig;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -123,7 +124,7 @@ public static String get(String url) throws IOException {

connection.setDoInput(true);
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 DreamVoid MiraiMC");
connection.setRequestProperty("User-Agent", String.format("MiraiMC/%s (%s; %s)", LifeCycle.getPlatform().getPluginVersion(), LifeCycle.getPlatform().getType(), System.getProperty("os.name")));
connection.setConnectTimeout(5000);
connection.setReadTimeout(10000);

Expand Down Expand Up @@ -152,7 +153,7 @@ public static String post(JsonObject json, String url) throws IOException {

connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 DreamVoid MiraiMC");
connection.setRequestProperty("User-Agent", String.format("MiraiMC/%s (%s; %s)", LifeCycle.getPlatform().getPluginVersion(), LifeCycle.getPlatform().getType(), System.getProperty("os.name")));
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Authorization", "Basic YWRtaW46");
connection.setConnectTimeout(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,9 @@ public PluginConfig getPluginConfig() {
public LibraryLoader getLibraryLoader() {
return loader;
}

@Override
public String getType() {
return "Bukkit";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ public ClassLoader getPluginClassLoader() {
public LibraryLoader getLibraryLoader() {
return loader;
}

@Override
public String getType() {
return "Paper";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ public LibraryLoader getLibraryLoader() {
return loader;
}

@Override
public String getType() {
return "BungeeCord";
}

@Override
public void runTaskLaterAsync(Runnable task, long delay) {
getProxy().getScheduler().schedule(this,task, delay * 50, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,9 @@ public PluginConfig getPluginConfig() {
public LibraryLoader getLibraryLoader() {
return loader;
}

@Override
public String getType() {
return "Nukkit";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,9 @@ public PluginConfig getPluginConfig() {
public LibraryLoader getLibraryLoader() {
return loader;
}

@Override
public String getType() {
return "Sponge";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,9 @@ public PluginConfig getPluginConfig() {
public LibraryLoader getLibraryLoader() {
return loader;
}

@Override
public String getType() {
return "Velocity";
}
}

0 comments on commit 09365be

Please sign in to comment.