Skip to content

Commit 43c1171

Browse files
committed
Add floodgate support
Based on: TuxCoding#649
1 parent 1715c08 commit 43c1171

File tree

5 files changed

+126
-4
lines changed

5 files changed

+126
-4
lines changed

velocity/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,14 @@
153153
<artifactId>mariadb-java-client</artifactId>
154154
<version>3.1.4</version>
155155
</dependency>
156+
157+
<!-- Bedrock player bridge -->
158+
<!-- Version 2.1.2 -->
159+
<dependency>
160+
<groupId>org.geysermc.floodgate</groupId>
161+
<artifactId>api</artifactId>
162+
<version>2.1.2-SNAPSHOT</version>
163+
<scope>provided</scope>
164+
</dependency>
156165
</dependencies>
157166
</project>

velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
5151
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
5252
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
53+
import org.geysermc.floodgate.api.FloodgateApi;
5354
import org.slf4j.Logger;
5455

5556
import java.io.IOException;
@@ -63,7 +64,7 @@
6364
import java.util.UUID;
6465
import java.util.concurrent.ConcurrentMap;
6566

66-
//TODO: Support for floodgate
67+
//FixMe: Support for floodgate
6768
@Plugin(id = PomData.NAME, name = PomData.DISPLAY_NAME, description = PomData.DESCRIPTION, url = PomData.URL,
6869
version = PomData.VERSION, authors = {"games647", "https://github.com/games647/FastLogin/graphs/contributors"})
6970
public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
@@ -95,6 +96,10 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
9596
return;
9697
}
9798

99+
if (isPluginInstalled("floodgate")) {
100+
floodgateService = new FloodgateService(FloodgateApi.getInstance(), core);
101+
}
102+
98103
server.getEventManager().register(this, new ConnectListener(this, core.getAntiBot()));
99104
server.getEventManager().register(this, new PluginMessageListener(this));
100105

@@ -141,8 +146,8 @@ public boolean isPluginInstalled(String name) {
141146
}
142147

143148
@Override
144-
public BedrockService<?> getBedrockService() {
145-
return null;
149+
public BedrockService<?> getFloodgateService() {
150+
return floodgateService;
146151
}
147152

148153
public FastLoginCore<Player, CommandSource, FastLoginVelocity> getCore() {

velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
import com.github.games647.fastlogin.core.antibot.AntiBotService.Action;
3131
import com.github.games647.fastlogin.core.shared.LoginSession;
3232
import com.github.games647.fastlogin.core.storage.StoredProfile;
33+
import com.github.games647.fastlogin.core.hooks.FloodgateService;
3334
import com.github.games647.fastlogin.velocity.FastLoginVelocity;
3435
import com.github.games647.fastlogin.velocity.VelocityLoginSession;
3536
import com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck;
3637
import com.github.games647.fastlogin.velocity.task.ForceLoginTask;
38+
import com.github.games647.fastlogin.velocity.task.FloodgateAuthTask;
3739
import com.velocitypowered.api.event.Continuation;
3840
import com.velocitypowered.api.event.Subscribe;
3941
import com.velocitypowered.api.event.connection.DisconnectEvent;
@@ -48,6 +50,7 @@
4850
import com.velocitypowered.api.util.GameProfile.Property;
4951
import net.kyori.adventure.text.TextComponent;
5052
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
53+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
5154

5255
import java.net.InetSocketAddress;
5356
import java.util.ArrayList;
@@ -141,6 +144,16 @@ public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
141144
Player player = serverConnectedEvent.getPlayer();
142145
RegisteredServer server = serverConnectedEvent.getServer();
143146

147+
FloodgateService floodgateService = plugin.getFloodgateService();
148+
if (floodgateService != null) {
149+
FloodgatePlayer floodgatePlayer = floodgateService.getFloodgatePlayer(player.getUniqueId());
150+
if (floodgatePlayer != null) {
151+
Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer, server);
152+
plugin.getScheduler().runAsync(floodgateAuthTask);
153+
return;
154+
}
155+
}
156+
144157
VelocityLoginSession session = plugin.getSession().get(player.getRemoteAddress());
145158
if (session == null) {
146159
return;

velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.github.games647.fastlogin.core.message.SuccessMessage;
3030
import com.github.games647.fastlogin.core.shared.FastLoginCore;
3131
import com.github.games647.fastlogin.core.storage.StoredProfile;
32+
import com.github.games647.fastlogin.core.hooks.FloodgateService;
3233
import com.github.games647.fastlogin.velocity.FastLoginVelocity;
3334
import com.github.games647.fastlogin.velocity.VelocityLoginSession;
3435
import com.github.games647.fastlogin.velocity.task.AsyncToggleMessage;
@@ -115,7 +116,15 @@ private void readMessage(Player forPlayer, String channel, byte[] data) {
115116
}
116117

117118
private void onSuccessMessage(Player forPlayer) {
118-
if (forPlayer.isOnlineMode()) {
119+
boolean shouldPersist = forPlayer.isOnlineMode();
120+
121+
FloodgateService floodgateService = plugin.getFloodgateService();
122+
if (!shouldPersist && floodgateService != null) {
123+
// always save floodgate players to lock this username
124+
shouldPersist = floodgateService.isFloodgatePlayer(forPlayer.getUniqueId());
125+
}
126+
127+
if (shouldPersist){
119128
//bukkit module successfully received and force logged in the user
120129
//update only on success to prevent corrupt data
121130
VelocityLoginSession loginSession = plugin.getSession().get(forPlayer.getRemoteAddress());
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2015-2021 <Your name and contributors>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
package com.github.games647.fastlogin.velocity.task;
27+
28+
import com.github.games647.fastlogin.core.shared.FastLoginCore;
29+
import com.github.games647.fastlogin.core.shared.FloodgateManagement;
30+
import com.github.games647.fastlogin.velocity.FastLoginVelocity;
31+
import com.github.games647.fastlogin.velocity.VelocityLoginSession;
32+
import com.velocitypowered.api.command.CommandSource;
33+
import com.velocitypowered.api.proxy.Player;
34+
import com.velocitypowered.api.proxy.server.RegisteredServer;
35+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
36+
37+
import java.net.InetSocketAddress;
38+
import java.util.UUID;
39+
import java.util.concurrent.TimeUnit;
40+
41+
public class FloodgateAuthTask
42+
extends FloodgateManagement<Player, CommandSource, VelocityLoginSession, FastLoginVelocity> {
43+
44+
private final RegisteredServer server;
45+
46+
public FloodgateAuthTask(FastLoginCore<Player, CommandSource, FastLoginVelocity> core, Player player,
47+
FloodgatePlayer floodgatePlayer, RegisteredServer server) {
48+
super(core, player, floodgatePlayer);
49+
this.server = server;
50+
}
51+
52+
@Override
53+
protected void startLogin() {
54+
VelocityLoginSession session = new VelocityLoginSession(player.getUsername(), isRegistered, profile);
55+
core.getPlugin().getSession().put(player.getRemoteAddress(), session);
56+
57+
// enable auto login based on the value of 'autoLoginFloodgate' in config.yml
58+
boolean forcedOnlineMode = autoLoginFloodgate.equals("true")
59+
|| (autoLoginFloodgate.equals("linked") && isLinked);
60+
61+
// delay sending force command, because Paper will process the login event asynchronously
62+
// In this case it means that the force command (plugin message) is already received and processed while
63+
// player is still in the login phase and reported to be offline.
64+
Runnable loginTask = new ForceLoginTask(core.getPlugin().getCore(), player, server, session, forcedOnlineMode);
65+
core.getPlugin().getProxy().getScheduler()
66+
.buildTask(core.getPlugin(), () -> core.getPlugin().getScheduler().runAsync(loginTask))
67+
.delay(1L, TimeUnit.SECONDS) // Delay at least one second, otherwise the login command can be missed
68+
.schedule();
69+
}
70+
71+
@Override
72+
protected String getName(Player player) {
73+
return player.getUsername();
74+
}
75+
76+
@Override
77+
protected UUID getUUID(Player player) {
78+
return player.getUniqueId();
79+
}
80+
81+
@Override
82+
protected InetSocketAddress getAddress(Player player) {
83+
return player.getRemoteAddress();
84+
}
85+
86+
}

0 commit comments

Comments
 (0)