Skip to content

Commit 97c7c57

Browse files
xrh0905Smart123s
authored andcommitted
Add floodgate support
Based on: TuxCoding#649 Solve hooks not found Add defination of floodgateservice Geyser API
1 parent d65cf4b commit 97c7c57

File tree

5 files changed

+161
-2
lines changed

5 files changed

+161
-2
lines changed

velocity/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
<id>velocity</id>
130130
<url>https://repo.papermc.io/repository/maven-public/</url>
131131
</repository>
132+
<repository>
133+
<id>opencollab-snapshot</id>
134+
<url>https://repo.opencollab.dev/main/</url>
135+
</repository>
132136
</repositories>
133137

134138
<dependencies>
@@ -153,5 +157,27 @@
153157
<artifactId>mariadb-java-client</artifactId>
154158
<version>3.1.4</version>
155159
</dependency>
160+
161+
<!-- Bedrock player bridge -->
162+
<dependency>
163+
<groupId>org.geysermc.geyser</groupId>
164+
<artifactId>core</artifactId>
165+
<version>${geyser.version}</version>
166+
<scope>provided</scope>
167+
<exclusions>
168+
<exclusion>
169+
<groupId>*</groupId>
170+
<artifactId>*</artifactId>
171+
</exclusion>
172+
</exclusions>
173+
</dependency>
174+
175+
<!-- Floodgate -->
176+
<dependency>
177+
<groupId>org.geysermc.floodgate</groupId>
178+
<artifactId>api</artifactId>
179+
<version>${floodgate.version}</version>
180+
<scope>provided</scope>
181+
</dependency>
156182
</dependencies>
157183
</project>

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import com.github.games647.fastlogin.core.AsyncScheduler;
2929
import com.github.games647.fastlogin.core.hooks.bedrock.BedrockService;
30+
import com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService;
31+
import com.github.games647.fastlogin.core.hooks.bedrock.GeyserService;
3032
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
3133
import com.github.games647.fastlogin.core.message.ChannelMessage;
3234
import com.github.games647.fastlogin.core.message.SuccessMessage;
@@ -50,6 +52,8 @@
5052
import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
5153
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
5254
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
55+
import org.geysermc.floodgate.api.FloodgateApi;
56+
import org.geysermc.geyser.GeyserImpl;
5357
import org.slf4j.Logger;
5458

5559
import java.io.IOException;
@@ -76,6 +80,8 @@ public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
7680

7781
private FastLoginCore<Player, CommandSource, FastLoginVelocity> core;
7882
private AsyncScheduler scheduler;
83+
private FloodgateService floodgateService;
84+
private GeyserService geyserService;
7985
private UUID proxyId;
8086

8187
@Inject
@@ -95,6 +101,14 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
95101
return;
96102
}
97103

104+
if (isPluginInstalled("floodgate")) {
105+
floodgateService = new FloodgateService(FloodgateApi.getInstance(), core);
106+
}
107+
108+
if (isPluginInstalled("Geyser-Velocity")) {
109+
geyserService = new GeyserService(GeyserImpl.getInstance(), core);
110+
}
111+
98112
server.getEventManager().register(this, new ConnectListener(this, core.getAntiBot()));
99113
server.getEventManager().register(this, new PluginMessageListener(this));
100114

@@ -140,9 +154,21 @@ public boolean isPluginInstalled(String name) {
140154
return server.getPluginManager().isLoaded(name);
141155
}
142156

157+
public FloodgateService getFloodgateService() {
158+
return floodgateService;
159+
}
160+
161+
public GeyserService getGeyserService() {
162+
return geyserService;
163+
}
164+
143165
@Override
144166
public BedrockService<?> getBedrockService() {
145-
return null;
167+
if (floodgateService != null) {
168+
return floodgateService;
169+
}
170+
171+
return geyserService;
146172
}
147173

148174
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.bedrock.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.getBedrockPlayer(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.bedrock.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.isBedrockPlayer(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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2015-2023 games647 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+
}

0 commit comments

Comments
 (0)