Clean up methods names and documentation

This commit is contained in:
games647
2024-05-21 14:41:41 +02:00
parent e9643ee3e2
commit be2ec1e5a8
26 changed files with 97 additions and 109 deletions
@@ -82,7 +82,7 @@ public abstract class FloodgateManagement<P extends C, C, L extends LoginSession
profile = core.getStorage().loadProfile(username);
if (profile.isSaved()) {
if (profile.isExistingPlayer()) {
if (profile.isFloodgateMigrated()) {
if (profile.getFloodgate() == FloodgateState.TRUE && isLinked) {
core.getPlugin().getLog()
@@ -71,60 +71,65 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
} else {
profile.setFloodgate(FloodgateState.FALSE);
core.getPlugin().getLog().info(
"Player {} will be migrated to the v2 database schema as a JAVA user", username);
"Player {} will be migrated to the v2 database schema as a JAVA user", username
);
}
callFastLoginPreLoginEvent(username, source, profile);
Configuration config = core.getConfig();
String ip = source.getAddress().getAddress().getHostAddress();
profile.setLastIp(ip);
try {
if (profile.isSaved()) {
if (profile.isOnlinemodePreferred()) {
core.getPlugin().getLog().info("Requesting premium login for registered player: {}", username);
requestPremiumLogin(source, profile, username, true);
} else {
if (isValidUsername(source, profile)) {
startCrackedSession(source, profile, username);
}
}
if (profile.isExistingPlayer()) {
if (profile.isOnlinemodePreferred()) {
core.getPlugin().getLog().info("Requesting premium login for registered player: {}", username);
requestPremiumLogin(source, profile, username, true);
} else {
if (core.hasFailedLogin(ip, username)) {
core.getPlugin().getLog().info("Second attempt login -> cracked {}", username);
//first login request failed so make a cracked session
startCrackedSession(source, profile, username);
return;
}
Optional<Profile> premiumUUID = Optional.empty();
if (config.get("nameChangeCheck", false) || config.get("autoRegister", false)) {
premiumUUID = core.getResolver().findProfile(username);
}
if (!premiumUUID.isPresent()
|| (!checkNameChange(source, username, premiumUUID.get())
&& !checkPremiumName(source, username, profile))) {
//nothing detected the player as premium -> start a cracked session
if (core.getConfig().get("switchMode", false)) {
source.kick(core.getMessage("switch-kick-message"));
return;
}
if (isValidUsername(source, profile)) {
startCrackedSession(source, profile, username);
}
}
} else {
performNewPlayerLogin(username, source, ip, profile);
}
}
private void performNewPlayerLogin(String username, S source, String ip, StoredProfile profile) {
try {
if (core.hasFailedLogin(ip, username)) {
core.getPlugin().getLog().info("Second attempt login -> cracked {}", username);
//first login request failed so make a cracked session
startCrackedSession(source, profile, username);
return;
}
Configuration config = core.getConfig();
Optional<Profile> premiumUUID = Optional.empty();
if (config.get("nameChangeCheck", false) || config.get("autoRegister", false)) {
premiumUUID = core.getResolver().findProfile(username);
}
if (!premiumUUID.isPresent()
|| (!isNameChanged(source, username, premiumUUID.get())
&& !isUsernameAvailable(source, username, profile))) {
//nothing detected the player as premium -> start a cracked session
if (core.getConfig().get("switchMode", false)) {
source.kick(core.getMessage("switch-kick-message"));
return;
}
startCrackedSession(source, profile, username);
}
} catch (RateLimitException rateLimitEx) {
core.getPlugin().getLog().error("Mojang's rate limit reached for {}. The public IPv4 address of this"
+ " server issued more than 600 Name -> UUID requests within 10 minutes. After those 10"
+ " minutes we can make requests again.", username);
+ " server issued more than 600 Name -> UUID requests within 10 minutes. After those 10"
+ " minutes we can make requests again.", username);
} catch (Exception ex) {
core.getPlugin().getLog().error("Failed to check premium state of {}", username, ex);
}
}
protected boolean isValidUsername(LoginSource source, StoredProfile profile) throws Exception {
protected boolean isValidUsername(LoginSource source, StoredProfile profile) {
if (bedrockService != null && bedrockService.isUsernameForbidden(profile)) {
core.getPlugin().getLog().info("Floodgate Prefix detected on cracked player");
source.kick("Your username contains illegal characters");
@@ -134,7 +139,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
return true;
}
private boolean checkPremiumName(S source, String username, StoredProfile profile) throws Exception {
private boolean isUsernameAvailable(S source, String username, StoredProfile profile) throws Exception {
core.getPlugin().getLog().info("GameProfile {} uses a premium username", username);
if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) {
requestPremiumLogin(source, profile, username, false);
@@ -144,7 +149,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
return false;
}
private boolean checkNameChange(S source, String username, Profile profile) {
private boolean isNameChanged(S source, String username, Profile profile) {
//user not exists in the db
if (core.getConfig().get("nameChangeCheck", false)) {
StoredProfile storedProfile = core.getStorage().loadProfile(profile.getId());
@@ -31,7 +31,7 @@ public interface LoginSource {
void enableOnlinemode() throws Exception;
void kick(String message) throws Exception;
void kick(String message);
InetSocketAddress getAddress();
}
@@ -176,7 +176,7 @@ public abstract class SQLStorage implements AuthStorage {
playerProfile.getSaveLock().lock();
try {
if (playerProfile.isSaved()) {
if (playerProfile.isExistingPlayer()) {
try (PreparedStatement saveStmt = con.prepareStatement(UPDATE_PROFILE)) {
saveStmt.setString(1, uuid);
saveStmt.setString(2, playerProfile.getName());
@@ -68,7 +68,7 @@ public class StoredProfile extends Profile {
return saveLock;
}
public synchronized boolean isSaved() {
public synchronized boolean isExistingPlayer() {
return rowId >= 0;
}
+1 -1
View File
@@ -9,7 +9,7 @@
# problem. Low level firewalls like uwf (or iptables direct) are more efficient than a Minecraft plugin. TCP reverse
# proxies could also be used and offload some work even to different host.
#
# The settings wil limit how many connections this plugin will handle. After hitting this limit. FastLogin will
# The settings will limit how many connections this plugin will handle. After hitting this limit. FastLogin will
# completely ignore incoming connections. Effectively there will be no database requests and network requests.
# Therefore, auto logins won't be possible.
anti-bot: