Search in sources :

Example 1 with SpongeGameProfile

use of org.spongepowered.common.profile.SpongeGameProfile in project SpongeCommon by SpongePowered.

the class PlayerListMixin method impl$canPlayerLoginServer.

protected final CompletableFuture<net.minecraft.network.chat.Component> impl$canPlayerLoginServer(final SocketAddress param0, final com.mojang.authlib.GameProfile param1) {
    final SpongeGameProfile profile = SpongeGameProfile.basicOf(param1);
    return Sponge.server().serviceProvider().banService().find(profile).thenCompose(profileBanOpt -> {
        if (profileBanOpt.isPresent()) {
            final Ban.Profile var0 = profileBanOpt.get();
            final MutableComponent var1 = new TranslatableComponent("multiplayer.disconnect.banned.reason", var0.reason().orElse(Component.empty()));
            if (var0.expirationDate().isPresent()) {
                var1.append(new TranslatableComponent("multiplayer.disconnect.banned.expiration", BAN_DATE_FORMAT.format(var0.expirationDate().get())));
            }
            return CompletableFuture.completedFuture(var1);
        }
        if (param0 instanceof LocalAddress) {
            // don't bother looking up IP bans on local address
            return CompletableFuture.completedFuture(null);
        }
        final InetAddress address;
        try {
            address = InetAddress.getByName(NetworkUtil.getHostString(param0));
        } catch (final UnknownHostException ex) {
            // no
            return CompletableFuture.completedFuture(new TextComponent(ex.getMessage()));
        }
        return Sponge.server().serviceProvider().banService().find(address).thenCompose(ipBanOpt -> {
            if (ipBanOpt.isPresent()) {
                final Ban.IP var2 = ipBanOpt.get();
                final MutableComponent var3 = new TranslatableComponent("multiplayer.disconnect.banned_ip.reason", var2.reason().orElse(Component.empty()));
                if (var2.expirationDate().isPresent()) {
                    var3.append(new TranslatableComponent("multiplayer.disconnect.banned_ip.expiration", BAN_DATE_FORMAT.format(var2.expirationDate().get())));
                }
                return CompletableFuture.completedFuture(var3);
            }
            return CompletableFuture.supplyAsync(() -> {
                if (!Sponge.server().isWhitelistEnabled()) {
                    return true;
                }
                final PermissionService permissionService = Sponge.server().serviceProvider().permissionService();
                Subject subject = permissionService.userSubjects().subject(param1.getId().toString()).orElse(null);
                if (subject == null) {
                    subject = permissionService.defaults();
                }
                return subject.hasPermission(LoginPermissions.BYPASS_WHITELIST_PERMISSION);
            }, SpongeCommon.server()).thenCompose(w -> {
                if (w) {
                    return CompletableFuture.completedFuture(null);
                }
                return Sponge.server().serviceProvider().whitelistService().isWhitelisted(profile).<net.minecraft.network.chat.Component>thenApply(whitelisted -> {
                    if (!whitelisted) {
                        return new TranslatableComponent("multiplayer.disconnect.not_whitelisted");
                    }
                    return null;
                });
            });
        });
    }).thenApplyAsync(component -> {
        if (component != null) {
            return component;
        }
        if (this.players.size() >= this.maxPlayers && !this.shadow$canBypassPlayerLimit(param1)) {
            return new TranslatableComponent("multiplayer.disconnect.server_full");
        }
        return null;
    }, SpongeCommon.server());
}
Also used : ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) ConnectionBridge(org.spongepowered.common.bridge.network.ConnectionBridge) SpongeUserBanList(org.spongepowered.common.service.server.ban.SpongeUserBanList) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) Inject(org.spongepowered.asm.mixin.injection.Inject) Connection(net.minecraft.network.Connection) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) PermissionService(org.spongepowered.api.service.permission.PermissionService) PlayerList(net.minecraft.server.players.PlayerList) LocalAddress(io.netty.channel.local.LocalAddress) InetAddress(java.net.InetAddress) MinecraftServer(net.minecraft.server.MinecraftServer) IntegratedPlayerListBridge(org.spongepowered.common.bridge.client.server.IntegratedPlayerListBridge) ClientboundPlayerInfoPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundPlayerInfoPacketAccessor) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) GameProfile(org.spongepowered.api.profile.GameProfile) PlayerInventoryTransaction(org.spongepowered.common.event.tracking.context.transaction.inventory.PlayerInventoryTransaction) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) ServerScoreboardBridge(org.spongepowered.common.bridge.server.ServerScoreboardBridge) PlayerListBridge(org.spongepowered.common.bridge.server.players.PlayerListBridge) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) IpBanList(net.minecraft.server.players.IpBanList) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Set(java.util.Set) RegistryAccess(net.minecraft.core.RegistryAccess) TextComponent(net.minecraft.network.chat.TextComponent) Logger(org.apache.logging.log4j.Logger) BroadcastInventoryChangesEffect(org.spongepowered.common.event.tracking.context.transaction.effect.BroadcastInventoryChangesEffect) SpongeUserView(org.spongepowered.common.entity.player.SpongeUserView) Shadow(org.spongepowered.asm.mixin.Shadow) Packet(net.minecraft.network.protocol.Packet) GameType(net.minecraft.world.level.GameType) ServerLocation(org.spongepowered.api.world.server.ServerLocation) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) Ban(org.spongepowered.api.service.ban.Ban) SimpleDateFormat(java.text.SimpleDateFormat) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) MutableComponent(net.minecraft.network.chat.MutableComponent) UserBanList(net.minecraft.server.players.UserBanList) ServerScoreboard(net.minecraft.server.ServerScoreboard) SpongeIPBanList(org.spongepowered.common.service.server.ban.SpongeIPBanList) PerWorldBorderListener(org.spongepowered.common.server.PerWorldBorderListener) Nullable(javax.annotation.Nullable) Opcodes(org.objectweb.asm.Opcodes) Identity(net.kyori.adventure.identity.Identity) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) UnknownHostException(java.net.UnknownHostException) Cause(org.spongepowered.api.event.Cause) Audience(net.kyori.adventure.audience.Audience) LoginPermissions(org.spongepowered.common.entity.player.LoginPermissions) VecHelper(org.spongepowered.common.util.VecHelper) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) SocketAddress(java.net.SocketAddress) SpongeServer(org.spongepowered.common.SpongeServer) RespawnPlayerEvent(org.spongepowered.api.event.entity.living.player.RespawnPlayerEvent) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) EventContext(org.spongepowered.api.event.EventContext) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) SpongeUserWhiteList(org.spongepowered.common.service.server.whitelist.SpongeUserWhiteList) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) Subject(org.spongepowered.api.service.permission.Subject) At(org.spongepowered.asm.mixin.injection.At) User(org.spongepowered.api.entity.living.player.User) NetworkUtil(org.spongepowered.common.util.NetworkUtil) Sponge(org.spongepowered.api.Sponge) ChatType(net.minecraft.network.chat.ChatType) UUID(java.util.UUID) Final(org.spongepowered.asm.mixin.Final) Instant(java.time.Instant) ClientboundDisconnectPacket(net.minecraft.network.protocol.game.ClientboundDisconnectPacket) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) Optional(java.util.Optional) ClientboundRespawnPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundRespawnPacketAccessor) Level(net.minecraft.world.level.Level) UserWhiteList(net.minecraft.server.players.UserWhiteList) Constants(org.spongepowered.common.util.Constants) CustomBossEvents(net.minecraft.server.bossevents.CustomBossEvents) CompletableFuture(java.util.concurrent.CompletableFuture) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) WorldBorder(net.minecraft.world.level.border.WorldBorder) Component(net.kyori.adventure.text.Component) BorderChangeListener(net.minecraft.world.level.border.BorderChangeListener) Audiences(org.spongepowered.api.adventure.Audiences) Mutable(org.spongepowered.asm.mixin.Mutable) VanishableBridge(org.spongepowered.common.bridge.data.VanishableBridge) SpongeCommon(org.spongepowered.common.SpongeCommon) ClientboundLoginPacket(net.minecraft.network.protocol.game.ClientboundLoginPacket) ResourceKey(net.minecraft.resources.ResourceKey) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) Vector3d(org.spongepowered.math.vector.Vector3d) Slice(org.spongepowered.asm.mixin.injection.Slice) TextComponent(net.minecraft.network.chat.TextComponent) LocalAddress(io.netty.channel.local.LocalAddress) UnknownHostException(java.net.UnknownHostException) GameProfile(org.spongepowered.api.profile.GameProfile) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) Subject(org.spongepowered.api.service.permission.Subject) PermissionService(org.spongepowered.api.service.permission.PermissionService) MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) InetAddress(java.net.InetAddress)

Aggregations

LocalAddress (io.netty.channel.local.LocalAddress)1 InetAddress (java.net.InetAddress)1 SocketAddress (java.net.SocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Instant (java.time.Instant)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Nullable (javax.annotation.Nullable)1 Audience (net.kyori.adventure.audience.Audience)1 Identity (net.kyori.adventure.identity.Identity)1 Component (net.kyori.adventure.text.Component)1 BlockPos (net.minecraft.core.BlockPos)1 RegistryAccess (net.minecraft.core.RegistryAccess)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 Connection (net.minecraft.network.Connection)1