Skip to content

Commit ee2b3a3

Browse files
committed
Move Floodgate name conflict check to Core
1 parent 0e8ad6e commit ee2b3a3

File tree

7 files changed

+106
-83
lines changed

7 files changed

+106
-83
lines changed

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/floodgate/FloodgateHook.java

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -25,72 +25,13 @@
2525
*/
2626
package com.github.games647.fastlogin.bukkit.hook.floodgate;
2727

28-
import java.io.IOException;
29-
import java.util.Optional;
30-
3128
import org.bukkit.Bukkit;
3229
import org.geysermc.floodgate.api.FloodgateApi;
3330
import org.geysermc.floodgate.api.player.FloodgatePlayer;
3431

35-
import com.github.games647.craftapi.model.Profile;
36-
import com.github.games647.craftapi.resolver.RateLimitException;
37-
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
38-
import com.github.games647.fastlogin.core.shared.LoginSource;
39-
4032
public class FloodgateHook {
4133

42-
private final FastLoginBukkit plugin;
43-
44-
public FloodgateHook(FastLoginBukkit plugin) {
45-
this.plugin = plugin;
46-
}
47-
48-
/**
49-
* Check if the player's name conflicts an existing Java player's name, and
50-
* kick them if it does
51-
*
52-
* @param core the FastLoginCore
53-
* @param username the name of the player
54-
* @param source an instance of LoginSource
55-
* @param plugin the FastLoginBukkit plugin
56-
*/
57-
public void checkNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) {
58-
String allowConflict = plugin.getCore().getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
59-
60-
// check if the Bedrock player is linked to a Java account
61-
boolean isLinked = floodgatePlayer.getLinkedPlayer() != null;
62-
63-
if (allowConflict.equals("false")
64-
|| allowConflict.equals("linked") && !isLinked) {
65-
66-
// check for conflicting Premium Java name
67-
Optional<Profile> premiumUUID = Optional.empty();
68-
try {
69-
premiumUUID = plugin.getCore().getResolver().findProfile(username);
70-
} catch (IOException | RateLimitException e) {
71-
plugin.getLog().error(
72-
"Could not check wether Floodgate Player {}'s name conflicts a premium Java player's name.",
73-
username);
74-
try {
75-
source.kick("Could not check if your name conflicts an existing Java Premium Player's name");
76-
} catch (Exception e1) {
77-
plugin.getLog().error("Could not kick Player {}", username);
78-
}
79-
}
80-
81-
if (premiumUUID.isPresent()) {
82-
plugin.getLog().info("Bedrock Player {}'s name conflicts an existing Java Premium Player's name",
83-
username);
84-
try {
85-
source.kick("Your name conflicts an existing Java Premium Player's name");
86-
} catch (Exception e) {
87-
plugin.getLog().error("Could not kick Player {}", username);
88-
}
89-
}
90-
} else {
91-
plugin.getLog().info("Skipping name conflict checking for player {}", username);
92-
}
93-
}
34+
public FloodgateHook() { }
9435

9536
/**
9637
* The FloodgateApi does not support querying players by name, so this function

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/NameCheckTask.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,7 @@ public NameCheckTask(FastLoginBukkit plugin, PacketEvent packetEvent, Random ran
7272
@Override
7373
public void run() {
7474
try {
75-
ProtocolLibLoginSource source = new ProtocolLibLoginSource(packetEvent, player, random, publicKey);
76-
77-
//check if the player is connecting through Floodgate
78-
FloodgatePlayer floodgatePlayer = floodgateHook.getFloodgatePlayer(username);
79-
80-
if (floodgatePlayer != null) {
81-
floodgateHook.checkNameConflict(username, source, floodgatePlayer);
82-
} else {
83-
//do Java login tasks
84-
super.onLogin(username, source);
85-
}
75+
super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey));
8676
} finally {
8777
ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
8878
}
@@ -127,4 +117,12 @@ public void startCrackedSession(ProtocolLibLoginSource source, StoredProfile pro
127117
plugin.putSession(player.getAddress(), loginSession);
128118
}
129119

120+
@Override
121+
protected FloodgatePlayer getFloodgatePlayer(Object id) {
122+
if ((id instanceof String)) {
123+
return floodgateHook.getFloodgatePlayer((String) id);
124+
}
125+
return null;
126+
}
127+
130128
}

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocollib/ProtocolLibListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public ProtocolLibListener(FastLoginBukkit plugin, RateLimiter rateLimiter) {
6161

6262
this.plugin = plugin;
6363
this.rateLimiter = rateLimiter;
64-
this.floodgateHook = new FloodgateHook(plugin);
64+
this.floodgateHook = new FloodgateHook();
6565
}
6666

6767
public static void register(FastLoginBukkit plugin, RateLimiter rateLimiter) {

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public ProtocolSupportListener(FastLoginBukkit plugin, RateLimiter rateLimiter)
6060

6161
this.plugin = plugin;
6262
this.rateLimiter = rateLimiter;
63-
this.floodgateHook = new FloodgateHook(plugin);
63+
this.floodgateHook = new FloodgateHook();
6464
}
6565

6666
@EventHandler
@@ -81,16 +81,7 @@ public void onLoginStart(PlayerLoginStartEvent loginStartEvent) {
8181
plugin.removeSession(address);
8282

8383
ProtocolLoginSource source = new ProtocolLoginSource(loginStartEvent);
84-
85-
//check if the player is connecting through Floodgate
86-
FloodgatePlayer floodgatePlayer = floodgateHook.getFloodgatePlayer(username);
87-
88-
if (floodgatePlayer != null) {
89-
floodgateHook.checkNameConflict(username, source, floodgatePlayer);
90-
} else {
91-
//do Java login tasks
92-
super.onLogin(username, source);
93-
}
84+
super.onLogin(username, source);
9485
}
9586

9687
@EventHandler
@@ -139,4 +130,12 @@ public void startCrackedSession(ProtocolLoginSource source, StoredProfile profil
139130
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
140131
plugin.putSession(source.getAddress(), loginSession);
141132
}
133+
134+
@Override
135+
protected FloodgatePlayer getFloodgatePlayer(Object id) {
136+
if ((id instanceof String)) {
137+
return floodgateHook.getFloodgatePlayer((String) id);
138+
}
139+
return null;
140+
}
142141
}

bungee/src/main/java/com/github/games647/fastlogin/bungee/task/AsyncPremiumCheck.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
package com.github.games647.fastlogin.bungee.task;
2727

28+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
29+
2830
import com.github.games647.fastlogin.bungee.BungeeLoginSession;
2931
import com.github.games647.fastlogin.bungee.BungeeLoginSource;
3032
import com.github.games647.fastlogin.bungee.FastLoginBungee;
@@ -89,4 +91,10 @@ public void requestPremiumLogin(BungeeLoginSource source, StoredProfile profile,
8991
public void startCrackedSession(BungeeLoginSource source, StoredProfile profile, String username) {
9092
plugin.getSession().put(source.getConnection(), new BungeeLoginSession(username, false, profile));
9193
}
94+
95+
@Override
96+
protected FloodgatePlayer getFloodgatePlayer(Object id) {
97+
// force disabled for BungeeCord for now
98+
return null;
99+
}
92100
}

core/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
<id>codemc-repo</id>
5454
<url>https://repo.codemc.io/repository/maven-public/</url>
5555
</repository>
56+
<!-- Floodgate -->
57+
<repository>
58+
<id>nukkitx-snapshot</id>
59+
<url>https://repo.nukkitx.com/maven-snapshots/</url>
60+
</repository>
5661
</repositories>
5762

5863
<dependencies>
@@ -85,6 +90,14 @@
8590
</exclusions>
8691
</dependency>
8792

93+
<!--Floodgate for Xbox Live Authentication-->
94+
<dependency>
95+
<groupId>org.geysermc.floodgate</groupId>
96+
<artifactId>api</artifactId>
97+
<version>2.0-SNAPSHOT</version>
98+
<scope>provided</scope>
99+
</dependency>
100+
88101
<!--Common component for contacting the Mojang API-->
89102
<dependency>
90103
<groupId>com.github.games647</groupId>

core/src/main/java/com/github/games647/fastlogin/core/shared/JoinManagement.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
3232
import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent;
3333

34+
import java.io.IOException;
3435
import java.util.Optional;
3536

37+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
38+
3639
import net.md_5.bungee.config.Configuration;
3740

3841
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
@@ -52,6 +55,13 @@ public void onLogin(String username, S source) {
5255
return;
5356
}
5457

58+
//check if the player is connecting through Floodgate
59+
FloodgatePlayer floodgatePlayer = getFloodgatePlayer(username);
60+
61+
if (floodgatePlayer != null) {
62+
checkFloodgateNameConflict(username, source, floodgatePlayer);
63+
return;
64+
}
5565
callFastLoginPreLoginEvent(username, source, profile);
5666

5767
Configuration config = core.getConfig();
@@ -131,6 +141,60 @@ private boolean checkNameChange(S source, String username, Profile profile) {
131141
return false;
132142
}
133143

144+
/**
145+
* Check if the player's name conflicts an existing Java player's name, and
146+
* kick them if it does
147+
*
148+
* @param core the FastLoginCore
149+
* @param username the name of the player
150+
* @param source an instance of LoginSource
151+
*/
152+
public void checkFloodgateNameConflict(String username, LoginSource source, FloodgatePlayer floodgatePlayer) {
153+
String allowConflict = core.getConfig().get("allowFloodgateNameConflict").toString().toLowerCase();
154+
155+
// check if the Bedrock player is linked to a Java account
156+
boolean isLinked = floodgatePlayer.getLinkedPlayer() != null;
157+
158+
if (allowConflict.equals("false")
159+
|| allowConflict.equals("linked") && !isLinked) {
160+
161+
// check for conflicting Premium Java name
162+
Optional<Profile> premiumUUID = Optional.empty();
163+
try {
164+
premiumUUID = core.getResolver().findProfile(username);
165+
} catch (IOException | RateLimitException e) {
166+
core.getPlugin().getLog().error(
167+
"Could not check wether Floodgate Player {}'s name conflicts a premium Java player's name.",
168+
username);
169+
try {
170+
source.kick("Could not check if your name conflicts an existing Java Premium Player's name");
171+
} catch (Exception e1) {
172+
core.getPlugin().getLog().error("Could not kick Player {}", username);
173+
}
174+
}
175+
176+
if (premiumUUID.isPresent()) {
177+
core.getPlugin().getLog().info("Bedrock Player {}'s name conflicts an existing Java Premium Player's name",
178+
username);
179+
try {
180+
source.kick("Your name conflicts an existing Java Premium Player's name");
181+
} catch (Exception e) {
182+
core.getPlugin().getLog().error("Could not kick Player {}", username);
183+
}
184+
}
185+
} else {
186+
core.getPlugin().getLog().info("Skipping name conflict checking for player {}", username);
187+
}
188+
}
189+
190+
/**
191+
* Check if a player is connecting through Floodgate
192+
* @param id UUID for BungeeCord, username for Bukkit
193+
* @return true if the player is connecting through Floodgate
194+
* <br> null if Floodgate is unavailable
195+
*/
196+
protected abstract FloodgatePlayer getFloodgatePlayer(Object id);
197+
134198
public abstract FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, S source, StoredProfile profile);
135199

136200
public abstract void requestPremiumLogin(S source, StoredProfile profile, String username, boolean registered);

0 commit comments

Comments
 (0)