mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-30 04:02:04 +01:00
Make console detection more resilient against spoofed UUIDs
This commit is contained in:
parent
53bb61f9b2
commit
e3138eb94c
@ -94,6 +94,11 @@ public class BukkitSenderFactory extends SenderFactory<LPBukkitPlugin, CommandSe
|
||||
getPlugin().getBootstrap().getServer().dispatchCommand(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConsole(CommandSender sender) {
|
||||
return sender instanceof ConsoleCommandSender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
|
@ -81,6 +81,11 @@ public class BungeeSenderFactory extends SenderFactory<LPBungeePlugin, CommandSe
|
||||
getPlugin().getBootstrap().getProxy().getPluginManager().dispatchCommand(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConsole(CommandSender sender) {
|
||||
return !(sender instanceof ProxiedPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
|
@ -52,6 +52,7 @@ public final class AbstractSender<T> implements Sender {
|
||||
|
||||
private final UUID uniqueId;
|
||||
private final String name;
|
||||
private final boolean isConsole;
|
||||
|
||||
AbstractSender(LuckPermsPlugin plugin, SenderFactory<?, T> factory, T sender) {
|
||||
this.plugin = plugin;
|
||||
@ -59,6 +60,7 @@ public final class AbstractSender<T> implements Sender {
|
||||
this.sender = sender;
|
||||
this.uniqueId = factory.getUniqueId(this.sender);
|
||||
this.name = factory.getName(this.sender);
|
||||
this.isConsole = this.factory.isConsole(this.sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,6 +104,11 @@ public final class AbstractSender<T> implements Sender {
|
||||
this.factory.performCommand(this.sender, commandLine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsole() {
|
||||
return this.isConsole;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return isConsole() || this.plugin.getBootstrap().isPlayerOnline(this.uniqueId);
|
||||
|
@ -31,16 +31,16 @@ import net.luckperms.api.util.Tristate;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class DummySender implements Sender {
|
||||
public abstract class DummyConsoleSender implements Sender {
|
||||
private final LuckPermsPlugin platform;
|
||||
|
||||
private final UUID uniqueId;
|
||||
private final String name;
|
||||
|
||||
public DummySender(LuckPermsPlugin plugin, UUID uniqueId, String name) {
|
||||
public DummyConsoleSender(LuckPermsPlugin plugin) {
|
||||
this.platform = plugin;
|
||||
this.uniqueId = uniqueId;
|
||||
this.name = name;
|
||||
this.uniqueId = Sender.CONSOLE_UUID;
|
||||
this.name = Sender.CONSOLE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,6 +58,11 @@ public abstract class DummySender implements Sender {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsole() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsPlugin getPlugin() {
|
||||
return this.platform;
|
@ -149,9 +149,7 @@ public interface Sender {
|
||||
*
|
||||
* @return if the sender is the console
|
||||
*/
|
||||
default boolean isConsole() {
|
||||
return CONSOLE_UUID.equals(getUniqueId());
|
||||
}
|
||||
boolean isConsole();
|
||||
|
||||
/**
|
||||
* Gets whether this sender is still valid & receiving messages.
|
||||
|
@ -62,6 +62,8 @@ public abstract class SenderFactory<P extends LuckPermsPlugin, T> implements Aut
|
||||
|
||||
protected abstract void performCommand(T sender, String command);
|
||||
|
||||
protected abstract boolean isConsole(T sender);
|
||||
|
||||
public final Sender wrap(T sender) {
|
||||
Objects.requireNonNull(sender, "sender");
|
||||
return new AbstractSender<>(this.plugin, this, sender);
|
||||
|
@ -104,6 +104,11 @@ public class FabricSenderFactory extends SenderFactory<LPFabricPlugin, ServerCom
|
||||
sender.getMinecraftServer().getCommandManager().execute(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConsole(ServerCommandSource sender) {
|
||||
return sender.getEntity() == null;
|
||||
}
|
||||
|
||||
public static Text toNativeText(Component component) {
|
||||
return Text.Serializer.fromJson(GsonComponentSerializer.gson().serialize(component));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import me.lucko.luckperms.common.model.manager.group.StandardGroupManager;
|
||||
import me.lucko.luckperms.common.model.manager.track.StandardTrackManager;
|
||||
import me.lucko.luckperms.common.model.manager.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.DummySender;
|
||||
import me.lucko.luckperms.common.sender.DummyConsoleSender;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
@ -221,7 +221,7 @@ public class LPFabricPlugin extends AbstractLuckPermsPlugin {
|
||||
public Sender getConsoleSender() {
|
||||
return this.bootstrap.getServer()
|
||||
.map(s -> this.senderFactory.wrap(s.getCommandSource()))
|
||||
.orElseGet(() -> new DummySender(this, Sender.CONSOLE_UUID, Sender.CONSOLE_NAME) {
|
||||
.orElseGet(() -> new DummyConsoleSender(this) {
|
||||
@Override
|
||||
public void sendMessage(Component message) {
|
||||
LPFabricPlugin.this.bootstrap.getPluginLogger().info(PlainComponentSerializer.plain().serialize(TranslationManager.render(message)));
|
||||
|
@ -35,6 +35,7 @@ import net.luckperms.api.util.Tristate;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
import cn.nukkit.command.CommandSender;
|
||||
import cn.nukkit.command.ConsoleCommandSender;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
@ -92,4 +93,8 @@ public class NukkitSenderFactory extends SenderFactory<LPNukkitPlugin, CommandSe
|
||||
getPlugin().getBootstrap().getServer().dispatchCommand(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConsole(CommandSender sender) {
|
||||
return sender instanceof ConsoleCommandSender;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import me.lucko.luckperms.common.messaging.MessagingFactory;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.model.manager.track.StandardTrackManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.DummySender;
|
||||
import me.lucko.luckperms.common.sender.DummyConsoleSender;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
@ -250,7 +250,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
||||
if (this.bootstrap.getGame().isServerAvailable()) {
|
||||
return this.senderFactory.wrap(this.bootstrap.getGame().getServer().getConsole());
|
||||
} else {
|
||||
return new DummySender(this, Sender.CONSOLE_UUID, Sender.CONSOLE_NAME) {
|
||||
return new DummyConsoleSender(this) {
|
||||
@Override
|
||||
public void sendMessage(Component message) {
|
||||
LPSpongePlugin.this.getLogger().info(LegacyComponentSerializer.legacySection().serialize(TranslationManager.render(message)));
|
||||
|
@ -35,6 +35,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.command.source.ConsoleSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
@ -89,6 +90,11 @@ public class SpongeSenderFactory extends SenderFactory<LPSpongePlugin, CommandSo
|
||||
getPlugin().getBootstrap().getGame().getCommandManager().process(source, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConsole(CommandSource sender) {
|
||||
return sender instanceof ConsoleSource;
|
||||
}
|
||||
|
||||
public static Text toNativeText(Component component) {
|
||||
return TextSerializers.JSON.deserialize(GsonComponentSerializer.gson().serialize(component));
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.velocity;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import me.lucko.luckperms.common.locale.TranslationManager;
|
||||
@ -85,4 +86,9 @@ public class VelocitySenderFactory extends SenderFactory<LPVelocityPlugin, Comma
|
||||
protected void performCommand(CommandSource source, String command) {
|
||||
getPlugin().getBootstrap().getProxy().getCommandManager().executeAsync(source, command).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConsole(CommandSource sender) {
|
||||
return sender instanceof ConsoleCommandSource;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user