Skip to content

Commit

Permalink
Added code on kick support for require-link servers. Added spotless
Browse files Browse the repository at this point in the history
Fixes #396
  • Loading branch information
Tim203 committed Oct 15, 2024
1 parent 330b46a commit c09b348
Show file tree
Hide file tree
Showing 57 changed files with 902 additions and 1,302 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2022 GeyserMC
Copyright (c) 2019-2024 GeyserMC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repositories {
dependencies {
implementation(libs.indra.common)
implementation(libs.indra.git)
implementation(libs.indra.licenser.spotless)
implementation(libs.shadow)
implementation(libs.gradle.idea.ext)
}
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/floodgate.base-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
// id("net.ltgt.errorprone")
id("net.kyori.indra")
id("net.kyori.indra.git")
id("net.kyori.indra.licenser.spotless")
id("floodgate.depsize")
}

Expand All @@ -21,6 +22,15 @@ indra {
javaVersions {
target(17)
}

}

spotless {
java {
palantirJavaFormat()
formatAnnotations()
}
ratchetFrom("origin/development")
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* Copyright (c) 2019-2024 GeyserMC
* Licensed under the MIT license
* @link https://github.com/GeyserMC/Floodgate
*/

package org.geysermc.floodgate.bungee.addon.data;

import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import net.kyori.adventure.text.Component;
import org.geysermc.api.connection.Connection;
import org.geysermc.floodgate.core.addon.data.PacketBlocker;
import org.geysermc.floodgate.core.api.inject.InjectorAddon;
Expand Down Expand Up @@ -70,7 +51,7 @@ public class BungeeDataAddon implements InjectorAddon<Channel> {

@Inject
@Named("kickMessageAttribute")
AttributeKey<String> kickMessageAttribute;
AttributeKey<Component> kickMessageAttribute;

@Inject
BungeeServerDataHandler serverDataHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* Copyright (c) 2019-2024 GeyserMC
* Licensed under the MIT license
* @link https://github.com/GeyserMC/Floodgate
*/

package org.geysermc.floodgate.bungee.addon.data;

import static java.util.Objects.requireNonNull;
Expand All @@ -31,6 +11,7 @@
import io.netty.util.AttributeKey;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.HandlerBoss;
Expand Down Expand Up @@ -65,7 +46,7 @@ public BungeeProxyDataHandler(
ProxyFloodgateConfig config,
FloodgateLogger logger,
AttributeKey<Connection> connectionAttribute,
AttributeKey<String> kickMessageAttribute,
AttributeKey<Component> kickMessageAttribute,
PacketBlocker blocker) {
super(dataSeeker, handshakeHandler, config, logger, connectionAttribute, kickMessageAttribute, blocker);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* Copyright (c) 2019-2024 GeyserMC
* Licensed under the MIT license
* @link https://github.com/GeyserMC/Floodgate
*/

package org.geysermc.floodgate.bungee.listener;

import static java.util.Objects.requireNonNull;
Expand All @@ -32,6 +12,8 @@
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import java.lang.reflect.Field;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
Expand All @@ -49,6 +31,7 @@
import org.geysermc.floodgate.core.listener.McListener;
import org.geysermc.floodgate.core.skin.SkinApplier;
import org.geysermc.floodgate.core.skin.SkinDataImpl;
import org.geysermc.floodgate.core.util.Constants;
import org.geysermc.floodgate.core.util.LanguageManager;
import org.geysermc.floodgate.core.util.MojangUtils;
import org.geysermc.floodgate.core.util.ReflectionUtils;
Expand All @@ -62,17 +45,30 @@ public final class BungeeListener implements Listener, McListener {
requireNonNull(PLAYER_NAME, "Initial name field cannot be null");
}

@Inject Plugin plugin;
@Inject BungeeConnectionManager connectionManager;
@Inject ProxyFloodgateConfig config;
@Inject SimpleFloodgateApi api;
@Inject LanguageManager languageManager;
@Inject SkinApplier skinApplier;
@Inject MojangUtils mojangUtils;
@Inject
Plugin plugin;

@Inject
BungeeConnectionManager connectionManager;

@Inject
ProxyFloodgateConfig config;

@Inject
SimpleFloodgateApi api;

@Inject
LanguageManager languageManager;

@Inject
SkinApplier skinApplier;

@Inject
MojangUtils mojangUtils;

@Inject
@Named("kickMessageAttribute")
AttributeKey<String> kickMessageAttribute;
AttributeKey<Component> kickMessageAttribute;

@EventHandler(priority = EventPriority.LOWEST)
public void onPreLogin(PreLoginEvent event) {
Expand All @@ -85,10 +81,14 @@ public void onPreLogin(PreLoginEvent event) {
var channel = connectionManager.channelFor(pendingConnection);

// check if the player has to be kicked
String kickReason = channel.attr(kickMessageAttribute).get();
Component kickReason = channel.attr(kickMessageAttribute).get();
if (kickReason != null) {
event.setCancelled(true);
event.setCancelReason(kickReason);
if (pendingConnection.getVersion() >= Constants.PROTOCOL_HEX_COLOR) {
event.setCancelReason(BungeeComponentSerializer.get().serialize(kickReason));
} else {
event.setCancelReason(BungeeComponentSerializer.legacy().serialize(kickReason));
}
return;
}

Expand Down
3 changes: 3 additions & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
api(libs.cloud.core)
api(libs.snakeyaml)
api(libs.bstats)

api(libs.adventure.text.minimessage)

api(libs.micronaut.inject)
Expand All @@ -38,6 +39,8 @@ dependencies {

testImplementation(libs.junit.jupiter)
testRuntimeOnly(libs.junit.platform.launcher)

api(libs.expiringmap)
}

providedDependency(libs.slf4j)
Expand Down
Loading

0 comments on commit c09b348

Please sign in to comment.