v0.3 Kick when re-sync is needed. /Reload
This commit is contained in:
parent
ae44082336
commit
47db704422
|
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'org.adde0109'
|
||||
version '0.2.3'
|
||||
version '0.3.0'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.velocitypowered.api.event.Subscribe;
|
|||
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyReloadEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
|
@ -22,7 +23,7 @@ import org.slf4j.Logger;
|
|||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "0.2.3", authors = {"adde0109"})
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "0.3.0", authors = {"adde0109"})
|
||||
public class Ambassador {
|
||||
|
||||
private final ProxyServer server;
|
||||
|
|
@ -59,6 +60,18 @@ public class Ambassador {
|
|||
ForgeHandshakeUtils.HandshakeReceiver.logger = logger;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyReloadEvent(ProxyReloadEvent event) {
|
||||
AmbassadorConfig c = AmbassadorConfig.readOrCreateConfig(dataDirectory,server,logger);
|
||||
if (config != null) {
|
||||
config = c;
|
||||
forgeHandshakeHandler.setConfig(config);
|
||||
logger.info("Successfully reloaded the config");
|
||||
} else {
|
||||
logger.warn("Using the old config");
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onServerPreConnectEvent(ServerPreConnectEvent event, Continuation continuation) {
|
||||
Optional<ForgeServerConnection> forgeServerConnectionOptional = forgeHandshakeHandler.getForgeServerConnection(event.getOriginalServer());
|
||||
|
|
@ -88,7 +101,8 @@ public class Ambassador {
|
|||
continuation.resume();
|
||||
} else {
|
||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||
logger.warn("Resync needed");
|
||||
logger.info("Kicking {} because of re-sync needed", event.getPlayer());
|
||||
event.getPlayer().disconnect(Component.text("Please reconnect"));
|
||||
continuation.resume();
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ public class ForgeConnection {
|
|||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
|
||||
byte[] testPacket = ForgeHandshakeUtils.generateTestPacket();
|
||||
//This gets also sent to vanilla
|
||||
connection.sendLoginPluginMessage(MinecraftChannelIdentifier.create("fml", "loginwrapper"), testPacket,
|
||||
responseBody -> {
|
||||
future.complete(responseBody != null);
|
||||
|
|
@ -52,17 +53,20 @@ public class ForgeConnection {
|
|||
future.complete(false);
|
||||
logger.warn("Sync Exception: " + ex);
|
||||
} else {
|
||||
//This gets also sent to vanilla
|
||||
sendModlist(msg.modListPacket).thenAccept((response) -> {
|
||||
if (!ignoreSyncExepction && response == null) {
|
||||
logger.warn("Sync Exception: Client responded with an empty body.");
|
||||
}
|
||||
recivedClientModlist = Optional.ofNullable(response);
|
||||
});
|
||||
//This gets also sent to vanilla
|
||||
sendOther(msg.otherPackets).thenAccept((response) -> {
|
||||
if (!ignoreSyncExepction && response == null) {
|
||||
logger.warn("Sync Exception: Client responded with an empty body.");
|
||||
}
|
||||
ForgeConnection.recivedClientACK = response;
|
||||
//TODO: Generate the ACK packet ourself.
|
||||
ForgeConnection.recivedClientACK = (response == null) ? ForgeConnection.recivedClientACK : response;
|
||||
transmittedHandshake = Optional.of(msg);
|
||||
syncedTo = Optional.of(forgeServerConnection.getServer());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import org.slf4j.Logger;
|
|||
|
||||
public class ForgeHandshakeHandler {
|
||||
|
||||
private final AmbassadorConfig config;
|
||||
private AmbassadorConfig config;
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
|
||||
|
|
@ -97,6 +97,10 @@ public class ForgeHandshakeHandler {
|
|||
forgeServerConnectionMap.remove(server);
|
||||
}
|
||||
|
||||
public void setConfig(AmbassadorConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onServerLoginPluginMessageEvent(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
||||
if (!event.getIdentifier().equals(LOGIN_WRAPPER_ID)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user