fix: ServerLoginNetworkHandlerMixin#isLocal is acting incorrectly

This commit is contained in:
iceBear67 committed 2024-07-14 00:03:39 +08:00
1 parent 3e15f1e8fa
commit 060f0230eb
4 files changed
+18 -20

No files matched your search

@@ -19,7 +19,7 @@ import static io.ib67.sfcraft.callback.Utility.*;
public interface SFCallbacks {
Event<PlayerPreLoginCallback> PRE_LOGIN = EventFactory.createArrayBacked(PlayerPreLoginCallback.class,
(listeners) -> (s, c, d) -> anyMatch(listeners, i -> i.onPlayerPreLogin(s, c, d)));
(listeners) -> (s, c, d, o) -> forEach(listeners, i -> i.onPlayerPreLogin(s, c, d, o)));
Event<PlayerSleepCallback> PLAYER_SLEEP = EventFactory.createArrayBacked(PlayerSleepCallback.class,
l -> (pl, pos) -> anyMatch(l, i -> i.onPlayerSleep(pl, pos), a -> a.left().isPresent())
.orElse(getEitherUnitR()));
@@ -38,10 +38,7 @@ public interface SFCallbacks {
}
interface PlayerPreLoginCallback {
/**
* @return if let in
*/
boolean onPlayerPreLogin(String currentPlayer, ClientConnection connection, Consumer<Text> disconnect);
void onPlayerPreLogin(String currentPlayer, ClientConnection connection, Consumer<Text> disconnect, boolean offline);
}
interface PlayerSleepCallback {
@@ -44,19 +44,14 @@ public abstract class ServerLoginNetworkHandlerMixin {
}
var offlineProfile = Uuids.getOfflinePlayerProfile(currentPlayer);
boolean _r;
if (server.getUserCache() == null) {
// falling back to whitelist
if (server.getUserCache() != null) {
_r = server.getUserCache().getByUuid(offlineProfile.getId()).isPresent();
}else{
var wl = server.getPlayerManager().getWhitelist();
_r = wl.isAllowed(offlineProfile);
} else {
var profile = server.getUserCache().getByUuid(offlineProfile.getId());
_r = profile.isPresent();
}
var result = SFCallbacks.PRE_LOGIN.invoker().onPlayerPreLogin(currentPlayer, connection, this::disconnect);
if (result) {
return _r; // (is offline -> !true -> startVerify)
}
return !_r;
SFCallbacks.PRE_LOGIN.invoker().onPlayerPreLogin(currentPlayer, connection, this::disconnect, _r);
return _r;
}
@@ -10,6 +10,7 @@ import io.ib67.sfcraft.util.SFConsts;
import io.ib67.sfcraft.ServerModule;
import io.ib67.sfcraft.callback.SFCallbacks;
import io.ib67.sfcraft.config.SFConfig;
import lombok.Setter;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.network.ClientConnection;
@@ -29,6 +30,8 @@ public class OfflineExemptModule extends ServerModule {
@Inject
private SFConfig config;
private boolean state;
@Setter
private boolean temporallyState;
@Override
public void onInitialize() {
@@ -63,6 +66,8 @@ public class OfflineExemptModule extends ServerModule {
}
var profile = Uuids.getOfflinePlayerProfile(player);
wl.add(new WhitelistEntry(profile));
var uc = source.getServer().getUserCache();
if (uc != null) uc.add(profile);
source.sendMessage(Text.of("[" + profile.getName() + "/" + profile.getId() + "]" + " is added!"));
return 0;
}
@@ -85,10 +90,12 @@ public class OfflineExemptModule extends ServerModule {
@Override
public void onEnable() {
state = true;
state = temporallyState || config.enableOfflineExempt;
}
private boolean onPreLogin(String s, ClientConnection connection, Consumer<Text> textConsumer) {
return state;
private void onPreLogin(String s, ClientConnection connection, Consumer<Text> textConsumer, boolean offline) {
if (!state && offline) {
textConsumer.accept(Text.of("盗版赦免现已关闭"));
}
}
}
@@ -79,7 +79,7 @@ public class PlayLimitModule extends ServerModule {
}
private boolean onPreLogin(String currentPlayer, ClientConnection connection, Consumer<Text> disconnect) {
private void onPreLogin(String currentPlayer, ClientConnection connection, Consumer<Text> disconnect, boolean offline) {
if (isEnabled() && connection.getAddress() instanceof InetSocketAddress address) {
try {
var clock = geoIPService.clockOf(address.getAddress());
@@ -91,6 +91,5 @@ public class PlayLimitModule extends ServerModule {
System.err.println("Failed to locate " + address.getAddress());
}
}
return true;
}
}