*
This commit is contained in:
parent
3182441e66
commit
b4bb0ddc15
@ -66,6 +66,7 @@ public class Settings extends Config {
|
||||
|
||||
@Comment("Paths for various directories")
|
||||
public static final class PATHS {
|
||||
public String TOKENS = "tokens";
|
||||
@Comment({
|
||||
"Put any minecraft or mod jars for FAWE to be aware of block textures",
|
||||
})
|
||||
|
@ -3,31 +3,37 @@ package com.boydti.fawe.web;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SchemSync implements Runnable {
|
||||
private final static char PORT = 62522;
|
||||
|
||||
private final File tokensFile;
|
||||
private final WorldEdit worldEdit;
|
||||
private final File working;
|
||||
private Map<UUID, UUID> tokens;
|
||||
|
||||
public SchemSync() {
|
||||
this.tokensFile = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.TOKENS, "TOKENS.TXT");
|
||||
this.worldEdit = WorldEdit.getInstance();
|
||||
LocalConfiguration config = worldEdit.getConfiguration();
|
||||
this.working = worldEdit.getWorkingDirectoryFile(config.saveDir);
|
||||
}
|
||||
|
||||
private void loadTokens() {
|
||||
if (tokens == null) {
|
||||
String tokensDir = Settings.IMP.PATHS.TOKENS;
|
||||
tokens = new HashMap<>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +55,41 @@ public class SchemSync implements Runnable {
|
||||
|
||||
UUID receivedToken = new UUID(buf.getLong(), buf.getLong());
|
||||
if (!receivedToken.equals(expectedToken)) continue;
|
||||
|
||||
try (DataInputStream dis = new DataInputStream(in)) {
|
||||
File dir = new File(working, uuid.toString());
|
||||
|
||||
int data = dis.readByte() & 0xFF;
|
||||
switch (data) {
|
||||
case 0: {// list
|
||||
try (DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream())) {
|
||||
UtilityCommands.allFiles(dir.listFiles(), true, new Consumer<File>() {
|
||||
@Override
|
||||
public void accept(File file) {
|
||||
String path = dir.toURI().relativize(file.toURI()).getPath();
|
||||
try {
|
||||
out.writeUTF(path);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {// get
|
||||
String input = dis.readUTF();
|
||||
File file = new File(dir, input);
|
||||
if (!MainUtil.isInSubDirectory(working, file)) {
|
||||
|
||||
}
|
||||
if (MainUtil.isInSubDirectory(working, file) && file.exists())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// list
|
||||
// get
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user