2020-06-27 15:36:48 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2020-06-27 15:36:48 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2020-06-27 15:36:48 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2020-06-27 15:36:48 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2020-06-27 15:36:48 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
2020-06-27 15:36:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.connector.dump;
|
|
|
|
|
2020-07-30 16:40:53 +00:00
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
2021-08-24 20:34:50 +00:00
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
2020-06-27 15:36:48 +00:00
|
|
|
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
2021-04-30 16:43:37 +00:00
|
|
|
import com.google.common.hash.Hashing;
|
|
|
|
import com.google.common.io.ByteSource;
|
|
|
|
import com.google.common.io.Files;
|
2020-07-30 15:59:42 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
2021-04-30 16:43:37 +00:00
|
|
|
import lombok.AllArgsConstructor;
|
2020-06-27 15:36:48 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import org.geysermc.connector.GeyserConnector;
|
2020-09-15 00:51:07 +00:00
|
|
|
import org.geysermc.connector.common.serializer.AsteriskSerializer;
|
2020-06-27 15:36:48 +00:00
|
|
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
2020-08-11 14:00:14 +00:00
|
|
|
import org.geysermc.connector.network.BedrockProtocol;
|
2020-07-30 15:59:42 +00:00
|
|
|
import org.geysermc.connector.network.session.GeyserSession;
|
2020-06-27 15:36:48 +00:00
|
|
|
import org.geysermc.connector.utils.DockerCheck;
|
|
|
|
import org.geysermc.connector.utils.FileUtils;
|
2021-08-24 19:11:38 +00:00
|
|
|
import org.geysermc.connector.utils.WebUtils;
|
2020-08-18 15:39:29 +00:00
|
|
|
import org.geysermc.floodgate.util.DeviceOs;
|
2021-06-08 08:12:52 +00:00
|
|
|
import org.geysermc.floodgate.util.FloodgateInfoHolder;
|
2020-06-27 15:36:48 +00:00
|
|
|
|
2021-04-30 16:43:37 +00:00
|
|
|
import java.io.File;
|
2020-06-27 15:36:48 +00:00
|
|
|
import java.io.IOException;
|
2021-08-24 20:34:50 +00:00
|
|
|
import java.net.*;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2020-06-27 15:36:48 +00:00
|
|
|
import java.util.Properties;
|
2021-08-25 10:31:12 +00:00
|
|
|
import java.util.stream.Collectors;
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
@Getter
|
|
|
|
public class DumpInfo {
|
2020-07-30 16:40:53 +00:00
|
|
|
@JsonIgnore
|
|
|
|
private static final long MEGABYTE = 1024L * 1024L;
|
|
|
|
|
2020-06-27 15:36:48 +00:00
|
|
|
private final DumpInfo.VersionInfo versionInfo;
|
|
|
|
private Properties gitInfo;
|
|
|
|
private final GeyserConfiguration config;
|
2021-06-06 14:59:47 +00:00
|
|
|
private final Floodgate floodgate;
|
2020-12-01 22:17:54 +00:00
|
|
|
private final Object2IntMap<DeviceOs> userPlatforms;
|
2021-06-06 14:59:47 +00:00
|
|
|
private final HashInfo hashInfo;
|
2020-12-01 22:17:54 +00:00
|
|
|
private final RamInfo ramInfo;
|
2021-08-24 19:11:38 +00:00
|
|
|
private LogsInfo logsInfo;
|
2020-06-27 15:36:48 +00:00
|
|
|
private final BootstrapDumpInfo bootstrapInfo;
|
|
|
|
|
2021-08-24 19:11:38 +00:00
|
|
|
public DumpInfo(boolean addLog) {
|
2020-12-01 22:17:54 +00:00
|
|
|
this.versionInfo = new VersionInfo();
|
2020-07-30 15:59:42 +00:00
|
|
|
|
2020-06-27 15:36:48 +00:00
|
|
|
try {
|
|
|
|
this.gitInfo = new Properties();
|
|
|
|
this.gitInfo.load(FileUtils.getResource("git.properties"));
|
2020-12-01 22:17:54 +00:00
|
|
|
} catch (IOException ignored) {
|
|
|
|
}
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
this.config = GeyserConnector.getInstance().getConfig();
|
2021-06-06 14:59:47 +00:00
|
|
|
this.floodgate = new Floodgate();
|
2020-06-27 15:36:48 +00:00
|
|
|
|
2021-04-30 16:43:37 +00:00
|
|
|
String md5Hash = "unknown";
|
|
|
|
String sha256Hash = "unknown";
|
|
|
|
try {
|
|
|
|
// https://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file
|
|
|
|
// https://stackoverflow.com/questions/304268/getting-a-files-md5-checksum-in-java
|
|
|
|
File file = new File(DumpInfo.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
|
|
|
ByteSource byteSource = Files.asByteSource(file);
|
|
|
|
// Jenkins uses MD5 for its hash
|
|
|
|
//noinspection UnstableApiUsage
|
|
|
|
md5Hash = byteSource.hash(Hashing.md5()).toString();
|
|
|
|
//noinspection UnstableApiUsage
|
|
|
|
sha256Hash = byteSource.hash(Hashing.sha256()).toString();
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (GeyserConnector.getInstance().getConfig().isDebugMode()) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.hashInfo = new HashInfo(md5Hash, sha256Hash);
|
|
|
|
|
2020-07-30 15:59:42 +00:00
|
|
|
this.ramInfo = new DumpInfo.RamInfo();
|
|
|
|
|
2021-08-24 19:11:38 +00:00
|
|
|
if (addLog) {
|
|
|
|
this.logsInfo = new LogsInfo();
|
|
|
|
}
|
|
|
|
|
2020-12-01 22:17:54 +00:00
|
|
|
this.userPlatforms = new Object2IntOpenHashMap<>();
|
2020-07-30 15:59:42 +00:00
|
|
|
for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) {
|
2020-11-18 18:38:49 +00:00
|
|
|
DeviceOs device = session.getClientData().getDeviceOs();
|
2020-07-30 15:59:42 +00:00
|
|
|
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1);
|
|
|
|
}
|
|
|
|
|
2020-06-27 15:36:48 +00:00
|
|
|
this.bootstrapInfo = GeyserConnector.getInstance().getBootstrap().getDumpInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Getter
|
2020-12-01 22:17:54 +00:00
|
|
|
public static class VersionInfo {
|
2020-06-27 15:36:48 +00:00
|
|
|
private final String name;
|
|
|
|
private final String version;
|
|
|
|
private final String javaVersion;
|
|
|
|
private final String architecture;
|
|
|
|
private final String operatingSystem;
|
2020-07-30 15:59:42 +00:00
|
|
|
private final String operatingSystemVersion;
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
private final NetworkInfo network;
|
|
|
|
private final MCInfo mcInfo;
|
|
|
|
|
|
|
|
VersionInfo() {
|
|
|
|
this.name = GeyserConnector.NAME;
|
|
|
|
this.version = GeyserConnector.VERSION;
|
|
|
|
this.javaVersion = System.getProperty("java.version");
|
2020-12-01 22:17:54 +00:00
|
|
|
// Usually gives Java architecture but still may be helpful.
|
|
|
|
this.architecture = System.getProperty("os.arch");
|
2020-06-27 15:36:48 +00:00
|
|
|
this.operatingSystem = System.getProperty("os.name");
|
2020-07-30 15:59:42 +00:00
|
|
|
this.operatingSystemVersion = System.getProperty("os.version");
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
this.network = new NetworkInfo();
|
|
|
|
this.mcInfo = new MCInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
public static class NetworkInfo {
|
|
|
|
private final boolean dockerCheck;
|
2020-12-01 22:17:54 +00:00
|
|
|
private String internalIP;
|
2020-06-27 15:36:48 +00:00
|
|
|
|
|
|
|
NetworkInfo() {
|
2020-09-15 00:51:07 +00:00
|
|
|
if (AsteriskSerializer.showSensitive) {
|
2020-06-27 15:36:48 +00:00
|
|
|
try {
|
2020-09-15 00:51:07 +00:00
|
|
|
// This is the most reliable for getting the main local IP
|
|
|
|
Socket socket = new Socket();
|
|
|
|
socket.connect(new InetSocketAddress("geysermc.org", 80));
|
|
|
|
this.internalIP = socket.getLocalAddress().getHostAddress();
|
|
|
|
} catch (IOException e1) {
|
|
|
|
try {
|
|
|
|
// Fallback to the normal way of getting the local IP
|
|
|
|
this.internalIP = InetAddress.getLocalHost().getHostAddress();
|
2020-12-01 22:17:54 +00:00
|
|
|
} catch (UnknownHostException ignored) {
|
|
|
|
}
|
2020-09-15 00:51:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Sometimes the internal IP is the external IP...
|
|
|
|
this.internalIP = "***";
|
2020-06-27 15:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.dockerCheck = DockerCheck.checkBasic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
public static class MCInfo {
|
|
|
|
private final String bedrockVersion;
|
|
|
|
private final int bedrockProtocol;
|
|
|
|
private final String javaVersion;
|
|
|
|
private final int javaProtocol;
|
|
|
|
|
|
|
|
MCInfo() {
|
2020-08-11 14:00:14 +00:00
|
|
|
this.bedrockVersion = BedrockProtocol.DEFAULT_BEDROCK_CODEC.getMinecraftVersion();
|
|
|
|
this.bedrockProtocol = BedrockProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion();
|
2020-06-27 15:36:48 +00:00
|
|
|
this.javaVersion = MinecraftConstants.GAME_VERSION;
|
|
|
|
this.javaProtocol = MinecraftConstants.PROTOCOL_VERSION;
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 15:59:42 +00:00
|
|
|
|
2021-06-06 14:59:47 +00:00
|
|
|
@Getter
|
|
|
|
public static class Floodgate {
|
|
|
|
private final Properties gitInfo;
|
|
|
|
private final Object config;
|
|
|
|
|
|
|
|
Floodgate() {
|
2021-06-08 08:12:52 +00:00
|
|
|
this.gitInfo = FloodgateInfoHolder.getGitProperties();
|
|
|
|
this.config = FloodgateInfoHolder.getConfig();
|
2021-06-06 14:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 19:11:38 +00:00
|
|
|
@Getter
|
|
|
|
public static class LogsInfo {
|
|
|
|
private String link;
|
|
|
|
|
|
|
|
public LogsInfo() {
|
|
|
|
try {
|
2021-08-24 20:34:50 +00:00
|
|
|
Map<String, String> fields = new HashMap<>();
|
2021-08-25 10:31:12 +00:00
|
|
|
fields.put("content", FileUtils.readAllLines(GeyserConnector.getInstance().getBootstrap().getLogsPath()).collect(Collectors.joining("\n")));
|
2021-08-24 20:34:50 +00:00
|
|
|
|
|
|
|
JsonNode logData = GeyserConnector.JSON_MAPPER.readTree(WebUtils.postForm("https://api.mclo.gs/1/log", fields));
|
|
|
|
|
|
|
|
this.link = logData.get("url").textValue();
|
|
|
|
} catch (IOException ignored) { }
|
2021-08-24 19:11:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-06 14:59:47 +00:00
|
|
|
@AllArgsConstructor
|
|
|
|
@Getter
|
|
|
|
public static class HashInfo {
|
|
|
|
private final String md5Hash;
|
|
|
|
private final String sha256Hash;
|
|
|
|
}
|
|
|
|
|
2020-07-30 15:59:42 +00:00
|
|
|
@Getter
|
|
|
|
public static class RamInfo {
|
|
|
|
private final long free;
|
|
|
|
private final long total;
|
|
|
|
private final long max;
|
|
|
|
|
|
|
|
RamInfo() {
|
|
|
|
this.free = Runtime.getRuntime().freeMemory() / MEGABYTE;
|
|
|
|
this.total = Runtime.getRuntime().totalMemory() / MEGABYTE;
|
|
|
|
this.max = Runtime.getRuntime().maxMemory() / MEGABYTE;
|
|
|
|
}
|
|
|
|
}
|
2020-06-27 15:36:48 +00:00
|
|
|
}
|