mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Moved LoginEvent logic to GameProfileRequestEvent. Allow overwriting online mode uuid and support for forwardSkin. Added one second delay for login command.
This commit is contained in:
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user