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