forked from TuxCoding/FastLogin
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;
|
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.RateLimiter;
|
||||||
import com.github.games647.fastlogin.core.StoredProfile;
|
import com.github.games647.fastlogin.core.StoredProfile;
|
||||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
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.AsyncPremiumCheck;
|
||||||
import com.github.games647.fastlogin.velocity.task.ForceLoginTask;
|
import com.github.games647.fastlogin.velocity.task.ForceLoginTask;
|
||||||
import com.velocitypowered.api.event.Continuation;
|
import com.velocitypowered.api.event.Continuation;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
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.connection.PreLoginEvent;
|
||||||
|
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
import com.velocitypowered.api.proxy.InboundConnection;
|
import com.velocitypowered.api.proxy.InboundConnection;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ConnectListener {
|
public class ConnectListener {
|
||||||
|
|
||||||
@ -74,59 +76,32 @@ public class ConnectListener {
|
|||||||
plugin.getScheduler().runAsync(asyncPremiumCheck);
|
plugin.getScheduler().runAsync(asyncPremiumCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LATE)
|
@Subscribe
|
||||||
public void onLogin(LoginEvent loginEvent) {
|
public void onGameprofileRequest(GameProfileRequestEvent event) {
|
||||||
//use the login event instead of the post login event in order to send the login success packet to the client
|
if (event.isOnlineMode()) {
|
||||||
//with the offline uuid this makes it possible to set the skin then
|
LoginSession session = plugin.getSession().get(event.getConnection().getRemoteAddress());
|
||||||
Player connection = loginEvent.getPlayer();
|
|
||||||
if (connection.isOnlineMode()) {
|
|
||||||
LoginSession session = plugin.getSession().get(connection.getRemoteAddress());
|
|
||||||
|
|
||||||
UUID verifiedUUID = connection.getUniqueId();
|
UUID verifiedUUID = event.getGameProfile().getId();
|
||||||
String verifiedUsername = connection.getUsername();
|
String verifiedUsername = event.getUsername();
|
||||||
session.setUuid(verifiedUUID);
|
session.setUuid(verifiedUUID);
|
||||||
session.setVerifiedUsername(verifiedUsername);
|
session.setVerifiedUsername(verifiedUsername);
|
||||||
|
|
||||||
StoredProfile playerProfile = session.getProfile();
|
StoredProfile playerProfile = session.getProfile();
|
||||||
playerProfile.setId(verifiedUUID);
|
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 (!plugin.getCore().getConfig().get("forwardSkin", true)) {
|
||||||
// if (uniqueIdSetter != null) {
|
//FIXME: Do I need to remove *all* properties or only the skin related ones?
|
||||||
// InitialHandler initialHandler = (InitialHandler) connection;
|
event.setGameProfile(event.getGameProfile().withProperties(new ArrayList<>()));
|
||||||
//
|
}
|
||||||
// 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
|
@Subscribe
|
||||||
public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
|
public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
|
||||||
Player player = serverConnectedEvent.getPlayer();
|
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
|
// 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.
|
// player is still in the login phase and reported to be offline.
|
||||||
Runnable loginTask = new ForceLoginTask(plugin.getCore(), player, server, session);
|
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
|
@Subscribe
|
||||||
|
@ -40,7 +40,6 @@ import com.velocitypowered.api.command.CommandSource;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user