finishing all govindas requests

This commit is contained in:
mohammed jasem alaajel 2021-12-15 00:08:22 +04:00
parent 562e8ff014
commit 20a47229ef
2 changed files with 26 additions and 19 deletions

View File

@ -33,4 +33,15 @@ public class Messages {
&2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m &2&m""".replace("&", "§");
public final static String cracked_disclaimer = """
&c&oYou have been found using Offline minecraft (Cracked)
&7&o This could happen because:
1. Mojang / Microsoft api is down\040\040\040\040\040\040\040\040\040
2. Disconnecting when connection to a server faster!
3. Using cracked minecraft (if you are using cracked Minecraft please reconnect!
&6If this a mistake and you own a Minecraft account\040
&cPlease disconnect from the server and connect to
&areset.limework.net""".replace("&", "§");
}

View File

@ -5,6 +5,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.inject.Inject;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PostLoginEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent;
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
@ -40,17 +41,12 @@ public class VelocityGalPlugin {
private final ConfigLoader config;
private final Cache<String, Long> secondAttemptAsCrackedCache;
private final Cache<String, Object> offlineModePlayers;
private final Cache<String, Object> showFailedMessage;
@Inject
public VelocityGalPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) {
this.proxyServer = proxyServer;
this.logger = logger;
this.dataFolder = dataDirectory.toFile();
this.showFailedMessage = CacheBuilder.newBuilder()
.maximumSize(4000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
this.offlineModePlayers = CacheBuilder.newBuilder()
.maximumSize(4000)
.expireAfterWrite(48, TimeUnit.HOURS)
@ -87,26 +83,21 @@ public class VelocityGalPlugin {
@Subscribe(order = PostOrder.FIRST)
public void onPreLoginEvent(PreLoginEvent event) {
if (event.getConnection().getVirtualHost().get().getHostName().toLowerCase(Locale.ROOT).equals(config.getResetDomain())) {
secondAttemptAsCrackedCache.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
showFailedMessage.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
offlineModePlayers.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
secondAttemptAsCrackedCache.invalidate(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName());
offlineModePlayers.invalidate(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName());
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(Messages.RESET_MESSAGE)));
} else if (isCrackedPlayer(event.getUsername(), config)) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
} else if (offlineModePlayers.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) != null) {
} else if (offlineModePlayers.getIfPresent(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName()) != null) {
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
} else {
if (secondAttemptAsCrackedCache.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) != null) {
if (showFailedMessage.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) == null
&& offlineModePlayers.getIfPresent(event.getUsername() + event.getConnection().getRemoteAddress().getHostName()) == null) {
showFailedMessage.put(event.getUsername() + event.getConnection().getRemoteAddress().getHostName(), new Object());
offlineModePlayers.put(event.getUsername() + event.getConnection().getRemoteAddress().getHostName(), new Object());
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(Messages.FAILED_CONNECTION)));
} else {
if (secondAttemptAsCrackedCache.getIfPresent(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName()) != null) {
if (offlineModePlayers.getIfPresent(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName()) == null) {
offlineModePlayers.put(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName(), new Object());
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
}
} else {
secondAttemptAsCrackedCache.put(event.getUsername() + event.getConnection().getRemoteAddress().getHostName(), System.currentTimeMillis());
secondAttemptAsCrackedCache.put(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName(), System.currentTimeMillis());
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
}
}
@ -114,7 +105,7 @@ public class VelocityGalPlugin {
@Subscribe
public void onGameProfileRequestEvent(GameProfileRequestEvent event) {
secondAttemptAsCrackedCache.invalidate(event.getUsername() + event.getConnection().getRemoteAddress().getHostName());
secondAttemptAsCrackedCache.invalidate(getCorrectCrackedUsername(event.getUsername(), config) + event.getConnection().getRemoteAddress().getHostName());
if (!event.isOnlineMode()) {
logger.info("handling " + event.getUsername());
String username = getCorrectCrackedUsername(event.getUsername(), config);
@ -125,7 +116,12 @@ public class VelocityGalPlugin {
}
}
@Subscribe
public void onPostLoginEvent(PostLoginEvent event) {
if (offlineModePlayers.getIfPresent(getCorrectCrackedUsername(event.getPlayer().getUsername(), config) + event.getPlayer().getRemoteAddress().getHostName()) != null) {
event.getPlayer().sendMessage(Component.text(Messages.cracked_disclaimer));
}
}
public ProxyServer getProxyServer() {
return proxyServer;
}