Add second attemp login -> cracked (Fixes #51)

This commit is contained in:
games647 committed 2016-08-29 17:38:46 +02:00
1 parent c28d889c1b
commit d20db79f46
16 files changed
+124 -40

No files matched your search

@@ -2,11 +2,14 @@ package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.google.common.base.Charsets;
import com.google.common.cache.CacheLoader;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.io.File;
import java.io.InputStreamReader;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
@@ -14,9 +17,30 @@ import org.bukkit.configuration.file.YamlConfiguration;
public class BukkitCore extends FastLoginCore {
public static <K, V> ConcurrentMap<K, V> buildCache(int minutes, int maxSize) {
CompatibleCacheBuilder<Object, Object> builder = CompatibleCacheBuilder.newBuilder();
if (minutes > 0) {
builder.expireAfterWrite(minutes, TimeUnit.MINUTES);
}
if (maxSize > 0) {
builder.maximumSize(maxSize);
}
return builder.build(new CacheLoader<K, V>() {
@Override
public V load(K key) throws Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
private final FastLoginBukkit plugin;
public BukkitCore(FastLoginBukkit plugin) {
super(BukkitCore.<String, Object>buildCache(5, 0));
this.plugin = plugin;
}
@@ -15,7 +15,6 @@ import com.github.games647.fastlogin.bukkit.listener.protocollib.StartPacketList
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
import com.github.games647.fastlogin.core.FastLoginCore;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.Sets;
import java.security.KeyPair;
@@ -23,7 +22,6 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import org.bukkit.entity.Player;
@@ -47,7 +45,7 @@ public class FastLoginBukkit extends JavaPlugin {
//this map is thread-safe for async access (Packet Listener)
//SafeCacheBuilder is used in order to be version independent
private final ConcurrentMap<String, BukkitLoginSession> session = buildCache(1, -1);
private final ConcurrentMap<String, BukkitLoginSession> session = BukkitCore.buildCache(1, -1);
//1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
private BukkitAuthPlugin authPlugin;
@@ -60,7 +58,8 @@ public class FastLoginBukkit extends JavaPlugin {
List<String> ipAddresses = getConfig().getStringList("ip-addresses");
int requestLimit = getConfig().getInt("mojang-request-limit");
MojangApiBukkit mojangApi = new MojangApiBukkit(buildCache(10, -1), getLogger(), ipAddresses, requestLimit);
ConcurrentMap<Object, Object> requestCache = BukkitCore.buildCache(10, -1);
MojangApiBukkit mojangApi = new MojangApiBukkit(requestCache, getLogger(), ipAddresses, requestLimit);
core.setMojangApiConnector(mojangApi);
try {
@@ -220,23 +219,4 @@ public class FastLoginBukkit extends JavaPlugin {
this.serverStarted = true;
}
}
private <K, V> ConcurrentMap<K, V> buildCache(int minutes, int maxSize) {
CompatibleCacheBuilder<Object, Object> builder = CompatibleCacheBuilder.newBuilder();
if (minutes > 0) {
builder.expireAfterWrite(minutes, TimeUnit.MINUTES);
}
if (maxSize > 0) {
builder.maximumSize(maxSize);
}
return builder.build(new CacheLoader<K, V>() {
@Override
public V load(K key) throws Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
});
}
}
@@ -54,7 +54,18 @@ public class NameCheckTask implements Runnable {
if (profile.getUserId() == -1) {
UUID premiumUUID = null;
String ip = player.getAddress().getAddress().getHostAddress();
if (plugin.getCore().getPendingLogins().containsKey(ip + username)
&& plugin.getConfig().getBoolean("secondAttemptCracked")) {
plugin.getLogger().log(Level.INFO, "Second attempt login -> cracked {0}", username);
//first login request failed so make a cracked session
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.getSessions().put(player.getAddress().toString(), loginSession);
return;
}
//user not exists in the db
try {
boolean isRegistered = plugin.getAuthPlugin().isRegistered(username);
@@ -105,6 +116,9 @@ public class NameCheckTask implements Runnable {
boolean success = sentEncryptionRequest(player, serverId, verify);
if (success) {
String ip = player.getAddress().getAddress().getHostAddress();
plugin.getCore().getPendingLogins().put(ip + username, new Object());
BukkitLoginSession playerSession = new BukkitLoginSession(username, serverId, verify, registered, profile);
plugin.getSessions().put(player.getAddress().toString(), playerSession);
//cancel only if the player has a paid account otherwise login as normal offline player
@@ -50,6 +50,9 @@ public class VerifyResponseTask implements Runnable {
disconnect(plugin.getCore().getMessage("invalid-requst"), true
, "Player {0} tried to send encryption response at invalid state", fromPlayer.getAddress());
} else {
String ip = fromPlayer.getAddress().getAddress().getHostAddress();
plugin.getCore().getPendingLogins().remove(ip + session.getUsername());
verifyResponse(session);
}
} finally {
@@ -31,9 +31,10 @@ public class ProtocolSupportListener implements Listener {
}
String username = loginStartEvent.getName();
InetSocketAddress address = loginStartEvent.getAddress();
//remove old data every time on a new login in order to keep the session only for one person
plugin.getSessions().remove(loginStartEvent.getAddress().toString());
plugin.getSessions().remove(address.toString());
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
if (authPlugin == null) {
@@ -43,6 +44,18 @@ public class ProtocolSupportListener implements Listener {
PlayerProfile profile = plugin.getCore().getStorage().loadProfile(username);
if (profile != null) {
if (profile.getUserId() == -1) {
String ip = address.getAddress().getHostAddress();
if (plugin.getCore().getPendingLogins().containsKey(ip + username)
&& plugin.getConfig().getBoolean("secondAttemptCracked")) {
plugin.getLogger().log(Level.INFO, "Second attempt login -> cracked {0}", username);
//first login request failed so make a cracked session
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.getSessions().put(address.toString(), loginSession);
return;
}
UUID premiumUUID = null;
//user not exists in the db
@@ -70,7 +83,7 @@ public class ProtocolSupportListener implements Listener {
//no premium check passed so we save it as a cracked player
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.getSessions().put(loginStartEvent.getAddress().toString(), loginSession);
plugin.getSessions().put(address.toString(), loginSession);
} catch (Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex);
}
@@ -78,7 +91,7 @@ public class ProtocolSupportListener implements Listener {
startPremiumSession(username, loginStartEvent, true, profile);
} else {
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.getSessions().put(loginStartEvent.getAddress().toString(), loginSession);
plugin.getSessions().put(address.toString(), loginSession);
}
}
}
@@ -90,17 +103,23 @@ public class ProtocolSupportListener implements Listener {
InetSocketAddress address = propertiesResolveEvent.getAddress();
BukkitLoginSession session = plugin.getSessions().get(address.toString());
if (session != null) {
String ip = address.getAddress().getHostAddress();
plugin.getCore().getPendingLogins().remove(ip + session.getUsername());
session.setVerified(true);
}
}
}
private void startPremiumSession(String playerName, PlayerLoginStartEvent loginStartEvent, boolean registered
private void startPremiumSession(String username, PlayerLoginStartEvent loginStartEvent, boolean registered
, PlayerProfile playerProfile) {
loginStartEvent.setOnlineMode(true);
InetSocketAddress address = loginStartEvent.getAddress();
BukkitLoginSession playerSession = new BukkitLoginSession(playerName, null, null, registered, playerProfile);
String ip = address.getAddress().getHostAddress();
plugin.getCore().getPendingLogins().put(ip + username, new Object());
BukkitLoginSession playerSession = new BukkitLoginSession(username, null, null, registered, playerProfile);
plugin.getSessions().put(address.toString(), playerSession);
if (plugin.getConfig().getBoolean("premiumUuid")) {
loginStartEvent.setUseOnlineModeUUID(true);