Revert "0.5 Maybe fixes an issue. New SyncResult class"
This reverts commit b19ced54c0.
This commit is contained in:
parent
ff1ce90d16
commit
7d9aba43ec
1
Velocity
1
Velocity
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 5fe3663d5102c98df1128b06f002e0c5b212f61f
|
|
||||||
|
|
@ -4,7 +4,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'org.adde0109'
|
group 'org.adde0109'
|
||||||
version '0.5.0'
|
version '0.4.0'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import org.slf4j.Logger;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Plugin(id = "ambassador", name = "Ambassador", version = "0.5.0", authors = {"adde0109"})
|
@Plugin(id = "ambassador", name = "Ambassador", version = "0.4.0", authors = {"adde0109"})
|
||||||
public class Ambassador {
|
public class Ambassador {
|
||||||
|
|
||||||
public ProxyServer server;
|
public ProxyServer server;
|
||||||
|
|
@ -82,7 +82,7 @@ public class Ambassador {
|
||||||
//Forge client
|
//Forge client
|
||||||
ForgeConnection forgeConnection = forgeHandshakeHandler.getForgeConnection(event.getPlayer()).get();
|
ForgeConnection forgeConnection = forgeHandshakeHandler.getForgeConnection(event.getPlayer()).get();
|
||||||
if (forgeConnection.isForced()) {
|
if (forgeConnection.isForced()) {
|
||||||
event.setInitialServer(forgeConnection.getSyncResult().get().getSyncedServer());
|
event.setInitialServer(forgeConnection.getSyncedServer().get());
|
||||||
}
|
}
|
||||||
forgeConnection.setForced(config.getForced(forgeConnection.getConnection().getProtocolVersion().getProtocol()));
|
forgeConnection.setForced(config.getForced(forgeConnection.getConnection().getProtocolVersion().getProtocol()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ public class ForgeConnection {
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final LoginPhaseConnection connection;
|
private final LoginPhaseConnection connection;
|
||||||
|
|
||||||
|
private Optional<byte[]> recivedClientModlist = Optional.empty();
|
||||||
|
private static byte[] recivedClientACK;
|
||||||
private boolean ignoreSyncExepction = false;
|
private boolean ignoreSyncExepction = false;
|
||||||
|
|
||||||
|
private Optional<ForgeHandshakeUtils.CachedServerHandshake> transmittedHandshake = Optional.empty();
|
||||||
private boolean forced = false;
|
private boolean forced = false;
|
||||||
|
private Optional<RegisteredServer> syncedTo = Optional.empty();
|
||||||
private SyncResult syncResult;
|
|
||||||
|
|
||||||
|
|
||||||
public ForgeConnection(LoginPhaseConnection connection, Logger logger) {
|
public ForgeConnection(LoginPhaseConnection connection, Logger logger) {
|
||||||
|
|
@ -45,35 +47,34 @@ public class ForgeConnection {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void startSync(ForgeServerConnection forgeServerConnection, Continuation continuation) {
|
public CompletableFuture<Boolean> sync(ForgeServerConnection forgeServerConnection) {
|
||||||
|
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
forgeServerConnection.getHandshake().whenComplete((msg,ex) -> {
|
forgeServerConnection.getHandshake().whenComplete((msg,ex) -> {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
continuation.resume();
|
future.complete(false);
|
||||||
logger.warn("Sync Exception: " + ex);
|
logger.warn("Sync Exception: " + ex);
|
||||||
} else {
|
} else {
|
||||||
CompletableFuture<byte[]> clientModListFuture = new CompletableFuture<>();
|
|
||||||
//This gets also sent to vanilla
|
//This gets also sent to vanilla
|
||||||
sendModlist(msg.modListPacket).thenAccept((response) -> {
|
sendModlist(msg.modListPacket).thenAccept((response) -> {
|
||||||
if (!ignoreSyncExepction && response == null) {
|
if (!ignoreSyncExepction && response == null) {
|
||||||
logger.warn("Sync Exception: Client responded with an empty body.");
|
logger.warn("Sync Exception: Client responded with an empty body.");
|
||||||
}
|
}
|
||||||
clientModListFuture.complete(response);
|
recivedClientModlist = Optional.ofNullable(response);
|
||||||
});
|
});
|
||||||
syncResult = new SyncResult(msg,clientModListFuture, forgeServerConnection.getServer());
|
|
||||||
//This gets also sent to vanilla
|
//This gets also sent to vanilla
|
||||||
sendOther(msg.otherPackets).thenAccept((response) -> {
|
sendOther(msg.otherPackets).thenAccept((response) -> {
|
||||||
if (!ignoreSyncExepction && response == null) {
|
if (!ignoreSyncExepction && response == null) {
|
||||||
logger.warn("Sync Exception: Client responded with an empty body.");
|
logger.warn("Sync Exception: Client responded with an empty body.");
|
||||||
}
|
}
|
||||||
//TODO: Generate the ACK packet ourself.
|
//TODO: Generate the ACK packet ourself.
|
||||||
if (response != null && SyncResult.recivedClientACK == null) {
|
ForgeConnection.recivedClientACK = (response == null) ? ForgeConnection.recivedClientACK : response;
|
||||||
SyncResult.recivedClientACK = response;
|
transmittedHandshake = Optional.of(msg);
|
||||||
}
|
syncedTo = Optional.of(forgeServerConnection.getServer());
|
||||||
syncResult.complete(syncResult);
|
|
||||||
});
|
});
|
||||||
continuation.resume();
|
future.complete(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<byte[]> sendModlist(byte[] modListPacket) {
|
private CompletableFuture<byte[]> sendModlist(byte[] modListPacket) {
|
||||||
|
|
@ -94,11 +95,6 @@ public class ForgeConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleServerHandshakePacket(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
public void handleServerHandshakePacket(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
||||||
if (getSyncResult().isEmpty()) {
|
|
||||||
continuation.resumeWithException(new Exception("Client isn't synced. This should have been caught" +
|
|
||||||
" during serverPreConnect"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ByteArrayDataInput data = event.contentsAsDataStream();
|
ByteArrayDataInput data = event.contentsAsDataStream();
|
||||||
if (data.skipBytes(14) != 14) { //Channel Identifier
|
if (data.skipBytes(14) != 14) { //Channel Identifier
|
||||||
continuation.resumeWithException(new EOFException());
|
continuation.resumeWithException(new EOFException());
|
||||||
|
|
@ -108,27 +104,41 @@ public class ForgeConnection {
|
||||||
int packetID = ForgeHandshakeUtils.readVarInt(data);
|
int packetID = ForgeHandshakeUtils.readVarInt(data);
|
||||||
|
|
||||||
if (packetID == 1) {
|
if (packetID == 1) {
|
||||||
getSyncResult().get().getRecivedClientModlist().whenComplete((msg,ex) -> {
|
if (getRecivedClientModlist().isPresent()) {
|
||||||
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(msg));
|
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(getRecivedClientModlist().get()));
|
||||||
continuation.resume();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (SyncResult.recivedClientACK != null) {
|
|
||||||
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(SyncResult.recivedClientACK));
|
|
||||||
} else {
|
} else {
|
||||||
continuation.resumeWithException(new Exception("No ACK response packet available."));
|
continuation.resumeWithException(new Exception("Client isn't synced. This should have been caught" +
|
||||||
|
" during serverPreConnect"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getRecivedClientACK() != null) {
|
||||||
|
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(getRecivedClientACK()));
|
||||||
|
} else {
|
||||||
|
continuation.resumeWithException(new Exception("No response available."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
continuation.resume();
|
|
||||||
}
|
}
|
||||||
|
continuation.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginPhaseConnection getConnection() {
|
public LoginPhaseConnection getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<SyncResult> getSyncResult() {
|
public Optional<ForgeHandshakeUtils.CachedServerHandshake> getTransmittedHandshake() {
|
||||||
return Optional.ofNullable(syncResult);
|
return transmittedHandshake;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<byte[]> getRecivedClientModlist() {
|
||||||
|
return recivedClientModlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getRecivedClientACK() {
|
||||||
|
return recivedClientACK;
|
||||||
|
}
|
||||||
|
public Optional<RegisteredServer> getSyncedServer() {
|
||||||
|
return syncedTo;
|
||||||
}
|
}
|
||||||
public void setForced(boolean forced) {
|
public void setForced(boolean forced) {
|
||||||
this.forced = forced;
|
this.forced = forced;
|
||||||
|
|
@ -136,28 +146,4 @@ public class ForgeConnection {
|
||||||
public boolean isForced() {
|
public boolean isForced() {
|
||||||
return forced;
|
return forced;
|
||||||
}
|
}
|
||||||
public static class SyncResult extends CompletableFuture<SyncResult> {
|
|
||||||
private final ForgeHandshakeUtils.CachedServerHandshake transmittedHandshake;
|
|
||||||
private final CompletableFuture<byte[]> recivedClientModlist;
|
|
||||||
private static byte[] recivedClientACK;
|
|
||||||
private final RegisteredServer syncedTo;
|
|
||||||
|
|
||||||
SyncResult(ForgeHandshakeUtils.CachedServerHandshake transmittedHandshake, CompletableFuture<byte[]> recivedClientModlist, RegisteredServer syncedTo) {
|
|
||||||
this.transmittedHandshake = transmittedHandshake;
|
|
||||||
this.recivedClientModlist = recivedClientModlist;
|
|
||||||
this.syncedTo = syncedTo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ForgeHandshakeUtils.CachedServerHandshake getTransmittedHandshake() {
|
|
||||||
return transmittedHandshake;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<byte[]> getRecivedClientModlist() {
|
|
||||||
return recivedClientModlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegisteredServer getSyncedServer() {
|
|
||||||
return syncedTo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,9 @@ public class ForgeHandshakeHandler {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ambassador.forgeServerSwitchHandler.reSyncMap.containsKey(event.getUsername())) {
|
if (ambassador.forgeServerSwitchHandler.reSyncMap.containsKey(event.getUsername())) {
|
||||||
forgeConnection.startSync(ambassador.forgeServerSwitchHandler.reSyncMap.remove(event.getUsername()),continuation);
|
forgeConnection.sync(ambassador.forgeServerSwitchHandler.reSyncMap.remove(event.getUsername())).thenAccept((done) -> {
|
||||||
|
continuation.resume();
|
||||||
|
});
|
||||||
forgeConnection.setForced(true);
|
forgeConnection.setForced(true);
|
||||||
} else if (defaultServer != null) {
|
} else if (defaultServer != null) {
|
||||||
//If a connection does not already exist, create one.
|
//If a connection does not already exist, create one.
|
||||||
|
|
@ -60,7 +62,9 @@ public class ForgeHandshakeHandler {
|
||||||
forgeServerConnectionMap.put(defaultServer, new ForgeServerConnection(defaultServer));
|
forgeServerConnectionMap.put(defaultServer, new ForgeServerConnection(defaultServer));
|
||||||
}
|
}
|
||||||
//Forge Handshake
|
//Forge Handshake
|
||||||
forgeConnection.startSync(forgeServerConnectionMap.get(defaultServer),continuation);
|
forgeConnection.sync(forgeServerConnectionMap.get(defaultServer)).thenAccept((done) -> {
|
||||||
|
continuation.resume();
|
||||||
|
});
|
||||||
forgeConnection.setForced(ambassador.config.getForced(forgeConnection.getConnection().getProtocolVersion().getProtocol()));
|
forgeConnection.setForced(ambassador.config.getForced(forgeConnection.getConnection().getProtocolVersion().getProtocol()));
|
||||||
} else {
|
} else {
|
||||||
continuation.resume();
|
continuation.resume();
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,8 @@ public class ForgeServerSwitchHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Optional<ForgeServerConnection> forgeServerConnectionOptional = ambassador.forgeHandshakeHandler.getForgeServerConnection(event.getOriginalServer());
|
Optional<ForgeServerConnection> forgeServerConnectionOptional = ambassador.forgeHandshakeHandler.getForgeServerConnection(event.getOriginalServer());
|
||||||
Optional<ForgeConnection> forgeConnectionOptional = ambassador.forgeHandshakeHandler.getForgeConnection(event.getPlayer());
|
Optional<ForgeConnection> forgeConnection = ambassador.forgeHandshakeHandler.getForgeConnection(event.getPlayer());
|
||||||
if (forgeConnectionOptional.isPresent()) {
|
if (forgeConnection.isPresent()) {
|
||||||
ForgeConnection forgeConnection = forgeConnectionOptional.get();
|
|
||||||
ForgeServerConnection forgeServerConnection = forgeServerConnectionOptional.orElseGet(() -> new ForgeServerConnection(event.getOriginalServer()));
|
ForgeServerConnection forgeServerConnection = forgeServerConnectionOptional.orElseGet(() -> new ForgeServerConnection(event.getOriginalServer()));
|
||||||
forgeServerConnection.getHandshake().whenComplete((msg, ex) -> {
|
forgeServerConnection.getHandshake().whenComplete((msg, ex) -> {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
|
|
@ -57,7 +56,7 @@ public class ForgeServerSwitchHandler {
|
||||||
event.getPlayer().setGameProfileProperties(properties);
|
event.getPlayer().setGameProfileProperties(properties);
|
||||||
|
|
||||||
if (ambassador.config.reSyncOptionForge() != AmbassadorConfig.reSyncOption.NEVER) {
|
if (ambassador.config.reSyncOptionForge() != AmbassadorConfig.reSyncOption.NEVER) {
|
||||||
if (forgeConnection.getSyncResult().isEmpty() || !msg.equals(forgeConnection.getSyncResult().get().getTransmittedHandshake())) {
|
if (forgeConnection.get().getTransmittedHandshake().isEmpty() || !msg.equals(forgeConnection.get().getTransmittedHandshake().get())) {
|
||||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||||
reSync(event.getPlayer(),forgeServerConnection);
|
reSync(event.getPlayer(),forgeServerConnection);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user