[FIX] Фикс UpdateRequest, алгоритм обхода HashedDir, реализация joinServerRequest/CheckServerRequest

This commit is contained in:
Gravit 2019-04-03 21:53:12 +07:00
parent 50adbac117
commit 08f7a98dbb
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
5 changed files with 61 additions and 5 deletions

View file

@ -449,7 +449,6 @@ public static void main(String... args) throws Throwable {
Launcher.modulesManager.initModules();
// Verify ClientLauncher sign and classpath
LogHelper.debug("Verifying ClientLauncher sign and classpath");
//Warning - experimental.
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.getClassPath());
for (Path classpathURL : classPath) {
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());

View file

@ -7,6 +7,9 @@
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.ResultInterface;
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -15,7 +18,7 @@
import java.io.IOException;
public final class CheckServerRequest extends Request<CheckServerRequestEvent> {
public final class CheckServerRequest extends Request<CheckServerRequestEvent> implements RequestInterface {
private final String username;
private final String serverID;
@ -31,6 +34,12 @@ public CheckServerRequest(String username, String serverID) {
this(null, username, serverID);
}
@Override
public CheckServerRequestEvent requestWebSockets() throws Exception
{
return (CheckServerRequestEvent) LegacyRequestBridge.sendRequest(this);
}
@Override
public Integer getLegacyType() {
return RequestType.CHECK_SERVER.getNumber();
@ -51,4 +60,9 @@ protected CheckServerRequestEvent requestDo(HInput input, HOutput output) throws
readError(input);
return input.readBoolean() ? new CheckServerRequestEvent(new PlayerProfile(input)) : null;
}
@Override
public String getType() {
return "checkServer";
}
}

View file

@ -5,6 +5,8 @@
import ru.gravit.launcher.events.request.JoinServerRequestEvent;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -13,7 +15,7 @@
import java.io.IOException;
public final class JoinServerRequest extends Request<JoinServerRequestEvent> {
public final class JoinServerRequest extends Request<JoinServerRequestEvent> implements RequestInterface {
// Instance
private final String username;
@ -28,6 +30,11 @@ public JoinServerRequest(LauncherConfig config, String username, String accessTo
this.serverID = VerifyHelper.verifyServerID(serverID);
}
@Override
public JoinServerRequestEvent requestWebSockets() throws IOException, InterruptedException {
return (JoinServerRequestEvent) LegacyRequestBridge.sendRequest(this);
}
@LauncherAPI
public JoinServerRequest(String username, String accessToken, String serverID) {
this(null, username, accessToken, serverID);
@ -50,4 +57,8 @@ protected JoinServerRequestEvent requestDo(HInput input, HOutput output) throws
return new JoinServerRequestEvent(input.readBoolean());
}
@Override
public String getType() {
return "joinServer";
}
}

View file

@ -206,8 +206,8 @@ public UpdateRequestEvent requestWebSockets() throws Exception {
Launcher.profile.pushOptionalFile(e.hdir, !Launcher.profile.isUpdateFastCheck());
HashedDir.Diff diff = e.hdir.diff(localDir, matcher);
final List<String> adds = new ArrayList<>();
diff.mismatch.map().entrySet().stream().filter(e1 -> e1.getValue().getType().equals(HashedEntry.Type.FILE)).forEach(a -> {
adds.add(a.getKey());
diff.mismatch.walk(IOHelper.CROSS_SEPARATOR, (path, name, entry) -> {
if(entry.getType() == HashedEntry.Type.FILE) adds.add(path.replaceAll(" ","%20"));
});
totalSize = diff.mismatch.size();
startTime = Instant.now();

View file

@ -335,4 +335,36 @@ public void write(HOutput output) throws IOException {
entry.write(output);
}
}
public void walk(CharSequence separator, WalkCallback callback)
{
String append = "";
walk(append,separator, callback, true);
}
@FunctionalInterface
public interface WalkCallback
{
void walked(String path, String name, HashedEntry entry);
}
private void walk(String append, CharSequence separator, WalkCallback callback , boolean noSeparator)
{
for(Map.Entry<String, HashedEntry> entry : map.entrySet())
{
HashedEntry e = entry.getValue();
if(e.getType() == Type.FILE)
{
if(noSeparator)
callback.walked(append + entry.getKey(), entry.getKey(), e);
else
callback.walked(append + separator + entry.getKey(), entry.getKey(), e);
}
else
{
String newAppend;
if(noSeparator) newAppend = append + entry.getKey();
else newAppend = append + separator + entry.getKey();
callback.walked(newAppend, entry.getKey(), e);
((HashedDir)e).walk(newAppend, separator, callback, false);
}
}
}
}