geforkt von Mirrors/Velocity
Velocity Dump Cleanup
Dieser Commit ist enthalten in:
Ursprung
140eaaf5ab
Commit
01070f8fd2
@ -5,7 +5,7 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
@ -21,17 +21,15 @@ import com.velocitypowered.api.util.ProxyVersion;
|
|||||||
import com.velocitypowered.proxy.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
import com.velocitypowered.proxy.util.InformationUtils;
|
import com.velocitypowered.proxy.util.InformationUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.net.ConnectException;
|
||||||
import java.io.InputStreamReader;
|
import java.net.UnknownHostException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
@ -43,6 +41,10 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.asynchttpclient.AsyncHttpClient;
|
||||||
|
import org.asynchttpclient.BoundRequestBuilder;
|
||||||
|
import org.asynchttpclient.ListenableFuture;
|
||||||
|
import org.asynchttpclient.Response;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class VelocityCommand implements SimpleCommand {
|
public class VelocityCommand implements SimpleCommand {
|
||||||
@ -311,6 +313,7 @@ public class VelocityCommand implements SimpleCommand {
|
|||||||
|
|
||||||
private static class Dump implements SubCommand {
|
private static class Dump implements SubCommand {
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger(Dump.class);
|
||||||
private final ProxyServer server;
|
private final ProxyServer server;
|
||||||
|
|
||||||
private Dump(ProxyServer server) {
|
private Dump(ProxyServer server) {
|
||||||
@ -350,89 +353,92 @@ public class VelocityCommand implements SimpleCommand {
|
|||||||
dump.add("plugins", InformationUtils.collectPluginInfo(server));
|
dump.add("plugins", InformationUtils.collectPluginInfo(server));
|
||||||
|
|
||||||
source.sendMessage(Component.text().content("Uploading gathered information...").build());
|
source.sendMessage(Component.text().content("Uploading gathered information...").build());
|
||||||
|
AsyncHttpClient httpClient = ((VelocityServer) server).getAsyncHttpClient();
|
||||||
|
|
||||||
HttpURLConnection upload = null;
|
BoundRequestBuilder request =
|
||||||
try {
|
httpClient.preparePost("https://dump.velocitypowered.com/documents");
|
||||||
upload = (HttpURLConnection) new URL("https://dump.velocitypowered.com/documents")
|
request.setHeader("Content-Type", "text/plain");
|
||||||
.openConnection();
|
request.addHeader("User-Agent", server.getVersion().getName() + "/"
|
||||||
} catch (IOException e1) {
|
+ server.getVersion().getVersion());
|
||||||
// Couldn't open connection;
|
request.setBody(
|
||||||
source.sendMessage(
|
InformationUtils.toHumanReadableString(dump).getBytes(StandardCharsets.UTF_8));
|
||||||
Component.text()
|
|
||||||
.content("Failed to open a connection!")
|
|
||||||
.color(NamedTextColor.RED).build());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
upload.setRequestProperty("Content-Type", "text/plain");
|
|
||||||
upload.addRequestProperty(
|
|
||||||
"User-Agent", server.getVersion().getName() + "/"
|
|
||||||
+ server.getVersion().getVersion());
|
|
||||||
try {
|
|
||||||
upload.setRequestMethod("POST");
|
|
||||||
upload.setDoOutput(true);
|
|
||||||
|
|
||||||
OutputStream uploadStream = upload.getOutputStream();
|
ListenableFuture<Response> future = request.execute();
|
||||||
uploadStream.write(
|
future.addListener(() -> {
|
||||||
InformationUtils.toHumanReadableString(dump).getBytes(StandardCharsets.UTF_8));
|
try {
|
||||||
uploadStream.close();
|
Response response = future.get();
|
||||||
} catch (IOException e2) {
|
if (response.getStatusCode() != 200) {
|
||||||
// Couldn't POST the Data
|
source.sendMessage(Component.text()
|
||||||
source.sendMessage(
|
.content("An error occurred while communicating with the Velocity servers. "
|
||||||
Component.text()
|
+ "The servers may be temporarily unavailable or there is an issue "
|
||||||
.content("Couldn't upload the data!")
|
+ "with your network settings. You can find more information in the "
|
||||||
.color(NamedTextColor.RED).build());
|
+ "log or console of your Velocity server.")
|
||||||
return;
|
.color(NamedTextColor.RED).build());
|
||||||
}
|
logger.error("Invalid status code while POST-ing Velocity dump: "
|
||||||
String rawResponse = null;
|
+ response.getStatusCode());
|
||||||
try {
|
logger.error("Headers: \n--------------BEGIN HEADERS--------------\n"
|
||||||
rawResponse = CharStreams.toString(
|
+ response.getHeaders().toString()
|
||||||
new InputStreamReader(upload.getInputStream(), StandardCharsets.UTF_8));
|
+ "\n---------------END HEADERS---------------");
|
||||||
upload.getInputStream().close();
|
return;
|
||||||
} catch (IOException e3) {
|
}
|
||||||
// Couldn't read response
|
JsonObject key = InformationUtils.parseString(
|
||||||
source.sendMessage(
|
response.getResponseBody(StandardCharsets.UTF_8));
|
||||||
Component.text()
|
if (!key.has("key")) {
|
||||||
.content("Invalid server response received!")
|
throw new JsonSyntaxException("Missing Dump-Url-response");
|
||||||
.color(NamedTextColor.RED).build());
|
}
|
||||||
}
|
String url = "https://dump.velocitypowered.com/"
|
||||||
JsonObject returned = null;
|
+ key.get("key").getAsString() + ".json";
|
||||||
try {
|
source.sendMessage(Component.text()
|
||||||
returned = InformationUtils.parseString(rawResponse);
|
.content("Created an anonymised report containing useful information about "
|
||||||
if (returned == null || !returned.has("key")) {
|
+ "this proxy. If a developer requested it, you may share the "
|
||||||
throw new JsonParseException("Invalid json response");
|
+ "following link with them:")
|
||||||
|
.append(Component.newline())
|
||||||
|
.append(Component.text(">> " + url)
|
||||||
|
.color(NamedTextColor.GREEN)
|
||||||
|
.clickEvent(ClickEvent.openUrl(url)))
|
||||||
|
.append(Component.newline())
|
||||||
|
.append(Component.text("Note: This link is only valid for a few days")
|
||||||
|
.color(NamedTextColor.GRAY)
|
||||||
|
).build());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
source.sendMessage(Component.text()
|
||||||
|
.content("Could not complete the request, the command was interrupted."
|
||||||
|
+ "Please refer to the proxy-log or console for more information.")
|
||||||
|
.color(NamedTextColor.RED).build());
|
||||||
|
logger.error("Failed to complete dump command, "
|
||||||
|
+ "the executor was interrupted: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
TextComponent.Builder message = Component.text()
|
||||||
|
.content("An error occurred while attempting to upload the gathered "
|
||||||
|
+ "information to the Velocity servers.")
|
||||||
|
.append(Component.newline())
|
||||||
|
.color(NamedTextColor.RED);
|
||||||
|
if (e.getCause() instanceof UnknownHostException
|
||||||
|
|| e.getCause() instanceof ConnectException) {
|
||||||
|
message.append(Component.text(
|
||||||
|
"Likely cause: Invalid system DNS settings or no internet connection"));
|
||||||
|
}
|
||||||
|
source.sendMessage(message
|
||||||
|
.append(Component.newline()
|
||||||
|
.append(Component.text(
|
||||||
|
"Error details can be found in the proxy log / console"))
|
||||||
|
).build());
|
||||||
|
|
||||||
|
logger.error("Failed to complete dump command, "
|
||||||
|
+ "the executor encountered an Exception: " + e.getCause().getMessage());
|
||||||
|
e.getCause().printStackTrace();
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
source.sendMessage(Component.text()
|
||||||
|
.content("An error occurred on the Velocity-servers and the dump could not "
|
||||||
|
+ "be completed. Please contact the Velocity staff about this problem. "
|
||||||
|
+ "If you do, provide the details about this error from the Velocity "
|
||||||
|
+ "console or server log.")
|
||||||
|
.color(NamedTextColor.RED).build());
|
||||||
|
logger.error("Invalid response from the Velocity servers: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (JsonSyntaxException e4) {
|
}, MoreExecutors.directExecutor());
|
||||||
// Mangled json
|
|
||||||
source.sendMessage(
|
|
||||||
Component.text()
|
|
||||||
.content("Server responded with invalid data!")
|
|
||||||
.color(NamedTextColor.RED).build());
|
|
||||||
return;
|
|
||||||
} catch (JsonParseException e5) {
|
|
||||||
// Backend error?
|
|
||||||
source.sendMessage(
|
|
||||||
Component.text()
|
|
||||||
.content("Data was uploaded successfully but couldn't be posted")
|
|
||||||
.color(NamedTextColor.RED).build());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TextComponent response = Component.text()
|
|
||||||
.content("Created an anonymised report containing useful information about")
|
|
||||||
.append(Component.newline()
|
|
||||||
.append(
|
|
||||||
Component.text("this proxy. If a developer requested it"
|
|
||||||
+ ", you may share the"))
|
|
||||||
.append(Component.newline())
|
|
||||||
.append(Component.text("following link with them:"))
|
|
||||||
.append(Component.newline())
|
|
||||||
.append(Component.text("https://dump.velocitypowered.com/"
|
|
||||||
+ returned.get("key").getAsString() + ".json")
|
|
||||||
.color(NamedTextColor.GREEN)))
|
|
||||||
.append(Component.newline())
|
|
||||||
.append(Component.text("Note: This link is only valid for a few days"))
|
|
||||||
.build();
|
|
||||||
source.sendMessage(response);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -173,8 +173,6 @@ public enum InformationUtils {
|
|||||||
SocketAddress address = server.getServerInfo().getAddress();
|
SocketAddress address = server.getServerInfo().getAddress();
|
||||||
if (address instanceof InetSocketAddress) {
|
if (address instanceof InetSocketAddress) {
|
||||||
InetSocketAddress iaddr = (InetSocketAddress) address;
|
InetSocketAddress iaddr = (InetSocketAddress) address;
|
||||||
info.addProperty("socketType", "EventLoop/NIO");
|
|
||||||
info.addProperty("unresolved", iaddr.isUnresolved());
|
|
||||||
if (iaddr.isUnresolved()) {
|
if (iaddr.isUnresolved()) {
|
||||||
// Greetings form Netty 4aa10db9
|
// Greetings form Netty 4aa10db9
|
||||||
info.addProperty("host", iaddr.getHostString());
|
info.addProperty("host", iaddr.getHostString());
|
||||||
@ -184,10 +182,8 @@ public enum InformationUtils {
|
|||||||
info.addProperty("port", iaddr.getPort());
|
info.addProperty("port", iaddr.getPort());
|
||||||
} else if (address instanceof DomainSocketAddress) {
|
} else if (address instanceof DomainSocketAddress) {
|
||||||
DomainSocketAddress daddr = (DomainSocketAddress) address;
|
DomainSocketAddress daddr = (DomainSocketAddress) address;
|
||||||
info.addProperty("socketType", "Unix/Epoll");
|
|
||||||
info.addProperty("path", daddr.path());
|
info.addProperty("path", daddr.path());
|
||||||
} else {
|
} else {
|
||||||
info.addProperty("socketType", "Unknown/Generic");
|
|
||||||
info.addProperty("info", address.toString());
|
info.addProperty("info", address.toString());
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren