Sending clients modlist instead of a generic one
This commit is contained in:
parent
f20acb15c2
commit
f7121a6092
|
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
group 'org.adde0109'
|
||||
version '0.2.0-SNAPSHOT'
|
||||
version '0.2.1-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
|
|
|||
|
|
@ -3,14 +3,17 @@ package org.adde0109.ambassador;
|
|||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.KickedFromServerEvent;
|
||||
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.ProxyPingEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.adde0109.ambassador.forge.ForgeConnection;
|
||||
|
|
@ -23,14 +26,13 @@ import org.slf4j.Logger;
|
|||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "0.2.0-SNAPSHOT", authors = {"adde0109"})
|
||||
@Plugin(id = "ambassador", name = "Ambassador", version = "0.2.1-SNAPSHOT", authors = {"adde0109"})
|
||||
public class Ambassador {
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Metrics.Factory metricsFactory;
|
||||
private final Path dataDirectory;
|
||||
private Optional<RegisteredServer> forgeServer;
|
||||
private AmbassadorConfig config;
|
||||
|
||||
private ForgeHandshakeHandler forgeHandshakeHandler;
|
||||
|
|
@ -86,8 +88,6 @@ public class Ambassador {
|
|||
}
|
||||
//Register newly discovered forge server
|
||||
if (forgeServerConnectionOptional.isEmpty()) {
|
||||
forgeServerConnection.setDefaultClientModlist(forgeConnection.get().getRecivedClientModlist());
|
||||
forgeServerConnection.setDefaultClientACK(ForgeConnection.getRecivedClientACK());
|
||||
forgeHandshakeHandler.registerForgeServer(event.getOriginalServer(), forgeServerConnection);
|
||||
}
|
||||
|
||||
|
|
@ -102,6 +102,10 @@ public class Ambassador {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onKickedFromServerEvent(KickedFromServerEvent event, Continuation continuation) {
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerChooseInitialServerEvent(PlayerChooseInitialServerEvent event, Continuation continuation) {
|
||||
|
|
@ -115,5 +119,4 @@ public class Ambassador {
|
|||
}
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package org.adde0109.ambassador.forge;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.api.event.player.ServerLoginPluginMessageEvent;
|
||||
import com.velocitypowered.api.proxy.LoginPhaseConnection;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import java.io.EOFException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
|
@ -21,16 +24,17 @@ public class ForgeConnection {
|
|||
}
|
||||
|
||||
|
||||
public static CompletableFuture<ForgeConnection> sync(LoginPhaseConnection connection, ForgeServerConnection forgeServerConnection, Continuation continuation) {
|
||||
public static CompletableFuture<ForgeConnection> sync(LoginPhaseConnection connection,
|
||||
ForgeServerConnection forgeServerConnection,
|
||||
Continuation continuation) {
|
||||
CompletableFuture<ForgeConnection> future = new CompletableFuture<>();
|
||||
ForgeConnection forgeConnection = new ForgeConnection(connection);
|
||||
forgeServerConnection.getHandshake().whenComplete((msg,ex) -> {
|
||||
forgeServerConnection.getHandshake().whenComplete((msg, ex) -> {
|
||||
if (ex != null) {
|
||||
future.completeExceptionally(ex);
|
||||
} else {
|
||||
forgeConnection.sendModlist(msg.modListPacket).thenAccept((response) -> {
|
||||
if (response != null) {
|
||||
forgeServerConnection.setDefaultClientModlist(response);
|
||||
future.complete(forgeConnection);
|
||||
} else {
|
||||
future.complete(null);
|
||||
|
|
@ -38,7 +42,6 @@ public class ForgeConnection {
|
|||
});
|
||||
forgeConnection.sendOther(msg.otherPackets).thenAccept((response) -> {
|
||||
if (response != null) {
|
||||
forgeServerConnection.setDefaultClientACK(response);
|
||||
future.complete(forgeConnection);
|
||||
} else {
|
||||
future.complete(null);
|
||||
|
|
@ -54,26 +57,45 @@ public class ForgeConnection {
|
|||
|
||||
public CompletableFuture<byte[]> sendModlist(byte[] modListPacket) {
|
||||
CompletableFuture<byte[]> future = new CompletableFuture<>();
|
||||
connection.sendLoginPluginMessage(MinecraftChannelIdentifier.create("fml","loginwrapper"), modListPacket,
|
||||
connection.sendLoginPluginMessage(MinecraftChannelIdentifier.create("fml", "loginwrapper"), modListPacket,
|
||||
responseBody -> {
|
||||
recivedClientModlist = responseBody;
|
||||
future.complete(recivedClientModlist);
|
||||
recivedClientModlist = responseBody;
|
||||
future.complete(recivedClientModlist);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
CompletableFuture<byte[]> sendOther(List<byte[]> otherPackets) {
|
||||
CompletableFuture<byte[]> future = new CompletableFuture<>();
|
||||
for (int i = 0;i<otherPackets.size();i++) {
|
||||
connection.sendLoginPluginMessage(MinecraftChannelIdentifier.create("fml","loginwrapper"), otherPackets.get(i),
|
||||
(i<(otherPackets.size()-1)) ? responseBody -> {} : responseBody -> {
|
||||
recivedClientACK = responseBody;
|
||||
future.complete(responseBody);
|
||||
for (int i = 0; i < otherPackets.size(); i++) {
|
||||
connection.sendLoginPluginMessage(MinecraftChannelIdentifier.create("fml", "loginwrapper"), otherPackets.get(i),
|
||||
(i < (otherPackets.size() - 1)) ? responseBody -> {
|
||||
} : responseBody -> {
|
||||
if (responseBody != null)
|
||||
recivedClientACK = responseBody;
|
||||
future.complete(responseBody);
|
||||
});
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
public void handleServerHandshakePacket(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
||||
ByteArrayDataInput data = event.contentsAsDataStream();
|
||||
if (data.skipBytes(14) != 14) { //Channel Identifier
|
||||
continuation.resumeWithException(new EOFException());
|
||||
return;
|
||||
}
|
||||
ForgeHandshakeUtils.readVarInt(data); //Length
|
||||
int packetID = ForgeHandshakeUtils.readVarInt(data);
|
||||
|
||||
if (packetID == 1) {
|
||||
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(getRecivedClientModlist()));
|
||||
} else {
|
||||
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(getRecivedClientACK()));
|
||||
}
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
public LoginPhaseConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.adde0109.ambassador.forge;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||
|
|
@ -8,6 +9,7 @@ import com.velocitypowered.api.proxy.LoginPhaseConnection;
|
|||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import java.io.EOFException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -85,14 +87,11 @@ public class ForgeHandshakeHandler {
|
|||
|
||||
@Subscribe
|
||||
public void onServerLoginPluginMessageEvent(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
||||
//Only respond the servers that we can respond to
|
||||
if((!forgeServerConnectionMap.containsKey(event.getConnection().getServer())
|
||||
|| (getForgeConnection(event.getConnection().getPlayer()).isEmpty()))) {
|
||||
if (incomingForgeConnections.containsKey(event.getConnection().getPlayer().getRemoteAddress())) {
|
||||
incomingForgeConnections.get(event.getConnection().getPlayer().getRemoteAddress())
|
||||
.handleServerHandshakePacket(event,continuation);
|
||||
} else {
|
||||
continuation.resume();
|
||||
return;
|
||||
}
|
||||
//Grab the connection responsible for this - no pun intended
|
||||
ForgeServerConnection connection = forgeServerConnectionMap.get(event.getConnection().getServer());
|
||||
connection.handle(event,continuation);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ public class ForgeServerConnection {
|
|||
private final Logger logger;
|
||||
private final RegisteredServer handshakeServer;
|
||||
private ForgeHandshakeUtils.CachedServerHandshake handshake;
|
||||
private byte[] defaultClientModlist;
|
||||
private byte[] defaultClientACK;
|
||||
|
||||
public RegisteredServer getServer() {
|
||||
return handshakeServer;
|
||||
|
|
@ -38,32 +36,6 @@ public class ForgeServerConnection {
|
|||
return future;
|
||||
}
|
||||
|
||||
public void handle(ServerLoginPluginMessageEvent event, Continuation continuation) {
|
||||
ByteArrayDataInput data = event.contentsAsDataStream();
|
||||
if(data.skipBytes(PACKET_LENGTH_INDEX) != PACKET_LENGTH_INDEX) { //Channel Identifier
|
||||
continuation.resumeWithException(new EOFException());
|
||||
return;
|
||||
}
|
||||
ForgeHandshakeUtils.readVarInt(data); //Length
|
||||
int packetID = ForgeHandshakeUtils.readVarInt(data);
|
||||
|
||||
if(packetID == 1) {
|
||||
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(defaultClientModlist));
|
||||
}
|
||||
else {
|
||||
event.setResult(ServerLoginPluginMessageEvent.ResponseResult.reply(defaultClientACK));
|
||||
}
|
||||
continuation.resume();
|
||||
}
|
||||
|
||||
public void setDefaultClientModlist(byte[] modlist) {
|
||||
this.defaultClientModlist = modlist;
|
||||
}
|
||||
|
||||
public void setDefaultClientACK(byte[] ACK) {
|
||||
this.defaultClientACK = ACK;
|
||||
}
|
||||
|
||||
public ServerInfo getServerInfo() {
|
||||
return handshakeServer.getServerInfo();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user