From e639e29dee0b4930ab0a93319a3ea94d678cb571 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Mon, 13 Sep 2021 21:24:46 -0300 Subject: [PATCH 01/27] Partial velocity support. --- pom.xml | 1 + velocity/pom.xml | 136 +++++++++++++++ .../fastlogin/velocity/FastLoginVelocity.java | 125 ++++++++++++++ .../velocity/VelocityLoginSession.java | 40 +++++ .../velocity/VelocityLoginSource.java | 50 ++++++ .../VelocityFastLoginAutoLoginEvent.java | 76 +++++++++ .../event/VelocityFastLoginPreLoginEvent.java | 58 +++++++ .../VelocityFastLoginPremiumToggleEvent.java | 50 ++++++ .../velocity/listener/ConnectListener.java | 156 ++++++++++++++++++ .../listener/PluginMessageListener.java | 132 +++++++++++++++ .../velocity/task/AsyncPremiumCheck.java | 100 +++++++++++ .../velocity/task/AsyncToggleMessage.java | 110 ++++++++++++ .../velocity/task/ForceLoginTask.java | 141 ++++++++++++++++ .../src/main/resources/velocity-plugin.json | 9 + 14 files changed, 1184 insertions(+) create mode 100644 velocity/pom.xml create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPreLoginEvent.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPremiumToggleEvent.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncToggleMessage.java create mode 100644 velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java create mode 100644 velocity/src/main/resources/velocity-plugin.json diff --git a/pom.xml b/pom.xml index 6031c250..f3971014 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,7 @@ core bukkit bungee + velocity diff --git a/velocity/pom.xml b/velocity/pom.xml new file mode 100644 index 00000000..2076c23d --- /dev/null +++ b/velocity/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + + com.github.games647 + fastlogin + 1.11-SNAPSHOT + ../pom.xml + + + + fastlogin.velocity + jar + + + FastLoginVelocity + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + false + false + + + com.zaxxer.hikari + fastlogin.hikari + + + org.slf4j + fastlogin.slf4j + + + net.md_5.bungee.config + fastlogin.config + + + + + + package + + shade + + + + + + + + + + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + + + + opencollab-snapshot + https://repo.opencollab.dev/maven-snapshots/ + + + + spigotplugins-repo + https://maven.gamestrike.de/mvn/ + + + + velocity + https://nexus.velocitypowered.com/repository/maven-public/ + + + + jitpack.io + https://jitpack.io + + false + + + + + + + + ${project.groupId} + fastlogin.core + ${project.version} + + + + + com.velocitypowered + velocity-api + 3.0.1 + provided + + + + org.xerial + sqlite-jdbc + 3.32.3 + + + + diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java new file mode 100644 index 00000000..501db459 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -0,0 +1,125 @@ +package com.github.games647.fastlogin.velocity; + +import com.github.games647.fastlogin.core.AsyncScheduler; +import com.github.games647.fastlogin.core.CommonUtil; +import com.github.games647.fastlogin.core.message.ChangePremiumMessage; +import com.github.games647.fastlogin.core.message.ChannelMessage; +import com.github.games647.fastlogin.core.message.NamespaceKey; +import com.github.games647.fastlogin.core.message.SuccessMessage; +import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.core.shared.PlatformPlugin; +import com.github.games647.fastlogin.velocity.listener.ConnectListener; +import com.github.games647.fastlogin.velocity.listener.PluginMessageListener; +import com.google.common.collect.MapMaker; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.google.inject.Inject; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import com.velocitypowered.api.proxy.InboundConnection; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.util.UUID; +import java.util.concurrent.ConcurrentMap; + +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.slf4j.Logger; + +@Plugin(id = "fastlogin") +public class FastLoginVelocity implements PlatformPlugin { + private final ProxyServer server; + private final Path dataDirectory; + private final Logger logger; + private FastLoginCore core; + private final ConcurrentMap session = new MapMaker().weakKeys().makeMap(); + private AsyncScheduler scheduler; + + @Inject + public FastLoginVelocity(ProxyServer server, java.util.logging.Logger logger, @DataDirectory Path dataDirectory) { + this.server = server; + this.logger = CommonUtil.createLoggerFromJDK(logger); + this.dataDirectory = dataDirectory; + logger.info("FastLogin velocity."); + } + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + scheduler = new AsyncScheduler(logger, getThreadFactory()); + + core = new FastLoginCore<>(this); + core.load(); + if (!core.setupDatabase()) { + return; + } + logger.info("Velocity uuid for allowed proxies:" + UUID.nameUUIDFromBytes("velocity".getBytes(StandardCharsets.UTF_8))); + server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL)); + server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL)); + server.getEventManager().register(this, new ConnectListener(this, core.getRateLimiter())); + server.getEventManager().register(this, new PluginMessageListener(this)); + } + + @Override + public String getName() { + //FIXME: some dynamic way to get it? + return "fastlogin"; + } + + @Override + public Path getPluginFolder() { + return dataDirectory; + } + + @Override + public Logger getLog() { + return logger; + } + + @Override + public void sendMessage(CommandSource receiver, String message) { + receiver.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + + } + + @Override + public AsyncScheduler getScheduler() { + return scheduler; + } + + @Override + public boolean isPluginInstalled(String name) { + return server.getPluginManager().isLoaded(name); + } + + public FastLoginCore getCore() { + return core; + } + + public ConcurrentMap getSession() { + return session; + } + + public ProxyServer getProxy() { + return server; + } + + public void sendPluginMessage(RegisteredServer server, ChannelMessage message) { + if (server != null) { + ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); + message.writeTo(dataOutput); + + MinecraftChannelIdentifier channel = MinecraftChannelIdentifier.create(getName(), message.getChannelName()); + server.sendPluginMessage(channel, dataOutput.toByteArray()); + } + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java new file mode 100644 index 00000000..9d865a48 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java @@ -0,0 +1,40 @@ +package com.github.games647.fastlogin.velocity; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.shared.LoginSession; + +public class VelocityLoginSession extends LoginSession { + private boolean alreadySaved; + private boolean alreadyLogged; + public VelocityLoginSession(String requestUsername, boolean registered, StoredProfile profile) { + super(requestUsername, registered, profile); + } + public synchronized void setRegistered(boolean registered) { + this.registered = registered; + } + + public synchronized boolean isAlreadySaved() { + return alreadySaved; + } + + public synchronized void setAlreadySaved(boolean alreadySaved) { + this.alreadySaved = alreadySaved; + } + + public synchronized boolean isAlreadyLogged() { + return alreadyLogged; + } + + public synchronized void setAlreadyLogged(boolean alreadyLogged) { + this.alreadyLogged = alreadyLogged; + } + + @Override + public synchronized String toString() { + return this.getClass().getSimpleName() + '{' + + "alreadySaved=" + alreadySaved + + ", alreadyLogged=" + alreadyLogged + + ", registered=" + registered + + "} " + super.toString(); + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java new file mode 100644 index 00000000..abd3ef78 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java @@ -0,0 +1,50 @@ +package com.github.games647.fastlogin.velocity; + +import com.github.games647.fastlogin.core.shared.LoginSource; +import com.velocitypowered.api.event.Continuation; +import com.velocitypowered.api.event.connection.PreLoginEvent; +import com.velocitypowered.api.proxy.InboundConnection; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentBuilder; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +import java.net.InetSocketAddress; + +public class VelocityLoginSource implements LoginSource { + + private InboundConnection connection; + private PreLoginEvent preLoginEvent; + + public VelocityLoginSource(InboundConnection connection, PreLoginEvent preLoginEvent) { + this.connection = connection; + this.preLoginEvent = preLoginEvent; + } + + @Override + public void enableOnlinemode() { + preLoginEvent.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode()); + } + + @Override + public void kick(String message) { + + + if (message == null) { + preLoginEvent.setResult(PreLoginEvent.PreLoginComponentResult.denied( + Component.text("Kicked").color(NamedTextColor.WHITE))); + } else { + preLoginEvent.setResult(PreLoginEvent.PreLoginComponentResult.denied( + LegacyComponentSerializer.legacyAmpersand().deserialize(message))); + } + } + + @Override + public InetSocketAddress getAddress() { + return connection.getRemoteAddress(); + } + + public InboundConnection getConnection() { + return connection; + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java new file mode 100644 index 00000000..09b72603 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java @@ -0,0 +1,76 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.event; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.shared.LoginSession; +import com.github.games647.fastlogin.core.shared.event.FastLoginAutoLoginEvent; +import com.velocitypowered.api.event.ResultedEvent; + +import java.util.Objects; + +public class VelocityFastLoginAutoLoginEvent implements FastLoginAutoLoginEvent, ResultedEvent { + + private final LoginSession session; + private final StoredProfile profile; + private boolean cancelled; + + public VelocityFastLoginAutoLoginEvent(LoginSession session, StoredProfile profile) { + this.session = session; + this.profile = profile; + } + + @Override + public LoginSession getSession() { + return session; + } + + @Override + public StoredProfile getProfile() { + return profile; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + + @Override + public GenericResult getResult() { + return cancelled ? GenericResult.denied(): GenericResult.allowed(); + } + + @Override + public void setResult(GenericResult result) { + cancelled = Objects.requireNonNull(result) != GenericResult.allowed(); + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPreLoginEvent.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPreLoginEvent.java new file mode 100644 index 00000000..ce58ee52 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPreLoginEvent.java @@ -0,0 +1,58 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.event; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.shared.LoginSource; +import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; + +public class VelocityFastLoginPreLoginEvent implements FastLoginPreLoginEvent { + + private final String username; + private final LoginSource source; + private final StoredProfile profile; + + public VelocityFastLoginPreLoginEvent(String username, LoginSource source, StoredProfile profile) { + this.username = username; + this.source = source; + this.profile = profile; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public LoginSource getSource() { + return source; + } + + @Override + public StoredProfile getProfile() { + return profile; + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPremiumToggleEvent.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPremiumToggleEvent.java new file mode 100644 index 00000000..3dc83b1a --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginPremiumToggleEvent.java @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.event; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent; + +public class VelocityFastLoginPremiumToggleEvent implements FastLoginPremiumToggleEvent { + + private final StoredProfile profile; + private final PremiumToggleReason reason; + + public VelocityFastLoginPremiumToggleEvent(StoredProfile profile, PremiumToggleReason reason) { + this.profile = profile; + this.reason = reason; + } + + @Override + public StoredProfile getProfile() { + return profile; + } + + @Override + public PremiumToggleReason getReason() { + return reason; + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java new file mode 100644 index 00000000..b7e00492 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -0,0 +1,156 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.listener; + +import com.github.games647.craftapi.UUIDAdapter; +import com.github.games647.fastlogin.core.RateLimiter; +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.shared.LoginSession; +import com.github.games647.fastlogin.velocity.FastLoginVelocity; +import com.github.games647.fastlogin.velocity.VelocityLoginSession; +import com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck; +import com.github.games647.fastlogin.velocity.task.ForceLoginTask; +import com.google.common.base.Throwables; +import com.velocitypowered.api.event.Continuation; +import com.velocitypowered.api.event.PostOrder; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; +import com.velocitypowered.api.event.connection.LoginEvent; + +import com.velocitypowered.api.event.connection.PreLoginEvent; +import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.proxy.InboundConnection; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; + +import java.util.UUID; + +public class ConnectListener { + + private final FastLoginVelocity plugin; + private final RateLimiter rateLimiter; + + public ConnectListener(FastLoginVelocity plugin, RateLimiter rateLimiter) { + this.plugin = plugin; + this.rateLimiter = rateLimiter; + } + + @Subscribe() + public void onPreLogin(PreLoginEvent preLoginEvent, Continuation continuation) { + if (!preLoginEvent.getResult().isAllowed()) { + return; + } + InboundConnection connection = preLoginEvent.getConnection(); + if (!rateLimiter.tryAcquire()) { + plugin.getLog().warn("Simple Anti-Bot join limit - Ignoring {}", connection); + return; + } + + String username = preLoginEvent.getUsername(); + plugin.getLog().info("Incoming login request for {} from {}", username, connection.getRemoteAddress()); + + + Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, connection, username, continuation, preLoginEvent); + plugin.getScheduler().runAsync(asyncPremiumCheck); + } + + @Subscribe(order = PostOrder.LATE) + 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 + Player connection = loginEvent.getPlayer(); + if (connection.isOnlineMode()) { + LoginSession session = plugin.getSession().get(connection.getRemoteAddress()); + + UUID verifiedUUID = connection.getUniqueId(); + String verifiedUsername = connection.getUsername(); + session.setUuid(verifiedUUID); + session.setVerifiedUsername(verifiedUsername); + + StoredProfile playerProfile = session.getProfile(); + playerProfile.setId(verifiedUUID); + + // bungeecord will do this automatically so override it on disabled option +// if (uniqueIdSetter != null) { +// InitialHandler initialHandler = (InitialHandler) connection; +// +// if (!plugin.getCore().getConfig().get("premiumUuid", true)) { +// setOfflineId(initialHandler, verifiedUsername); +// } +// +// if (!plugin.getCore().getConfig().get("forwardSkin", true)) { +// // this is null on offline mode +// LoginResult loginProfile = initialHandler.getLoginProfile(); +// loginProfile.setProperties(emptyProperties); +// } +// } + } + } + +// private void setOfflineId(InitialHandler connection, String username) { +// try { +// final UUID oldPremiumId = connection.getUniqueId(); +// final UUID offlineUUID = UUIDAdapter.generateOfflineId(username); +// +// // BungeeCord only allows setting the UUID in PreLogin events and before requesting online mode +// // However if online mode is requested, it will override previous values +// // So we have to do it with reflection +// uniqueIdSetter.invokeExact(connection, offlineUUID); +// +// String format = "Overridden UUID from {} to {} (based of {}) on {}"; +// plugin.getLog().info(format, oldPremiumId, offlineUUID, username, connection); +// } catch (Exception ex) { +// plugin.getLog().error("Failed to set offline uuid of {}", username, ex); +// } catch (Throwable throwable) { +// // throw remaining exceptions like outofmemory that we shouldn't handle ourself +// Throwables.throwIfUnchecked(throwable); +// } +// } + + @Subscribe + public void onServerConnected(ServerConnectedEvent serverConnectedEvent) { + Player player = serverConnectedEvent.getPlayer(); + RegisteredServer server = serverConnectedEvent.getServer(); + + VelocityLoginSession session = plugin.getSession().get(player.getRemoteAddress()); + if (session == null) { + return; + } + + // delay sending force command, because Paper will process the login event asynchronously + // In this case it means that the force command (plugin message) is already received and processed while + // player is still in the login phase and reported to be offline. + Runnable loginTask = new ForceLoginTask(plugin.getCore(), player, server, session); + plugin.getScheduler().runAsync(loginTask); + } + + @Subscribe + public void onDisconnect(DisconnectEvent disconnectEvent) { + Player player = disconnectEvent.getPlayer(); + assert plugin.getSession().remove(player.getRemoteAddress()) != null; + plugin.getCore().getPendingConfirms().remove(player.getUniqueId()); + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java new file mode 100644 index 00000000..43f09e5d --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java @@ -0,0 +1,132 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.listener; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.message.ChangePremiumMessage; +import com.github.games647.fastlogin.core.message.NamespaceKey; +import com.github.games647.fastlogin.core.message.SuccessMessage; +import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.velocity.FastLoginVelocity; +import com.github.games647.fastlogin.velocity.VelocityLoginSession; +import com.github.games647.fastlogin.velocity.task.AsyncToggleMessage; +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +import java.util.Arrays; + +public class PluginMessageListener { + + private final FastLoginVelocity plugin; + + private final String successChannel; + private final String changeChannel; + + public PluginMessageListener(FastLoginVelocity plugin) { + this.plugin = plugin; + + this.successChannel = MinecraftChannelIdentifier.create(plugin.getName(), SuccessMessage.SUCCESS_CHANNEL).getId(); + this.changeChannel = MinecraftChannelIdentifier.create(plugin.getName(), ChangePremiumMessage.CHANGE_CHANNEL).getId(); + } + + @Subscribe + public void onPluginMessage(PluginMessageEvent pluginMessageEvent) { + String channel = pluginMessageEvent.getIdentifier().getId(); + if (!pluginMessageEvent.getResult().isAllowed() || !channel.startsWith(plugin.getName().toLowerCase())) { + return; + } + + //the client shouldn't be able to read the messages in order to know something about server internal states + //moreover the client shouldn't be able fake a running premium check by sending the result message + pluginMessageEvent.setResult(PluginMessageEvent.ForwardResult.handled()); + + if (!(pluginMessageEvent.getSource() instanceof ServerConnection)) { + //check if the message is sent from the server + return; + } + + //so that we can safely process this in the background + byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length); + Player forPlayer = (Player) pluginMessageEvent.getTarget(); + + plugin.getScheduler().runAsync(() -> readMessage(forPlayer, channel, data)); + } + + private void readMessage(Player forPlayer, String channel, byte[] data) { + FastLoginCore core = plugin.getCore(); + + ByteArrayDataInput dataInput = ByteStreams.newDataInput(data); + if (successChannel.equals(channel)) { + onSuccessMessage(forPlayer); + } else if (changeChannel.equals(channel)) { + ChangePremiumMessage changeMessage = new ChangePremiumMessage(); + changeMessage.readFrom(dataInput); + + String playerName = changeMessage.getPlayerName(); + boolean isSourceInvoker = changeMessage.isSourceInvoker(); + if (changeMessage.shouldEnable()) { + if (playerName.equals(forPlayer.getUsername()) && plugin.getCore().getConfig().get("premium-warning", true) + && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) { + String message = core.getMessage("premium-warning"); + forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + core.getPendingConfirms().add(forPlayer.getUniqueId()); + return; + } + + core.getPendingConfirms().remove(forPlayer.getUniqueId()); + Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker); + plugin.getScheduler().runAsync(task); + } else { + Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker); + plugin.getScheduler().runAsync(task); + } + } + } + + private void onSuccessMessage(Player forPlayer) { + + if (forPlayer.isOnlineMode()){ + //bukkit module successfully received and force logged in the user + //update only on success to prevent corrupt data + VelocityLoginSession loginSession = plugin.getSession().get(forPlayer.getRemoteAddress()); + StoredProfile playerProfile = loginSession.getProfile(); + loginSession.setRegistered(true); + if (!loginSession.isAlreadySaved()) { + playerProfile.setPremium(true); + plugin.getCore().getStorage().save(playerProfile); + loginSession.setAlreadySaved(true); + } + } + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java new file mode 100644 index 00000000..30b6dd17 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java @@ -0,0 +1,100 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.task; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.shared.JoinManagement; +import com.github.games647.fastlogin.core.shared.event.FastLoginPreLoginEvent; +import com.github.games647.fastlogin.velocity.FastLoginVelocity; +import com.github.games647.fastlogin.velocity.VelocityLoginSession; +import com.github.games647.fastlogin.velocity.VelocityLoginSource; +import com.github.games647.fastlogin.velocity.event.VelocityFastLoginPreLoginEvent; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.event.Continuation; +import com.velocitypowered.api.event.connection.PreLoginEvent; +import com.velocitypowered.api.proxy.InboundConnection; +import com.velocitypowered.api.proxy.Player; + +import java.util.concurrent.ExecutionException; + +public class AsyncPremiumCheck extends JoinManagement + implements Runnable { + + private final FastLoginVelocity plugin; + private final String username; + private Continuation continuation; + private PreLoginEvent preLoginEvent; + private final InboundConnection connection; + + public AsyncPremiumCheck(FastLoginVelocity plugin, InboundConnection connection, String username, Continuation continuation, PreLoginEvent preLoginEvent) { + super(plugin.getCore(), plugin.getCore().getAuthPluginHook()); + this.plugin = plugin; + this.connection = connection; + this.username = username; + this.continuation = continuation; + this.preLoginEvent = preLoginEvent; + } + + @Override + public void run() { + plugin.getSession().remove(connection.getRemoteAddress()); + try { + super.onLogin(username, new VelocityLoginSource(connection, preLoginEvent)); + } finally { + continuation.resume(); + } + } + + @Override + public FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, VelocityLoginSource source, StoredProfile profile) { + //FIXME: Am I doing it right? + VelocityFastLoginPreLoginEvent event = new VelocityFastLoginPreLoginEvent(username, source, profile); + try { + return plugin.getProxy().getEventManager().fire(event).get(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // Restore the interrupt flag + return event; + } catch (ExecutionException e) { + e.printStackTrace(); + return event; + } + } + + @Override + public void requestPremiumLogin(VelocityLoginSource source, StoredProfile profile, + String username, boolean registered) { + source.enableOnlinemode(); + plugin.getSession().put(source.getConnection().getRemoteAddress(), new VelocityLoginSession(username, registered, profile)); + + String ip = source.getAddress().getAddress().getHostAddress(); + plugin.getCore().getPendingLogin().put(ip + username, new Object()); + } + + @Override + public void startCrackedSession(VelocityLoginSource source, StoredProfile profile, String username) { + plugin.getSession().put(source.getConnection().getRemoteAddress(), new VelocityLoginSession(username, false, profile)); + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncToggleMessage.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncToggleMessage.java new file mode 100644 index 00000000..d1b24cf5 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncToggleMessage.java @@ -0,0 +1,110 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.task; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason; +import com.github.games647.fastlogin.velocity.FastLoginVelocity; +import com.github.games647.fastlogin.velocity.event.VelocityFastLoginPremiumToggleEvent; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public class AsyncToggleMessage implements Runnable { + + private final FastLoginCore core; + private final CommandSource sender; + private final String senderName; + private final String targetPlayer; + private final boolean toPremium; + private final boolean isPlayerSender; + + public AsyncToggleMessage(FastLoginCore core, + CommandSource sender, String playerName, boolean toPremium, boolean playerSender) { + this.core = core; + this.sender = sender; + this.targetPlayer = playerName; + this.toPremium = toPremium; + this.isPlayerSender = playerSender; + if (sender instanceof Player) + senderName = ((Player) sender).getUsername(); + else + senderName = ""; + } + + @Override + public void run() { + if (toPremium) { + activatePremium(); + } else { + turnOffPremium(); + } + } + + private void turnOffPremium() { + StoredProfile playerProfile = core.getStorage().loadProfile(targetPlayer); + //existing player is already cracked + if (playerProfile.isSaved() && !playerProfile.isPremium()) { + sendMessage("not-premium"); + return; + } + + playerProfile.setPremium(false); + playerProfile.setId(null); + core.getStorage().save(playerProfile); + PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) ? + PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; + core.getPlugin().getProxy().getEventManager().fire( + new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); + sendMessage("remove-premium"); + } + + private void activatePremium() { + StoredProfile playerProfile = core.getStorage().loadProfile(targetPlayer); + if (playerProfile.isPremium()) { + sendMessage("already-exists"); + return; + } + + playerProfile.setPremium(true); + core.getStorage().save(playerProfile); + PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) ? + PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF; + core.getPlugin().getProxy().getEventManager().fire( + new VelocityFastLoginPremiumToggleEvent(playerProfile, reason)); + sendMessage("add-premium"); + } + + private void sendMessage(String localeId) { + String message = core.getMessage(localeId); + if (isPlayerSender) { + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } else { + core.getPlugin().getProxy().getConsoleCommandSource().sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + } +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java new file mode 100644 index 00000000..50ad92e1 --- /dev/null +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java @@ -0,0 +1,141 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity.task; + +import com.github.games647.fastlogin.core.StoredProfile; +import com.github.games647.fastlogin.core.message.ChannelMessage; +import com.github.games647.fastlogin.core.message.LoginActionMessage; +import com.github.games647.fastlogin.core.message.LoginActionMessage.Type; +import com.github.games647.fastlogin.core.shared.FastLoginCore; +import com.github.games647.fastlogin.core.shared.ForceLoginManagement; +import com.github.games647.fastlogin.core.shared.LoginSession; +import com.github.games647.fastlogin.core.shared.event.FastLoginAutoLoginEvent; +import com.github.games647.fastlogin.velocity.FastLoginVelocity; +import com.github.games647.fastlogin.velocity.VelocityLoginSession; +import com.github.games647.fastlogin.velocity.event.VelocityFastLoginAutoLoginEvent; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; + +import java.nio.charset.StandardCharsets; +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +public class ForceLoginTask + extends ForceLoginManagement { + + private final RegisteredServer server; + + //treat player as if they had a premium account, even when they don't + //used for Floodgate auto login/register + private final boolean forcedOnlineMode; + + public ForceLoginTask(FastLoginCore core, + Player player, RegisteredServer server, VelocityLoginSession session, boolean forcedOnlineMode) { + super(core, player, session); + + this.server = server; + this.forcedOnlineMode = forcedOnlineMode; + } + + public ForceLoginTask(FastLoginCore core, Player player, + RegisteredServer server, VelocityLoginSession session) { + this(core, player, server, session, false); + } + + @Override + public void run() { + if (session == null) { + return; + } + + super.run(); + if (!isOnlineMode()) { + session.setAlreadySaved(true); + } + } + + @Override + public boolean forceLogin(Player player) { + if (session.isAlreadyLogged()) { + return true; + } + + session.setAlreadyLogged(true); + return super.forceLogin(player); + } + + @Override + public FastLoginAutoLoginEvent callFastLoginAutoLoginEvent(LoginSession session, StoredProfile profile) { + //FIXME: Am I doing it right? + VelocityFastLoginAutoLoginEvent event = new VelocityFastLoginAutoLoginEvent(session, profile); + try { + return core.getPlugin().getProxy().getEventManager().fire(event).get(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // Set the interrupt flag again + return event; + } catch (ExecutionException e) { + e.printStackTrace(); + return event; + } + } + + @Override + public boolean forceRegister(Player player) { + return session.isAlreadyLogged() || super.forceRegister(player); + } + + @Override + public void onForceActionSuccess(LoginSession session) { + //sub channel name + Type type = Type.LOGIN; + if (session.needsRegistration()) { + type = Type.REGISTER; + } + //FIXME: Velocity does not have an alternative for this! + //UUID proxyId = UUID.fromString(ProxyServer.getInstance().getConfig().getUuid()); + UUID proxyId = UUID.nameUUIDFromBytes("velocity".getBytes(StandardCharsets.UTF_8)); + ChannelMessage loginMessage = new LoginActionMessage(type, player.getUsername(), proxyId); + + core.getPlugin().sendPluginMessage(server, loginMessage); + } + + @Override + public String getName(Player player) { + return player.getUsername(); + } + + @Override + public boolean isOnline(Player player) { + //FIXME: is this right? + return core.getPlugin().getProxy().getPlayer(player.getUsername()).isPresent(); + } + + @Override + public boolean isOnlineMode() { + return forcedOnlineMode || player.isOnlineMode(); + } +} diff --git a/velocity/src/main/resources/velocity-plugin.json b/velocity/src/main/resources/velocity-plugin.json new file mode 100644 index 00000000..fc1dce76 --- /dev/null +++ b/velocity/src/main/resources/velocity-plugin.json @@ -0,0 +1,9 @@ +{ + "id":"fastlogin", + "name":"${project.parent.name}", + "version":"${project.version}-${git.commit.id.abbrev}", + "authors":["games647", "https://github.com/games647/FastLogin/graphs/contributors"], + "dependencies":[], + "main":"${project.groupId}.${project.artifactId}.${project.name}" + +} \ No newline at end of file From 7178ea45878a23559bcbfd2b782e89a517a889ce Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Mon, 13 Sep 2021 21:29:56 -0300 Subject: [PATCH 02/27] Seems like this is generated automatically. --- velocity/src/main/resources/velocity-plugin.json | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 velocity/src/main/resources/velocity-plugin.json diff --git a/velocity/src/main/resources/velocity-plugin.json b/velocity/src/main/resources/velocity-plugin.json deleted file mode 100644 index fc1dce76..00000000 --- a/velocity/src/main/resources/velocity-plugin.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "id":"fastlogin", - "name":"${project.parent.name}", - "version":"${project.version}-${git.commit.id.abbrev}", - "authors":["games647", "https://github.com/games647/FastLogin/graphs/contributors"], - "dependencies":[], - "main":"${project.groupId}.${project.artifactId}.${project.name}" - -} \ No newline at end of file From 0e7d8a595d65980185cfb98ba1d4ed53de2729be Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Tue, 14 Sep 2021 11:36:26 -0300 Subject: [PATCH 03/27] Added missing license header for some classes. --- .../fastlogin/velocity/FastLoginVelocity.java | 25 +++++++++++++++++++ .../velocity/VelocityLoginSession.java | 25 +++++++++++++++++++ .../velocity/VelocityLoginSource.java | 25 +++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 501db459..abab6c1b 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -1,3 +1,28 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity; import com.github.games647.fastlogin.core.AsyncScheduler; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java index 9d865a48..5a71ee98 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java @@ -1,3 +1,28 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity; import com.github.games647.fastlogin.core.StoredProfile; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java index abd3ef78..f6012b60 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java @@ -1,3 +1,28 @@ +/* + * SPDX-License-Identifier: MIT + * + * The MIT License (MIT) + * + * Copyright (c) 2015-2021 + * + * 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.velocity; import com.github.games647.fastlogin.core.shared.LoginSource; From de0655cba2173ed03067f1c065bc1d5ab7d9f5e4 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Tue, 14 Sep 2021 11:59:22 -0300 Subject: [PATCH 04/27] Changed the database driver to mysql --- velocity/pom.xml | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/velocity/pom.xml b/velocity/pom.xml index 2076c23d..b81284af 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -80,33 +80,15 @@ - - - codemc-repo - https://repo.codemc.io/repository/maven-public/ - - - - opencollab-snapshot - https://repo.opencollab.dev/maven-snapshots/ - - - - spigotplugins-repo - https://maven.gamestrike.de/mvn/ - - velocity https://nexus.velocitypowered.com/repository/maven-public/ + - jitpack.io - https://jitpack.io - - false - + Maven Central + https://repo1.maven.org/maven2/ @@ -126,11 +108,12 @@ provided + - org.xerial - sqlite-jdbc - 3.32.3 + mysql + mysql-connector-java + 8.0.26 + runtime - From 502b16a0e7c7a899a45706e557dbafb3b5fe472a Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Tue, 14 Sep 2021 12:12:04 -0300 Subject: [PATCH 05/27] Fill all plugin metadata properly. --- velocity/pom.xml | 13 +++++++++++++ .../github/games647/fastlogin/velocity/PomData.java | 9 +++++++++ .../fastlogin/velocity/FastLoginVelocity.java | 6 +++--- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 velocity/src/main/java-templates/com/github/games647/fastlogin/velocity/PomData.java diff --git a/velocity/pom.xml b/velocity/pom.xml index b81284af..8352c2a1 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -45,6 +45,19 @@ + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filter-src + + filter-sources + + + + org.apache.maven.plugins maven-shade-plugin diff --git a/velocity/src/main/java-templates/com/github/games647/fastlogin/velocity/PomData.java b/velocity/src/main/java-templates/com/github/games647/fastlogin/velocity/PomData.java new file mode 100644 index 00000000..340e0ea7 --- /dev/null +++ b/velocity/src/main/java-templates/com/github/games647/fastlogin/velocity/PomData.java @@ -0,0 +1,9 @@ +package com.github.games647.fastlogin.velocity; + +public class PomData { + public static final String DISPLAY_NAME = "${project.name}"; + public static final String NAME = "${project.parent.artifactId}"; + public static final String VERSION = "${project.version}-${git.commit.id.abbrev}"; + public static final String DESCRIPTION = "${project.parent.description}"; + public static final String URL = "${project.parent.url}"; +} diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index abab6c1b..888ed008 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -61,7 +61,8 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.slf4j.Logger; -@Plugin(id = "fastlogin") +@Plugin(id = PomData.NAME, name = PomData.DISPLAY_NAME, description = PomData.DESCRIPTION, url = PomData.URL, + version = PomData.VERSION, authors = {"games647", "https://github.com/games647/FastLogin/graphs/contributors"}) public class FastLoginVelocity implements PlatformPlugin { private final ProxyServer server; private final Path dataDirectory; @@ -96,8 +97,7 @@ public class FastLoginVelocity implements PlatformPlugin { @Override public String getName() { - //FIXME: some dynamic way to get it? - return "fastlogin"; + return PomData.NAME; } @Override From 89d03bcc6bd7b927f97ee4f2811e3ddc3d2377ff Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Tue, 14 Sep 2021 12:22:22 -0300 Subject: [PATCH 06/27] I missed that there was an alternative for bungee in the documentation --- .../games647/fastlogin/velocity/task/ForceLoginTask.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java index 50ad92e1..d6b0238d 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java @@ -130,8 +130,7 @@ public class ForceLoginTask @Override public boolean isOnline(Player player) { - //FIXME: is this right? - return core.getPlugin().getProxy().getPlayer(player.getUsername()).isPresent(); + return player.isActive(); } @Override From 6e318ba9bb1a34b9f4220f7c7c459a7b32cfc43a Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Tue, 14 Sep 2021 12:26:52 -0300 Subject: [PATCH 07/27] Use logger for exceptions --- .../games647/fastlogin/velocity/task/AsyncPremiumCheck.java | 2 +- .../github/games647/fastlogin/velocity/task/ForceLoginTask.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java index 30b6dd17..0fad9e2a 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java @@ -78,7 +78,7 @@ public class AsyncPremiumCheck extends JoinManagement Date: Tue, 14 Sep 2021 12:29:49 -0300 Subject: [PATCH 08/27] Ops, seems like velocity repo already mirrors the latest driver. --- velocity/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/velocity/pom.xml b/velocity/pom.xml index 8352c2a1..1e111a9a 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -97,12 +97,6 @@ velocity https://nexus.velocitypowered.com/repository/maven-public/ - - - - Maven Central - https://repo1.maven.org/maven2/ - From 268c70bc514fe6d58aa9fdda993ac55fa311353f Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Wed, 15 Sep 2021 13:54:28 -0300 Subject: [PATCH 09/27] Use org.slf4j.Logger directly --- velocity/pom.xml | 9 +++++---- .../games647/fastlogin/velocity/FastLoginVelocity.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/velocity/pom.xml b/velocity/pom.xml index 1e111a9a..7248110e 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -70,15 +70,16 @@ com.zaxxer.hikari fastlogin.hikari - - org.slf4j - fastlogin.slf4j - net.md_5.bungee.config fastlogin.config + + + org.slf4j:* + + diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 888ed008..8a38968d 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -72,9 +72,9 @@ public class FastLoginVelocity implements PlatformPlugin { private AsyncScheduler scheduler; @Inject - public FastLoginVelocity(ProxyServer server, java.util.logging.Logger logger, @DataDirectory Path dataDirectory) { + public FastLoginVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) { this.server = server; - this.logger = CommonUtil.createLoggerFromJDK(logger); + this.logger = logger; this.dataDirectory = dataDirectory; logger.info("FastLogin velocity."); } From 01632ec125382e2649bb9230152a4f531fa6ab6b Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Wed, 15 Sep 2021 15:44:51 -0300 Subject: [PATCH 10/27] Cleanup unused imports --- .../fastlogin/velocity/FastLoginVelocity.java | 14 ++++---------- .../fastlogin/velocity/VelocityLoginSource.java | 2 -- .../velocity/listener/ConnectListener.java | 3 --- .../velocity/listener/PluginMessageListener.java | 2 -- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 8a38968d..a7bd5c9d 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -26,10 +26,8 @@ package com.github.games647.fastlogin.velocity; import com.github.games647.fastlogin.core.AsyncScheduler; -import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; import com.github.games647.fastlogin.core.message.ChannelMessage; -import com.github.games647.fastlogin.core.message.NamespaceKey; import com.github.games647.fastlogin.core.message.SuccessMessage; import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.PlatformPlugin; @@ -41,26 +39,22 @@ import com.google.common.io.ByteStreams; import com.google.inject.Inject; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; -import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.slf4j.Logger; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.UUID; import java.util.concurrent.ConcurrentMap; -import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; -import com.velocitypowered.api.proxy.server.RegisteredServer; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.slf4j.Logger; - @Plugin(id = PomData.NAME, name = PomData.DISPLAY_NAME, description = PomData.DESCRIPTION, url = PomData.URL, version = PomData.VERSION, authors = {"games647", "https://github.com/games647/FastLogin/graphs/contributors"}) public class FastLoginVelocity implements PlatformPlugin { diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java index f6012b60..4c1e4423 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java @@ -26,11 +26,9 @@ package com.github.games647.fastlogin.velocity; import com.github.games647.fastlogin.core.shared.LoginSource; -import com.velocitypowered.api.event.Continuation; import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.proxy.InboundConnection; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.ComponentBuilder; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java index b7e00492..e18a1498 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -25,7 +25,6 @@ */ package com.github.games647.fastlogin.velocity.listener; -import com.github.games647.craftapi.UUIDAdapter; import com.github.games647.fastlogin.core.RateLimiter; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.LoginSession; @@ -33,13 +32,11 @@ import com.github.games647.fastlogin.velocity.FastLoginVelocity; import com.github.games647.fastlogin.velocity.VelocityLoginSession; import com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck; import com.github.games647.fastlogin.velocity.task.ForceLoginTask; -import com.google.common.base.Throwables; import com.velocitypowered.api.event.Continuation; import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.LoginEvent; - import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.proxy.InboundConnection; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java index 43f09e5d..bee1890c 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java @@ -27,7 +27,6 @@ package com.github.games647.fastlogin.velocity.listener; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.message.ChangePremiumMessage; -import com.github.games647.fastlogin.core.message.NamespaceKey; import com.github.games647.fastlogin.core.message.SuccessMessage; import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.velocity.FastLoginVelocity; @@ -41,7 +40,6 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; -import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import java.util.Arrays; From 4befb35af9d03a6013c3f38226b1ec2875b83136 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Wed, 15 Sep 2021 18:34:37 -0300 Subject: [PATCH 11/27] Added a way to generate or use a predefined proxy uuid. --- .../fastlogin/velocity/FastLoginVelocity.java | 54 +++++++++++++++++-- .../velocity/task/ForceLoginTask.java | 6 +-- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index a7bd5c9d..f1f7b040 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -49,9 +49,15 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.slf4j.Logger; +import java.io.*; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentMap; @@ -64,25 +70,26 @@ public class FastLoginVelocity implements PlatformPlugin { private FastLoginCore core; private final ConcurrentMap session = new MapMaker().weakKeys().makeMap(); private AsyncScheduler scheduler; + private UUID proxyId; + private final String PROXY_ID_fILE = "proxyId.txt"; @Inject public FastLoginVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) { this.server = server; this.logger = logger; this.dataDirectory = dataDirectory; - logger.info("FastLogin velocity."); } @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { scheduler = new AsyncScheduler(logger, getThreadFactory()); - core = new FastLoginCore<>(this); core.load(); - if (!core.setupDatabase()) { + loadOrGenerateProxyId(); + if (!core.setupDatabase() || proxyId == null) { return; } - logger.info("Velocity uuid for allowed proxies:" + UUID.nameUUIDFromBytes("velocity".getBytes(StandardCharsets.UTF_8))); + server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL)); server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL)); server.getEventManager().register(this, new ConnectListener(this, core.getRateLimiter())); @@ -141,4 +148,43 @@ public class FastLoginVelocity implements PlatformPlugin { server.sendPluginMessage(channel, dataOutput.toByteArray()); } } + + private void loadOrGenerateProxyId() { + File idFile = new File(dataDirectory.toFile(), PROXY_ID_fILE); + boolean shouldGenerate = false; + + if (idFile.exists()) { + try { + List lines = Files.readAllLines(idFile.toPath(), StandardCharsets.UTF_8); + if (lines.isEmpty()) { + shouldGenerate = true; + } else { + proxyId = UUID.fromString(lines.get(0)); + } + } catch (IOException e) { + e.printStackTrace(); + logger.error("Unable to load proxy id from '{}'", idFile.getAbsolutePath()); + logger.error("Detailed exception:", e); + } catch (IllegalArgumentException e) { + logger.error("'{}' contains an invalid uuid! FastLogin will not work without a valid id.", idFile.getAbsolutePath()); + } + } else { + shouldGenerate = true; + } + + if (shouldGenerate) { + proxyId = UUID.randomUUID(); + try { + Files.write(idFile.toPath(), Collections.singletonList(proxyId.toString()), + StandardCharsets.UTF_8, StandardOpenOption.CREATE); + } catch (IOException e) { + logger.error("Unable to save proxy id to '{}'", idFile.getAbsolutePath()); + logger.error("Detailed exception:", e); + } + } + } + + public UUID getProxyId() { + return proxyId; + } } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java index 44e4f034..4c75bf8d 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java @@ -115,11 +115,9 @@ public class ForceLoginTask if (session.needsRegistration()) { type = Type.REGISTER; } - //FIXME: Velocity does not have an alternative for this! - //UUID proxyId = UUID.fromString(ProxyServer.getInstance().getConfig().getUuid()); - UUID proxyId = UUID.nameUUIDFromBytes("velocity".getBytes(StandardCharsets.UTF_8)); - ChannelMessage loginMessage = new LoginActionMessage(type, player.getUsername(), proxyId); + UUID proxyId = core.getPlugin().getProxyId(); + ChannelMessage loginMessage = new LoginActionMessage(type, player.getUsername(), proxyId); core.getPlugin().sendPluginMessage(server, loginMessage); } From fc226e101064a0374322863226773f5d910cc364 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Wed, 15 Sep 2021 19:55:00 -0300 Subject: [PATCH 12/27] Moved LoginEvent logic to GameProfileRequestEvent. Allow overwriting online mode uuid and support for forwardSkin. Added one second delay for login command. --- .../velocity/listener/ConnectListener.java | 70 +++++++------------ .../velocity/task/ForceLoginTask.java | 1 - 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java index e18a1498..7b5c55e5 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -25,6 +25,7 @@ */ package com.github.games647.fastlogin.velocity.listener; +import com.github.games647.craftapi.UUIDAdapter; import com.github.games647.fastlogin.core.RateLimiter; import com.github.games647.fastlogin.core.StoredProfile; import com.github.games647.fastlogin.core.shared.LoginSession; @@ -33,17 +34,18 @@ import com.github.games647.fastlogin.velocity.VelocityLoginSession; import com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck; import com.github.games647.fastlogin.velocity.task.ForceLoginTask; import com.velocitypowered.api.event.Continuation; -import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.DisconnectEvent; -import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent; +import com.velocitypowered.api.event.player.GameProfileRequestEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.ArrayList; import java.util.UUID; +import java.util.concurrent.TimeUnit; public class ConnectListener { @@ -74,59 +76,32 @@ public class ConnectListener { plugin.getScheduler().runAsync(asyncPremiumCheck); } - @Subscribe(order = PostOrder.LATE) - 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 - Player connection = loginEvent.getPlayer(); - if (connection.isOnlineMode()) { - LoginSession session = plugin.getSession().get(connection.getRemoteAddress()); + @Subscribe + public void onGameprofileRequest(GameProfileRequestEvent event) { + if (event.isOnlineMode()) { + LoginSession session = plugin.getSession().get(event.getConnection().getRemoteAddress()); - UUID verifiedUUID = connection.getUniqueId(); - String verifiedUsername = connection.getUsername(); + UUID verifiedUUID = event.getGameProfile().getId(); + String verifiedUsername = event.getUsername(); session.setUuid(verifiedUUID); session.setVerifiedUsername(verifiedUsername); StoredProfile playerProfile = session.getProfile(); playerProfile.setId(verifiedUUID); + if (!plugin.getCore().getConfig().get("premiumUuid", true)) { + UUID offlineUUID = UUIDAdapter.generateOfflineId(playerProfile.getName()); + event.setGameProfile(event.getGameProfile().withId(offlineUUID)); + plugin.getLog().info("Overridden UUID from {} to {} (based of {}) on {}", + verifiedUUID, offlineUUID, verifiedUsername, event.getConnection()); + } - // bungeecord will do this automatically so override it on disabled option -// if (uniqueIdSetter != null) { -// InitialHandler initialHandler = (InitialHandler) connection; -// -// if (!plugin.getCore().getConfig().get("premiumUuid", true)) { -// setOfflineId(initialHandler, verifiedUsername); -// } -// -// if (!plugin.getCore().getConfig().get("forwardSkin", true)) { -// // this is null on offline mode -// LoginResult loginProfile = initialHandler.getLoginProfile(); -// loginProfile.setProperties(emptyProperties); -// } -// } + if (!plugin.getCore().getConfig().get("forwardSkin", true)) { + //FIXME: Do I need to remove *all* properties or only the skin related ones? + event.setGameProfile(event.getGameProfile().withProperties(new ArrayList<>())); + } } } -// private void setOfflineId(InitialHandler connection, String username) { -// try { -// final UUID oldPremiumId = connection.getUniqueId(); -// final UUID offlineUUID = UUIDAdapter.generateOfflineId(username); -// -// // BungeeCord only allows setting the UUID in PreLogin events and before requesting online mode -// // However if online mode is requested, it will override previous values -// // So we have to do it with reflection -// uniqueIdSetter.invokeExact(connection, offlineUUID); -// -// String format = "Overridden UUID from {} to {} (based of {}) on {}"; -// plugin.getLog().info(format, oldPremiumId, offlineUUID, username, connection); -// } catch (Exception ex) { -// plugin.getLog().error("Failed to set offline uuid of {}", username, ex); -// } catch (Throwable throwable) { -// // throw remaining exceptions like outofmemory that we shouldn't handle ourself -// Throwables.throwIfUnchecked(throwable); -// } -// } - @Subscribe public void onServerConnected(ServerConnectedEvent serverConnectedEvent) { Player player = serverConnectedEvent.getPlayer(); @@ -141,7 +116,10 @@ public class ConnectListener { // In this case it means that the force command (plugin message) is already received and processed while // player is still in the login phase and reported to be offline. Runnable loginTask = new ForceLoginTask(plugin.getCore(), player, server, session); - plugin.getScheduler().runAsync(loginTask); + plugin.getProxy().getScheduler() + .buildTask(plugin, () -> plugin.getScheduler().runAsync(loginTask)) + .delay(1L, TimeUnit.SECONDS) // Delay at least one second, otherwise the login command can be missed + .schedule(); } @Subscribe diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java index 4c75bf8d..c2ed6451 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/ForceLoginTask.java @@ -40,7 +40,6 @@ import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; -import java.nio.charset.StandardCharsets; import java.util.UUID; import java.util.concurrent.ExecutionException; From b6dfa4802a7e332a41ada53df2934215ad244e76 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Wed, 15 Sep 2021 19:57:19 -0300 Subject: [PATCH 13/27] Removed old FIXME and added a new TODO --- .../github/games647/fastlogin/velocity/FastLoginVelocity.java | 1 + .../games647/fastlogin/velocity/task/AsyncPremiumCheck.java | 1 - .../github/games647/fastlogin/velocity/task/ForceLoginTask.java | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index f1f7b040..77ae5b28 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -61,6 +61,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentMap; +//TODO: Support for floodgate @Plugin(id = PomData.NAME, name = PomData.DISPLAY_NAME, description = PomData.DESCRIPTION, url = PomData.URL, version = PomData.VERSION, authors = {"games647", "https://github.com/games647/FastLogin/graphs/contributors"}) public class FastLoginVelocity implements PlatformPlugin { diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java index 0fad9e2a..cb342da4 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java @@ -70,7 +70,6 @@ public class AsyncPremiumCheck extends JoinManagement Date: Wed, 15 Sep 2021 20:08:03 -0300 Subject: [PATCH 14/27] Some code formatting and cleanup --- .../fastlogin/velocity/FastLoginVelocity.java | 13 +++++++------ .../fastlogin/velocity/VelocityLoginSource.java | 2 -- .../velocity/listener/ConnectListener.java | 1 - .../velocity/listener/PluginMessageListener.java | 1 - 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 77ae5b28..da524f47 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -49,13 +49,13 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.slf4j.Logger; -import java.io.*; +import java.io.File; +import java.io.IOException; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -65,14 +65,16 @@ import java.util.concurrent.ConcurrentMap; @Plugin(id = PomData.NAME, name = PomData.DISPLAY_NAME, description = PomData.DESCRIPTION, url = PomData.URL, version = PomData.VERSION, authors = {"games647", "https://github.com/games647/FastLogin/graphs/contributors"}) public class FastLoginVelocity implements PlatformPlugin { + private final ProxyServer server; private final Path dataDirectory; private final Logger logger; - private FastLoginCore core; private final ConcurrentMap session = new MapMaker().weakKeys().makeMap(); + private final String PROXY_ID_fILE = "proxyId.txt"; + + private FastLoginCore core; private AsyncScheduler scheduler; private UUID proxyId; - private final String PROXY_ID_fILE = "proxyId.txt"; @Inject public FastLoginVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) { @@ -115,7 +117,6 @@ public class FastLoginVelocity implements PlatformPlugin { @Override public void sendMessage(CommandSource receiver, String message) { receiver.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); - } @Override @@ -132,7 +133,7 @@ public class FastLoginVelocity implements PlatformPlugin { return core; } - public ConcurrentMap getSession() { + public ConcurrentMap getSession() { return session; } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java index 4c1e4423..766c79f6 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java @@ -51,8 +51,6 @@ public class VelocityLoginSource implements LoginSource { @Override public void kick(String message) { - - if (message == null) { preLoginEvent.setResult(PreLoginEvent.PreLoginComponentResult.denied( Component.text("Kicked").color(NamedTextColor.WHITE))); diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java index 7b5c55e5..4aa04ba6 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -71,7 +71,6 @@ public class ConnectListener { String username = preLoginEvent.getUsername(); plugin.getLog().info("Incoming login request for {} from {}", username, connection.getRemoteAddress()); - Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, connection, username, continuation, preLoginEvent); plugin.getScheduler().runAsync(asyncPremiumCheck); } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java index bee1890c..b9df0a8a 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java @@ -113,7 +113,6 @@ public class PluginMessageListener { } private void onSuccessMessage(Player forPlayer) { - if (forPlayer.isOnlineMode()){ //bukkit module successfully received and force logged in the user //update only on success to prevent corrupt data From 68a783bd4094b02e991429f3c7218139fd1945dc Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Thu, 16 Sep 2021 13:25:35 -0300 Subject: [PATCH 15/27] Use path directly for loading the proxy uuid --- .../fastlogin/velocity/FastLoginVelocity.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index da524f47..a536e5a8 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -152,12 +152,12 @@ public class FastLoginVelocity implements PlatformPlugin { } private void loadOrGenerateProxyId() { - File idFile = new File(dataDirectory.toFile(), PROXY_ID_fILE); + Path idFile = dataDirectory.resolve(PROXY_ID_fILE); boolean shouldGenerate = false; - if (idFile.exists()) { + if (Files.exists(idFile)) { try { - List lines = Files.readAllLines(idFile.toPath(), StandardCharsets.UTF_8); + List lines = Files.readAllLines(idFile, StandardCharsets.UTF_8); if (lines.isEmpty()) { shouldGenerate = true; } else { @@ -165,10 +165,10 @@ public class FastLoginVelocity implements PlatformPlugin { } } catch (IOException e) { e.printStackTrace(); - logger.error("Unable to load proxy id from '{}'", idFile.getAbsolutePath()); + logger.error("Unable to load proxy id from '{}'", idFile.toAbsolutePath()); logger.error("Detailed exception:", e); } catch (IllegalArgumentException e) { - logger.error("'{}' contains an invalid uuid! FastLogin will not work without a valid id.", idFile.getAbsolutePath()); + logger.error("'{}' contains an invalid uuid! FastLogin will not work without a valid id.", idFile.toAbsolutePath()); } } else { shouldGenerate = true; @@ -177,10 +177,10 @@ public class FastLoginVelocity implements PlatformPlugin { if (shouldGenerate) { proxyId = UUID.randomUUID(); try { - Files.write(idFile.toPath(), Collections.singletonList(proxyId.toString()), + Files.write(idFile, Collections.singletonList(proxyId.toString()), StandardCharsets.UTF_8, StandardOpenOption.CREATE); } catch (IOException e) { - logger.error("Unable to save proxy id to '{}'", idFile.getAbsolutePath()); + logger.error("Unable to save proxy id to '{}'", idFile.toAbsolutePath()); logger.error("Detailed exception:", e); } } From 7ade1278884bcea8947a40a19909d87e237b6e62 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Thu, 16 Sep 2021 13:42:36 -0300 Subject: [PATCH 16/27] Relocate the MySql Driver --- velocity/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/velocity/pom.xml b/velocity/pom.xml index 7248110e..778e446c 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -74,6 +74,10 @@ net.md_5.bungee.config fastlogin.config + + com.mysql + fastlogin.mysql + From d0491d44ec6ac13a6504c226f55b67340e800240 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Fri, 17 Sep 2021 09:34:52 -0300 Subject: [PATCH 17/27] Remove left over assertion --- .../games647/fastlogin/velocity/listener/ConnectListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java index 4aa04ba6..76742e4f 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -124,7 +124,6 @@ public class ConnectListener { @Subscribe public void onDisconnect(DisconnectEvent disconnectEvent) { Player player = disconnectEvent.getPlayer(); - assert plugin.getSession().remove(player.getRemoteAddress()) != null; plugin.getCore().getPendingConfirms().remove(player.getUniqueId()); } } From bc4d9857b49e374181aaf21e7a86d94a9f976f6f Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Fri, 17 Sep 2021 09:36:51 -0300 Subject: [PATCH 18/27] Ops, printing exception directly --- .../github/games647/fastlogin/velocity/FastLoginVelocity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index a536e5a8..a1417927 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -164,7 +164,6 @@ public class FastLoginVelocity implements PlatformPlugin { proxyId = UUID.fromString(lines.get(0)); } } catch (IOException e) { - e.printStackTrace(); logger.error("Unable to load proxy id from '{}'", idFile.toAbsolutePath()); logger.error("Detailed exception:", e); } catch (IllegalArgumentException e) { From 310ef4068cdc43930f2ac38af45495871f5fe9a7 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Fri, 17 Sep 2021 09:37:50 -0300 Subject: [PATCH 19/27] Make `PROXY_ID_fILE` static --- .../github/games647/fastlogin/velocity/FastLoginVelocity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index a1417927..05d5bc0e 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -70,7 +70,7 @@ public class FastLoginVelocity implements PlatformPlugin { private final Path dataDirectory; private final Logger logger; private final ConcurrentMap session = new MapMaker().weakKeys().makeMap(); - private final String PROXY_ID_fILE = "proxyId.txt"; + private static final String PROXY_ID_fILE = "proxyId.txt"; private FastLoginCore core; private AsyncScheduler scheduler; From 20379d13b292b4bb78c27565e39a75ce27463632 Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Fri, 17 Sep 2021 09:40:12 -0300 Subject: [PATCH 20/27] Commented why org.slf4j is excluded from the final jar --- velocity/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/velocity/pom.xml b/velocity/pom.xml index 778e446c..9639240d 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -80,6 +80,8 @@ + org.slf4j:* From 64fbbf759fe66e3699b1f3e79831ac4612872f5d Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Fri, 17 Sep 2021 09:45:09 -0300 Subject: [PATCH 21/27] Actually handle proxy shutdown this time --- .../games647/fastlogin/velocity/FastLoginVelocity.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 05d5bc0e..15e7beea 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -40,6 +40,7 @@ import com.google.inject.Inject; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.Player; @@ -99,6 +100,13 @@ public class FastLoginVelocity implements PlatformPlugin { server.getEventManager().register(this, new PluginMessageListener(this)); } + @Subscribe + public void onProxyShutdown(ProxyShutdownEvent event) { + if (core != null) { + core.close(); + } + } + @Override public String getName() { return PomData.NAME; From c458bd383a9517b19914aaeb7b75e36ed72d121f Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Fri, 17 Sep 2021 10:00:45 -0300 Subject: [PATCH 22/27] Only remove the texture property from the player profile if forwardSkin is disabled --- .../velocity/listener/ConnectListener.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java index 76742e4f..73f73963 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -42,8 +42,10 @@ import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; +import com.velocitypowered.api.util.GameProfile; import java.util.ArrayList; +import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -95,12 +97,20 @@ public class ConnectListener { } if (!plugin.getCore().getConfig().get("forwardSkin", true)) { - //FIXME: Do I need to remove *all* properties or only the skin related ones? - event.setGameProfile(event.getGameProfile().withProperties(new ArrayList<>())); + event.setGameProfile(event.getGameProfile().withProperties(removeSkin(event.getGameProfile().getProperties()))); } } } + private List removeSkin(List oldProperties) { + List newProperties = new ArrayList<>(oldProperties.size() - 1); + for (GameProfile.Property property : oldProperties) { + if (!property.getName().equals("textures")) + newProperties.add(property); + } + return newProperties; + } + @Subscribe public void onServerConnected(ServerConnectedEvent serverConnectedEvent) { Player player = serverConnectedEvent.getPlayer(); From 709edc6c0ac73e572ec7bc459fad9bbe74d3486a Mon Sep 17 00:00:00 2001 From: juanmuscaria Date: Fri, 17 Sep 2021 10:04:05 -0300 Subject: [PATCH 23/27] Added comment to the config to notify about the different driver name --- core/src/main/resources/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 8e048961..4c89a7c4 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -252,6 +252,7 @@ database: '{pluginDir}/FastLogin.db' # MySQL/MariaDB # If you want to enable it uncomment only the lines below this not this line. +# If on velocity use 'fastlogin.mysql.cj.jdbc.Driver' as driver #driver: 'com.mysql.jdbc.Driver' #host: '127.0.0.1' #port: 3306 From 5192b98d7806ca53baf9e6b7acd844326b53bfb4 Mon Sep 17 00:00:00 2001 From: games647 Date: Wed, 22 Sep 2021 11:48:28 +0200 Subject: [PATCH 24/27] Use java runner for cache --- .github/workflows/maven.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7ae5ed1b..408bfc92 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,25 +26,14 @@ jobs: # Pull changes - uses: actions/checkout@v2.3.4 - # Cache artifacts - however this has the downside that we don't get notified of - # artifact resolution failures like invalid repository - # Nevertheless the repositories should be more stable and it makes no sense to pull - # a same version every time - # A dry run would make more sense - - uses: actions/cache@v2.1.4 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - # Setup Java - name: Set up JDK - uses: actions/setup-java@v2.1.0 + uses: actions/setup-java@v2.3.0 with: distribution: 'adopt' # Use Java 11, because it's minimum required version java-version: 11 + cache: 'maven' # Build and test (included in package) - name: Build with Maven and test From 665881d19a626d97b84f92d84f1e06c41afc64a9 Mon Sep 17 00:00:00 2001 From: games647 Date: Wed, 22 Sep 2021 12:01:08 +0200 Subject: [PATCH 25/27] Exclude gson already present in velocity --- velocity/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/velocity/pom.xml b/velocity/pom.xml index 9639240d..647f81a0 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -84,6 +84,7 @@ shading and relocating it causes logger injection to fail--> org.slf4j:* + com.google.code.gson:gson From c2ec8c93b05e2b30f30df11786dbdd9284808789 Mon Sep 17 00:00:00 2001 From: games647 Date: Wed, 22 Sep 2021 12:03:44 +0200 Subject: [PATCH 26/27] Use the MariaDB driver for a smaller footprint --- velocity/pom.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/velocity/pom.xml b/velocity/pom.xml index 647f81a0..64582e85 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -125,10 +125,9 @@ - mysql - mysql-connector-java - 8.0.26 - runtime + org.mariadb.jdbc + mariadb-java-client + 2.7.4 From 37ac04c8ed32f78409348ddd365ab39a610ada0a Mon Sep 17 00:00:00 2001 From: games647 Date: Wed, 22 Sep 2021 12:13:33 +0200 Subject: [PATCH 27/27] Reformat --- .../fastlogin/velocity/FastLoginVelocity.java | 14 +++++++------- .../fastlogin/velocity/VelocityLoginSession.java | 2 ++ .../fastlogin/velocity/VelocityLoginSource.java | 9 +++++---- .../event/VelocityFastLoginAutoLoginEvent.java | 3 ++- .../velocity/listener/ConnectListener.java | 6 ++++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java index 15e7beea..9de54b5a 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java @@ -47,10 +47,7 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.server.RegisteredServer; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.slf4j.Logger; -import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; @@ -62,6 +59,10 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentMap; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +import org.slf4j.Logger; + //TODO: Support for floodgate @Plugin(id = PomData.NAME, name = PomData.DISPLAY_NAME, description = PomData.DESCRIPTION, url = PomData.URL, version = PomData.VERSION, authors = {"games647", "https://github.com/games647/FastLogin/graphs/contributors"}) @@ -94,10 +95,10 @@ public class FastLoginVelocity implements PlatformPlugin { return; } - server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL)); - server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL)); server.getEventManager().register(this, new ConnectListener(this, core.getRateLimiter())); server.getEventManager().register(this, new PluginMessageListener(this)); + server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL)); + server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL)); } @Subscribe @@ -184,8 +185,7 @@ public class FastLoginVelocity implements PlatformPlugin { if (shouldGenerate) { proxyId = UUID.randomUUID(); try { - Files.write(idFile, Collections.singletonList(proxyId.toString()), - StandardCharsets.UTF_8, StandardOpenOption.CREATE); + Files.write(idFile, Collections.singletonList(proxyId.toString()), StandardOpenOption.CREATE); } catch (IOException e) { logger.error("Unable to save proxy id to '{}'", idFile.toAbsolutePath()); logger.error("Detailed exception:", e); diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java index 5a71ee98..be5d314d 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSession.java @@ -31,9 +31,11 @@ import com.github.games647.fastlogin.core.shared.LoginSession; public class VelocityLoginSession extends LoginSession { private boolean alreadySaved; private boolean alreadyLogged; + public VelocityLoginSession(String requestUsername, boolean registered, StoredProfile profile) { super(requestUsername, registered, profile); } + public synchronized void setRegistered(boolean registered) { this.registered = registered; } diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java index 766c79f6..d2ee5102 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/VelocityLoginSource.java @@ -28,16 +28,17 @@ package com.github.games647.fastlogin.velocity; import com.github.games647.fastlogin.core.shared.LoginSource; import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.proxy.InboundConnection; + +import java.net.InetSocketAddress; + import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import java.net.InetSocketAddress; - public class VelocityLoginSource implements LoginSource { - private InboundConnection connection; - private PreLoginEvent preLoginEvent; + private final InboundConnection connection; + private final PreLoginEvent preLoginEvent; public VelocityLoginSource(InboundConnection connection, PreLoginEvent preLoginEvent) { this.connection = connection; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java index 09b72603..61ecb1a8 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/event/VelocityFastLoginAutoLoginEvent.java @@ -32,7 +32,8 @@ import com.velocitypowered.api.event.ResultedEvent; import java.util.Objects; -public class VelocityFastLoginAutoLoginEvent implements FastLoginAutoLoginEvent, ResultedEvent { +public class VelocityFastLoginAutoLoginEvent + implements FastLoginAutoLoginEvent, ResultedEvent { private final LoginSession session; private final StoredProfile profile; diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java index 73f73963..acb24c7b 100644 --- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java @@ -59,11 +59,12 @@ public class ConnectListener { this.rateLimiter = rateLimiter; } - @Subscribe() + @Subscribe public void onPreLogin(PreLoginEvent preLoginEvent, Continuation continuation) { if (!preLoginEvent.getResult().isAllowed()) { return; } + InboundConnection connection = preLoginEvent.getConnection(); if (!rateLimiter.tryAcquire()) { plugin.getLog().warn("Simple Anti-Bot join limit - Ignoring {}", connection); @@ -105,9 +106,10 @@ public class ConnectListener { private List removeSkin(List oldProperties) { List newProperties = new ArrayList<>(oldProperties.size() - 1); for (GameProfile.Property property : oldProperties) { - if (!property.getName().equals("textures")) + if (!"textures".equals(property.getName())) newProperties.add(property); } + return newProperties; }