Skip to content

Commit 6d3932f

Browse files
committed
Added support for Floodgate plugin in Velocity proxy
1 parent 8c1d30c commit 6d3932f

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

velocity/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,14 @@
129129
<artifactId>mariadb-java-client</artifactId>
130130
<version>2.7.4</version>
131131
</dependency>
132+
133+
<!-- Bedrock player bridge -->
134+
<!-- Version 2.0 -->
135+
<dependency>
136+
<groupId>org.geysermc.floodgate</groupId>
137+
<artifactId>api</artifactId>
138+
<version>2.0-SNAPSHOT</version>
139+
<scope>provided</scope>
140+
</dependency>
132141
</dependencies>
133142
</project>

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
6464

65+
import org.geysermc.floodgate.api.FloodgateApi;
6566
import org.slf4j.Logger;
6667

6768
//TODO: Support for floodgate
@@ -78,6 +79,7 @@ public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
7879
private FastLoginCore<Player, CommandSource, FastLoginVelocity> core;
7980
private AsyncScheduler scheduler;
8081
private UUID proxyId;
82+
private FloodgateService floodgateService;
8183

8284
@Inject
8385
public FastLoginVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
@@ -96,6 +98,10 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
9698
return;
9799
}
98100

101+
if (isPluginInstalled("floodgate")) {
102+
floodgateService = new FloodgateService(FloodgateApi.getInstance(), core);
103+
}
104+
99105
server.getEventManager().register(this, new ConnectListener(this, core.getRateLimiter()));
100106
server.getEventManager().register(this, new PluginMessageListener(this));
101107
server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL));
@@ -141,7 +147,7 @@ public boolean isPluginInstalled(String name) {
141147

142148
@Override
143149
public FloodgateService getFloodgateService() {
144-
return null;
150+
return floodgateService;
145151
}
146152

147153
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
@@ -28,10 +28,12 @@
2828
import com.github.games647.craftapi.UUIDAdapter;
2929
import com.github.games647.fastlogin.core.RateLimiter;
3030
import com.github.games647.fastlogin.core.StoredProfile;
31+
import com.github.games647.fastlogin.core.hooks.FloodgateService;
3132
import com.github.games647.fastlogin.core.shared.LoginSession;
3233
import com.github.games647.fastlogin.velocity.FastLoginVelocity;
3334
import com.github.games647.fastlogin.velocity.VelocityLoginSession;
3435
import com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck;
36+
import com.github.games647.fastlogin.velocity.task.FloodgateAuthTask;
3537
import com.github.games647.fastlogin.velocity.task.ForceLoginTask;
3638
import com.velocitypowered.api.event.Continuation;
3739
import com.velocitypowered.api.event.Subscribe;
@@ -43,6 +45,7 @@
4345
import com.velocitypowered.api.proxy.Player;
4446
import com.velocitypowered.api.proxy.server.RegisteredServer;
4547
import com.velocitypowered.api.util.GameProfile;
48+
import org.geysermc.floodgate.api.player.FloodgatePlayer;
4649

4750
import java.util.ArrayList;
4851
import java.util.List;
@@ -118,6 +121,16 @@ public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
118121
Player player = serverConnectedEvent.getPlayer();
119122
RegisteredServer server = serverConnectedEvent.getServer();
120123

124+
FloodgateService floodgateService = plugin.getFloodgateService();
125+
if (floodgateService != null) {
126+
FloodgatePlayer floodgatePlayer = floodgateService.getFloodgatePlayer(player.getUniqueId());
127+
if (floodgatePlayer != null) {
128+
Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer, server);
129+
plugin.getScheduler().runAsync(floodgateAuthTask);
130+
return;
131+
}
132+
}
133+
121134
VelocityLoginSession session = plugin.getSession().get(player.getRemoteAddress());
122135
if (session == null) {
123136
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
@@ -26,6 +26,7 @@
2626
package com.github.games647.fastlogin.velocity.listener;
2727

2828
import com.github.games647.fastlogin.core.StoredProfile;
29+
import com.github.games647.fastlogin.core.hooks.FloodgateService;
2930
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
3031
import com.github.games647.fastlogin.core.message.SuccessMessage;
3132
import com.github.games647.fastlogin.core.shared.FastLoginCore;
@@ -113,7 +114,15 @@ private void readMessage(Player forPlayer, String channel, byte[] data) {
113114
}
114115

115116
private void onSuccessMessage(Player forPlayer) {
116-
if (forPlayer.isOnlineMode()){
117+
boolean shouldPersist = forPlayer.isOnlineMode();
118+
119+
FloodgateService floodgateService = plugin.getFloodgateService();
120+
if (!shouldPersist && floodgateService != null) {
121+
// always save floodgate players to lock this username
122+
shouldPersist = floodgateService.isFloodgatePlayer(forPlayer.getUniqueId());
123+
}
124+
125+
if (shouldPersist){
117126
//bukkit module successfully received and force logged in the user
118127
//update only on success to prevent corrupt data
119128
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)