mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-15 11:21:56 +01:00
Allow unregistered players in not enforced config to use tab
This commit is contained in:
parent
a8ebe70900
commit
f52e6a1a2f
@ -54,14 +54,14 @@ class InventoryPacketAdapter extends PacketAdapter {
|
||||
private final PlayerCache playerCache;
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final boolean isRegistrationForced;
|
||||
private final ProtocolLibService protocolLibService;
|
||||
|
||||
InventoryPacketAdapter(AuthMe plugin, PlayerCache playerCache, DataSource dataSource,
|
||||
boolean isRegistrationForced) {
|
||||
ProtocolLibService protocolLibService) {
|
||||
super(plugin, PacketType.Play.Server.SET_SLOT, PacketType.Play.Server.WINDOW_ITEMS);
|
||||
this.playerCache = playerCache;
|
||||
this.dataSource = dataSource;
|
||||
this.isRegistrationForced = isRegistrationForced;
|
||||
this.protocolLibService = protocolLibService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,7 +70,7 @@ class InventoryPacketAdapter extends PacketAdapter {
|
||||
PacketContainer packet = packetEvent.getPacket();
|
||||
|
||||
int windowId = packet.getIntegers().read(0);
|
||||
if (windowId == PLAYER_INVENTORY && shouldHideInventory(player.getName())) {
|
||||
if (windowId == PLAYER_INVENTORY && protocolLibService.shouldRestrictPlayer(player.getName())) {
|
||||
packetEvent.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -84,27 +84,10 @@ class InventoryPacketAdapter extends PacketAdapter {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
||||
|
||||
bukkitService.getOnlinePlayers().stream()
|
||||
.filter(player -> shouldHideInventory(player.getName()))
|
||||
.filter(player -> protocolLibService.shouldRestrictPlayer(player.getName()))
|
||||
.forEach(this::sendBlankInventoryPacket);
|
||||
}
|
||||
|
||||
private boolean shouldHideInventory(String playerName) {
|
||||
if (playerCache.isAuthenticated(playerName)) {
|
||||
// fully logged in - no need to protect it
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dataSource.isCached()) {
|
||||
// load from cache or only request once
|
||||
return dataSource.isAuthAvailable(playerName);
|
||||
}
|
||||
|
||||
// data source is not cached - this means queries would run blocking
|
||||
// If registration is enforced: **assume** player is registered to prevent any information leak
|
||||
// If not, players could play even without a registration, so there is no need for protection
|
||||
return isRegistrationForced;
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(this);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
if (protectInvBeforeLogin) {
|
||||
if (inventoryPacketAdapter == null) {
|
||||
// register the packet listener and start hiding it for all already online players (reload)
|
||||
inventoryPacketAdapter = new InventoryPacketAdapter(plugin, playerCache, dataSource, isRegistrationForced);
|
||||
inventoryPacketAdapter = new InventoryPacketAdapter(plugin, playerCache, dataSource, this);
|
||||
inventoryPacketAdapter.register(bukkitService);
|
||||
}
|
||||
} else if (inventoryPacketAdapter != null) {
|
||||
@ -78,7 +78,7 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
|
||||
if (denyTabCompleteBeforeLogin) {
|
||||
if (tabCompletePacketAdapter == null) {
|
||||
tabCompletePacketAdapter = new TabCompletePacketAdapter(plugin, playerCache);
|
||||
tabCompletePacketAdapter = new TabCompletePacketAdapter(plugin, this);
|
||||
tabCompletePacketAdapter.register();
|
||||
}
|
||||
} else if (tabCompletePacketAdapter != null) {
|
||||
@ -116,6 +116,23 @@ public class ProtocolLibService implements SettingsDependent {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldRestrictPlayer(String playerName) {
|
||||
if (playerCache.isAuthenticated(playerName)) {
|
||||
// fully logged in - no need to protect it
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dataSource.isCached()) {
|
||||
// load from cache or only request once
|
||||
return dataSource.isAuthAvailable(playerName);
|
||||
}
|
||||
|
||||
// data source is not cached - this means queries would run blocking
|
||||
// If registration is enforced: **assume** player is registered to prevent any information leak
|
||||
// If not, players could play even without a registration, so there is no need for protection
|
||||
return isRegistrationForced;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(Settings settings) {
|
||||
boolean oldProtectInventory = this.protectInvBeforeLogin;
|
||||
|
@ -8,24 +8,25 @@ import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
|
||||
class TabCompletePacketAdapter extends PacketAdapter {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(TabCompletePacketAdapter.class);
|
||||
private final PlayerCache playerCache;
|
||||
|
||||
TabCompletePacketAdapter(AuthMe plugin, PlayerCache playerCache) {
|
||||
private final ProtocolLibService protocolLibService;
|
||||
|
||||
TabCompletePacketAdapter(AuthMe plugin, ProtocolLibService protocolLibService) {
|
||||
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE);
|
||||
this.playerCache = playerCache;
|
||||
this.protocolLibService = protocolLibService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
|
||||
try {
|
||||
if (!playerCache.isAuthenticated(event.getPlayer().getName())) {
|
||||
String playerName = event.getPlayer().getName();
|
||||
if (protocolLibService.shouldRestrictPlayer(playerName)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (FieldAccessException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user