mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -04:00
Auto download mappings if mappings are not available on disk
This commit is contained in:
parent
7af06cdbf2
commit
fad06a58a1
@ -18,7 +18,8 @@ public enum GameConfiguration implements ConfigEnum {
|
||||
GAME_RENDER_DISTANCE("game.render-distance"),
|
||||
NETWORK_FAKE_CLIENT_BRAND("network.fake-client-brand"),
|
||||
GENERAL_LOG_LEVEL("general.log-level"),
|
||||
CLIENT_TOKEN("account.clientToken");
|
||||
CLIENT_TOKEN("account.clientToken"),
|
||||
MAPPINGS_URL("download.mappings");
|
||||
|
||||
final String path;
|
||||
|
||||
|
@ -18,6 +18,8 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import de.bixilon.minosoft.Config;
|
||||
import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.config.GameConfiguration;
|
||||
import de.bixilon.minosoft.game.datatypes.Mappings;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.protocol.ConnectionStates;
|
||||
@ -25,10 +27,13 @@ import de.bixilon.minosoft.protocol.protocol.Packets;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
public class Versions {
|
||||
|
||||
@ -132,7 +137,23 @@ public class Versions {
|
||||
Log.verbose(String.format("Loading mappings for version %s...", version));
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
HashMap<String, String> files = Util.readTarGzFile(Config.homeDir + String.format("assets/mapping/%s.tar.gz", version.getVersionName()));
|
||||
String fileName = Config.homeDir + String.format("assets/mapping/%s.tar.gz", version.getVersionName());
|
||||
HashMap<String, String> files;
|
||||
try {
|
||||
files = Util.readTarGzFile(fileName);
|
||||
} catch (FileNotFoundException e) {
|
||||
long downloadStartTime = System.currentTimeMillis();
|
||||
Log.info(String.format("Mappings for %s are not available on disk. Downloading them...", version.getVersionName()));
|
||||
Util.downloadFile(String.format(Minosoft.getConfig().getString(GameConfiguration.MAPPINGS_URL), version.getVersionName()), fileName);
|
||||
try {
|
||||
files = Util.readTarGzFile(fileName);
|
||||
} catch (ZipException e2) {
|
||||
// bullshit downloaded, delete file
|
||||
new File(fileName).delete();
|
||||
throw e2;
|
||||
}
|
||||
Log.info(String.format("Mappings for %s downloaded successfully in %dms!", version.getVersionName(), (System.currentTimeMillis() - downloadStartTime)));
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Mappings> mappingSet : mappingsHashMap.entrySet()) {
|
||||
JsonObject data = JsonParser.parseString(files.get(mappingSet.getKey() + ".json")).getAsJsonObject().getAsJsonObject("minecraft");
|
||||
|
@ -157,11 +157,10 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
motd.setText(ping.getMotd().getRawMessage());
|
||||
if (ping.getFavicon() != null) {
|
||||
icon.setImage(ping.getFavicon());
|
||||
if (ping.getBase64EncodedFavicon().equals(server.getBase64Favicon())) {
|
||||
return;
|
||||
if (!ping.getBase64EncodedFavicon().equals(server.getBase64Favicon())) {
|
||||
server.setBase64Favicon(ping.getBase64EncodedFavicon());
|
||||
server.saveToConfig();
|
||||
}
|
||||
server.setBase64Favicon(ping.getBase64EncodedFavicon());
|
||||
server.saveToConfig();
|
||||
}
|
||||
if (server.getLastPing().getLastConnectionException() != null) {
|
||||
// connection failed because of an error in minosoft, but ping was okay
|
||||
|
@ -38,6 +38,7 @@ import de.bixilon.minosoft.util.DNSUtil;
|
||||
import de.bixilon.minosoft.util.ServerAddress;
|
||||
import org.xbill.DNS.TextParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@ -195,6 +196,9 @@ public class Connection {
|
||||
handleCallbacks(null);
|
||||
}
|
||||
break;
|
||||
case FAILED_NO_RETRY:
|
||||
handleCallbacks(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,11 +212,11 @@ public class Connection {
|
||||
try {
|
||||
Versions.loadVersionMappings(version.getProtocolVersion());
|
||||
customMapping.setVersion(version);
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version));
|
||||
network.lastException = new RuntimeException(String.format("Mappings could not be loaded: %s", e.getLocalizedMessage()));
|
||||
setConnectionState(ConnectionStates.FAILED);
|
||||
setConnectionState(ConnectionStates.FAILED_NO_RETRY);
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +305,7 @@ public class Connection {
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return state != ConnectionStates.FAILED && state != ConnectionStates.DISCONNECTING && state != ConnectionStates.DISCONNECTED && state != ConnectionStates.CONNECTING;
|
||||
return state != ConnectionStates.FAILED && state != ConnectionStates.FAILED_NO_RETRY && state != ConnectionStates.DISCONNECTING && state != ConnectionStates.DISCONNECTED && state != ConnectionStates.CONNECTING;
|
||||
}
|
||||
|
||||
public PacketSender getSender() {
|
||||
@ -347,7 +351,7 @@ public class Connection {
|
||||
}
|
||||
|
||||
public void addPingCallback(PingCallback pingCallback) {
|
||||
if (getConnectionState() == ConnectionStates.FAILED || lastPing != null) {
|
||||
if (getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || lastPing != null) {
|
||||
// ping done
|
||||
pingCallback.handle(lastPing);
|
||||
return;
|
||||
|
@ -21,7 +21,8 @@ public enum ConnectionStates {
|
||||
CONNECTING,
|
||||
DISCONNECTING,
|
||||
DISCONNECTED,
|
||||
FAILED;
|
||||
FAILED,
|
||||
FAILED_NO_RETRY;
|
||||
|
||||
|
||||
public static ConnectionStates byId(int id) {
|
||||
|
@ -21,6 +21,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -149,4 +150,14 @@ public final class Util {
|
||||
public static JsonObject readJsonFromFile(String fileName) throws IOException {
|
||||
return JsonParser.parseString(readFile(fileName)).getAsJsonObject();
|
||||
}
|
||||
|
||||
public static void downloadFile(String url, String destination) throws IOException {
|
||||
BufferedInputStream inputStream = new BufferedInputStream(new URL(url).openStream());
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(destination);
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer, 0, 1024)) != -1) {
|
||||
fileOutputStream.write(buffer, 0, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,5 +14,6 @@ network:
|
||||
account:
|
||||
clientToken: "randomGenerated"
|
||||
accounts:
|
||||
|
||||
download:
|
||||
mappings: "https://gitlab.com/Bixilon/minosoft/-/raw/master/data/mcdata/%s.tar.gz?inline=false" # url for all mappings. Files must be called version.tar.gz (e.g. 1.12.2.tar.gz). In these files must be the blocks.json and the registries.json
|
||||
servers:
|
||||
|
Loading…
x
Reference in New Issue
Block a user