Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/ldtteam/structurize/api/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public static String getSafePackName(String input)
s = s.replaceAll("[\\\\/:*?\"<>|]", "_");
s = s.replaceAll("\\p{Cntrl}", "");
s = s.trim();
if (s.isEmpty() || s.equals(".") || s.equals("..") || s.length() > 255)
{
return "";
}

return s;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.neoforged.fml.ModList;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforgespi.language.IModInfo;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -254,12 +255,13 @@ else if (version != pack.getVersion())
/**
* On reception of a new structure pack.
*
* @param packName the name of the structure pack.
* @param name the name of the structure pack.
* @param payload the payload of the pack.
* @param eol if last sync.
*/
public static void onStructurePackTransfer(final String packName, final ByteBuf payload, final boolean eol)
public static void onStructurePackTransfer(final String name, final ByteBuf payload, final boolean eol)
{
final String packName = Utils.getSafePackName(name);
Log.getLogger().warn("Received Structure pack from the Server: " + packName);
IOPool.execute(() ->
{
Expand All @@ -269,13 +271,20 @@ public static void onStructurePackTransfer(final String packName, final ByteBuf
Log.getLogger().warn("Error trying to delete pack: ");
}

final Path structureFolder = Minecraft.getInstance().gameDirectory.toPath().resolve(BLUEPRINT_FOLDER).normalize();
final Path childPath = structureFolder.resolve(packName);
if (Files.isSymbolicLink(childPath))
{
return;
}

JavaUtils.deleteDirectory(childPath);

try (ZipInputStream zis = new ZipInputStream(new ByteBufInputStream(payload)))
{
ZipEntry zipEntry = zis.getNextEntry();
final Path structureFolder = Minecraft.getInstance().gameDirectory.toPath().resolve(BLUEPRINT_FOLDER);
JavaUtils.deleteDirectory(structureFolder.resolve(packName));
final Path rootPath = Files.createDirectory(structureFolder.resolve(packName));

final Path rootPath = Files.createDirectory(childPath);
while (zipEntry != null)
{
boolean isDirectory = zipEntry.isDirectory();
Expand Down
Loading