1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-19 14:59:20 +00:00

Simplified plugin message channel logic

This commit is contained in:
Tim203
2022-08-30 13:25:09 +02:00
parent 7e930afcef
commit eca042dc82
7 changed files with 29 additions and 66 deletions

View File

@@ -53,21 +53,6 @@ public final class BungeePluginMessageUtils extends PluginMessageUtils implement
return; return;
} }
UUID targetUuid = null;
String targetUsername = null;
Identity targetIdentity = Identity.UNKNOWN;
Connection target = event.getReceiver();
if (target instanceof ProxiedPlayer) {
ProxiedPlayer player = (ProxiedPlayer) target;
targetUuid = player.getUniqueId();
targetUsername = player.getName();
targetIdentity = Identity.PLAYER;
} else if (target instanceof ServerConnection) {
targetIdentity = Identity.SERVER;
}
UUID sourceUuid = null; UUID sourceUuid = null;
String sourceUsername = null; String sourceUsername = null;
Identity sourceIdentity = Identity.UNKNOWN; Identity sourceIdentity = Identity.UNKNOWN;
@@ -83,8 +68,9 @@ public final class BungeePluginMessageUtils extends PluginMessageUtils implement
sourceIdentity = Identity.SERVER; sourceIdentity = Identity.SERVER;
} }
Result result = channel.handleProxyCall(event.getData(), targetUuid, targetUsername, Result result = channel.handleProxyCall(
targetIdentity, sourceUuid, sourceUsername, sourceIdentity); event.getData(), sourceUuid, sourceUsername, sourceIdentity
);
event.setCancelled(!result.isAllowed()); event.setCancelled(!result.isAllowed());

View File

@@ -36,14 +36,12 @@ public interface PluginMessageChannel {
Result handleProxyCall( Result handleProxyCall(
byte[] data, byte[] data,
UUID targetUuid,
String targetUsername,
Identity targetIdentity,
UUID sourceUuid, UUID sourceUuid,
String sourceUsername, String sourceUsername,
Identity sourceIdentity); Identity sourceIdentity
);
Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername); Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername);
@Getter @Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) @RequiredArgsConstructor(access = AccessLevel.PRIVATE)

View File

@@ -56,13 +56,10 @@ public class FormChannel implements PluginMessageChannel {
@Override @Override
public Result handleProxyCall( public Result handleProxyCall(
byte[] data, byte[] data,
UUID targetUuid,
String targetUsername,
Identity targetIdentity,
UUID sourceUuid, UUID sourceUuid,
String sourceUsername, String sourceUsername,
Identity sourceIdentity) { Identity sourceIdentity
) {
if (sourceIdentity == Identity.SERVER) { if (sourceIdentity == Identity.SERVER) {
// send it to the client // send it to the client
return Result.forward(); return Result.forward();
@@ -89,7 +86,7 @@ public class FormChannel implements PluginMessageChannel {
} }
@Override @Override
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) { public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
callResponseConsumer(data); callResponseConsumer(data);
return Result.handled(); return Result.handled();
} }

View File

@@ -40,23 +40,26 @@ public final class PacketChannel implements PluginMessageChannel {
} }
@Override @Override
public Result handleProxyCall(byte[] data, UUID targetUuid, String targetUsername, public Result handleProxyCall(
Identity targetIdentity, UUID sourceUuid, String sourceUsername, byte[] data,
Identity sourceIdentity) { UUID sourceUuid,
String sourceUsername,
Identity sourceIdentity
) {
if (sourceIdentity == Identity.SERVER) { if (sourceIdentity == Identity.SERVER) {
// send it to the client // send it to the client
return Result.forward(); return Result.forward();
} }
if (sourceIdentity == Identity.PLAYER) { if (sourceIdentity == Identity.PLAYER) {
return handleServerCall(data, targetUuid, targetUsername); return handleServerCall(data, sourceUuid, sourceUsername);
} }
return Result.handled(); return Result.handled();
} }
@Override @Override
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) { public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
return Result.kick("Cannot send packets from Geyser/Floodgate to Floodgate"); return Result.kick("Cannot send packets from Geyser/Floodgate to Floodgate");
} }

View File

@@ -51,16 +51,13 @@ public class SkinChannel implements PluginMessageChannel {
@Override @Override
public Result handleProxyCall( public Result handleProxyCall(
byte[] data, byte[] data,
UUID targetUuid,
String targetUsername,
Identity targetIdentity,
UUID sourceUuid, UUID sourceUuid,
String sourceUsername, String sourceUsername,
Identity sourceIdentity) { Identity sourceIdentity
) {
// we can only get skins from Geyser (client) // we can only get skins from Geyser (client)
if (sourceIdentity == Identity.PLAYER) { if (sourceIdentity == Identity.PLAYER) {
Result result = handleServerCall(data, targetUuid, targetUsername); Result result = handleServerCall(data, sourceUuid, sourceUsername);
// aka translate 'handled' into 'forward' when send-floodgate-data is enabled // aka translate 'handled' into 'forward' when send-floodgate-data is enabled
if (!result.isAllowed() && result.getReason() == null) { if (!result.isAllowed() && result.getReason() == null) {
if (config.isProxy() && ((ProxyFloodgateConfig) config).isSendFloodgateData()) { if (config.isProxy() && ((ProxyFloodgateConfig) config).isSendFloodgateData()) {
@@ -78,8 +75,8 @@ public class SkinChannel implements PluginMessageChannel {
} }
@Override @Override
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) { public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
FloodgatePlayer floodgatePlayer = api.getPlayer(targetUuid); FloodgatePlayer floodgatePlayer = api.getPlayer(playerUuid);
if (floodgatePlayer == null) { if (floodgatePlayer == null) {
return Result.kick("Player sent skins data for a non-Floodgate player"); return Result.kick("Player sent skins data for a non-Floodgate player");
} }

View File

@@ -42,27 +42,24 @@ public class TransferChannel implements PluginMessageChannel {
@Override @Override
public Result handleProxyCall( public Result handleProxyCall(
byte[] data, byte[] data,
UUID targetUuid,
String targetUsername,
Identity targetIdentity,
UUID sourceUuid, UUID sourceUuid,
String sourceUsername, String sourceUsername,
Identity sourceIdentity) { Identity sourceIdentity
) {
if (sourceIdentity == Identity.SERVER) { if (sourceIdentity == Identity.SERVER) {
// send it to the client // send it to the client
return Result.forward(); return Result.forward();
} }
if (sourceIdentity == Identity.PLAYER) { if (sourceIdentity == Identity.PLAYER) {
handleServerCall(data, targetUuid, targetUsername); handleServerCall(data, sourceUuid, sourceUsername);
} }
return Result.handled(); return Result.handled();
} }
@Override @Override
public Result handleServerCall(byte[] data, UUID targetUuid, String targetUsername) { public Result handleServerCall(byte[] data, UUID playerUuid, String playerUsername) {
return Result.kick("I'm sorry, I'm unable to transfer a server :("); return Result.kick("I'm sorry, I'm unable to transfer a server :(");
} }

View File

@@ -33,7 +33,6 @@ import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import java.util.UUID; import java.util.UUID;
@@ -64,21 +63,6 @@ public class VelocityPluginMessageUtils extends PluginMessageUtils {
return; return;
} }
UUID targetUuid = null;
String targetUsername = null;
Identity targetIdentity = Identity.UNKNOWN;
ChannelMessageSink target = event.getTarget();
if (target instanceof Player) {
Player player = (Player) target;
targetUuid = player.getUniqueId();
targetUsername = player.getUsername();
targetIdentity = Identity.PLAYER;
} else if (target instanceof ServerConnection) {
targetIdentity = Identity.SERVER;
}
UUID sourceUuid = null; UUID sourceUuid = null;
String sourceUsername = null; String sourceUsername = null;
Identity sourceIdentity = Identity.UNKNOWN; Identity sourceIdentity = Identity.UNKNOWN;
@@ -94,8 +78,9 @@ public class VelocityPluginMessageUtils extends PluginMessageUtils {
sourceIdentity = Identity.SERVER; sourceIdentity = Identity.SERVER;
} }
Result result = channel.handleProxyCall(event.getData(), targetUuid, targetUsername, Result result = channel.handleProxyCall(
targetIdentity, sourceUuid, sourceUsername, sourceIdentity); event.getData(), sourceUuid, sourceUsername, sourceIdentity
);
event.setResult(result.isAllowed() ? ForwardResult.forward() : ForwardResult.handled()); event.setResult(result.isAllowed() ? ForwardResult.forward() : ForwardResult.handled());