Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@
<scope>provided</scope>
</dependency>

<!-- Bedrock player bridge for low level checks -->
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.2.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!--Login plugin-->
<dependency>
<groupId>me.vik1395</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* SPDX-License-Identifier: MIT
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2021 <Your name and contributors>
*
* 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.
*/
package com.github.games647.fastlogin.bungee;

import com.github.games647.fastlogin.core.shared.LoginSource;

import java.net.InetSocketAddress;

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.event.LoginEvent;

public class BungeeFloodgateLoginSource implements LoginSource {

private final PendingConnection connection;
private final LoginEvent loginEvent;

public BungeeFloodgateLoginSource(PendingConnection connection, LoginEvent loginEvent) {
this.connection = connection;
this.loginEvent = loginEvent;
}

@Override
public void enableOnlinemode() {
connection.setOnlineMode(true);
}

@Override
public void kick(String message) {
loginEvent.setCancelled(true);

if (message == null) {
loginEvent.setCancelReason(new ComponentBuilder("Kicked").color(ChatColor.WHITE).create());
} else {
loginEvent.setCancelReason(TextComponent.fromLegacyText(message));
}
}

@Override
public InetSocketAddress getAddress() {
return connection.getAddress();
}

public PendingConnection getConnection() {
return connection;
}

@Override
public String toString() {
return this.getClass().getSimpleName() + '{' +
"connection=" + connection +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ public class BungeeLoginSession extends LoginSession {
private boolean alreadySaved;
private boolean alreadyLogged;

public BungeeLoginSession(String username, boolean registered, StoredProfile profile) {
//this will be true, if the Floodgate name conflict checks were skipped in PreLoginEvent
private boolean floodgateCheckSkipped;

public BungeeLoginSession(String username, boolean registered, StoredProfile profile, boolean floodgateCheckSkipped) {
super(username, registered, profile);
this.floodgateCheckSkipped = floodgateCheckSkipped;
}

public BungeeLoginSession(String username, boolean registered, StoredProfile profile) {
this(username, registered, profile, false);
}

public synchronized void setRegistered(boolean registered) {
Expand Down Expand Up @@ -65,4 +73,12 @@ public synchronized String toString() {
", registered=" + registered +
"} " + super.toString();
}

public boolean isFloodgateCheckSkipped() {
return this.floodgateCheckSkipped;
}

public void setFloodgateCheckSkipped(boolean floodgateCheckSkipped) {
this.floodgateCheckSkipped = floodgateCheckSkipped;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@
package com.github.games647.fastlogin.bungee.listener;

import com.github.games647.craftapi.UUIDAdapter;
import com.github.games647.fastlogin.bungee.BungeeFloodgateLoginSource;
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
import com.github.games647.fastlogin.bungee.BungeeLoginSource;
import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.task.AsyncPremiumCheck;
import com.github.games647.fastlogin.bungee.task.FloodgateAuthTask;
import com.github.games647.fastlogin.bungee.task.ForceLoginTask;
import com.github.games647.fastlogin.core.RateLimiter;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.hooks.FloodgateHook;
import com.github.games647.fastlogin.core.shared.LoginSession;
import com.github.games647.fastlogin.core.shared.LoginSource;
import com.google.common.base.Throwables;

import java.lang.invoke.MethodHandle;
Expand All @@ -42,6 +46,7 @@
import java.lang.reflect.Field;
import java.util.UUID;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
Expand All @@ -56,6 +61,8 @@
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;

import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.floodgate.api.FloodgateApi;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.slf4j.Logger;
Expand All @@ -69,6 +76,7 @@ public class ConnectListener implements Listener {

private static final String UUID_FIELD_NAME = "uniqueId";
private static final MethodHandle uniqueIdSetter;
private final FloodgateHook<ProxiedPlayer, CommandSender, BungeeLoginSource> floodgateHook;

static {
MethodHandle setHandle = null;
Expand Down Expand Up @@ -100,6 +108,7 @@ public class ConnectListener implements Listener {
public ConnectListener(FastLoginBungee plugin, RateLimiter rateLimiter) {
this.plugin = plugin;
this.rateLimiter = rateLimiter;
this.floodgateHook = new FloodgateHook<ProxiedPlayer, CommandSender, BungeeLoginSource>(plugin.getCore());
}

@EventHandler
Expand All @@ -117,6 +126,18 @@ public void onPreLogin(PreLoginEvent preLoginEvent) {
String username = connection.getName();
plugin.getLog().info("Incoming login request for {} from {}", username, connection.getSocketAddress());

if (plugin.isPluginInstalled("Geyser-BungeeCord") && plugin.isPluginInstalled("floodgate")) {
for (GeyserSession gSess : GeyserConnector.getInstance().getPlayers()) {
if (username.equals(FloodgateApi.getInstance().getPlayerPrefix() + gSess.getName())){
//todo: if no Floodgate prefix is set, and there are name conflicts, how will this behave?
plugin.getLog().info("Player {} is using Geyser. Name conflict checks will be done later.", username);
StoredProfile profile = plugin.getCore().getStorage().loadProfile(username);
plugin.getSession().put(connection, new BungeeLoginSession(username, true, profile, true));
return;
}
}
}

preLoginEvent.registerIntent(plugin);
Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, preLoginEvent, connection, username);
plugin.getScheduler().runAsync(asyncPremiumCheck);
Expand All @@ -131,9 +152,15 @@ public void onLogin(LoginEvent loginEvent) {
//use the login event instead of the post login event in order to send the login success packet to the client
//with the offline uuid this makes it possible to set the skin then
PendingConnection connection = loginEvent.getConnection();
if (connection.isOnlineMode()) {
LoginSession session = plugin.getSession().get(connection);
BungeeLoginSession session = plugin.getSession().get(connection);

if (session.isFloodgateCheckSkipped()) {
FloodgatePlayer floodgatePlayer = FloodgateApi.getInstance().getPlayer(connection.getUniqueId());
LoginSource source = new BungeeFloodgateLoginSource(connection, loginEvent);
floodgateHook.checkFloodgateNameConflict(connection.getName(), source, floodgatePlayer);
}

if (connection.isOnlineMode()) {
UUID verifiedUUID = connection.getUniqueId();
String verifiedUsername = connection.getName();
session.setUuid(verifiedUUID);
Expand Down