1.4r4
This commit is contained in:
parent
d62578f398
commit
0ec10b3302
10 changed files with 100 additions and 31 deletions
|
|
@ -17,38 +17,76 @@ public class GAuthBaseCommand implements CommandExecutor {
|
|||
}
|
||||
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2 && (args.length == 0 || !args[0].equals("autologin"))) {
|
||||
sender.sendMessage(ChatColor.RED + "This command requires a password.");
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /gAuth <login|register|unregister|autologin|clearcooldown> [args]");
|
||||
return false;
|
||||
} else {
|
||||
Player player = (Player) sender;
|
||||
boolean var10000;
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "login":
|
||||
var10000 = Login.subCommand(player, args[1]);
|
||||
break;
|
||||
case "register":
|
||||
var10000 = Register.subCommand(player, args[1]);
|
||||
break;
|
||||
case "unregister":
|
||||
var10000 = Unregister.subCommand(player, args[1]);
|
||||
break;
|
||||
case "autologin":
|
||||
if (!isLoggedIn(player)) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to login.");
|
||||
var10000 = false;
|
||||
} else {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
playerStats.setStat("autologin", !(Boolean) playerStats.getStat("autologin", Boolean.class));
|
||||
player.sendMessage(ChatColor.GREEN + "Toggled autologin, remember that this is considered unsafe.");
|
||||
var10000 = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
var10000 = false;
|
||||
}
|
||||
}
|
||||
|
||||
return var10000;
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "login":
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by players.");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "This command requires a password.");
|
||||
return false;
|
||||
}
|
||||
return Login.subCommand((Player) sender, args[1]);
|
||||
case "register":
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by players.");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "This command requires a password.");
|
||||
return false;
|
||||
}
|
||||
return Register.subCommand((Player) sender, args[1]);
|
||||
case "unregister":
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by players.");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "This command requires a password.");
|
||||
return false;
|
||||
}
|
||||
return Unregister.subCommand((Player) sender, args[1]);
|
||||
case "autologin":
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by players.");
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (!isLoggedIn(player)) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to login.");
|
||||
return false;
|
||||
} else {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
playerStats.setStat("autologin", !(Boolean) playerStats.getStat("autologin", Boolean.class));
|
||||
player.sendMessage(ChatColor.GREEN + "Toggled autologin, remember that this is considered unsafe.");
|
||||
return true;
|
||||
}
|
||||
case "clearcooldown":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /gAuth clearcooldown <player>");
|
||||
return false;
|
||||
}
|
||||
Player target = GrimmsServer.instance.getServer().getPlayer(args[1]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Player not found.");
|
||||
return false;
|
||||
}
|
||||
String playerKey = target.getUniqueId() + "-login";
|
||||
PerSessionDataStorage.softSave(0, Integer.class, playerKey + "-attempts");
|
||||
PerSessionDataStorage.softSave(null, Long.class, playerKey + "-cooldown");
|
||||
PerSessionDataStorage.softSave(1, Integer.class, playerKey + "-multiplier");
|
||||
sender.sendMessage(ChatColor.GREEN + "Cleared login cooldown for " + target.getName());
|
||||
return true;
|
||||
default:
|
||||
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Usage: /gAuth <login|register|unregister|autologin|clearcooldown> [args]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.gsdistance.grimmsServer.Commands.GAuthCommand;
|
|||
import com.google.common.hash.Hashing;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Data.PerSessionDataStorage;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -16,13 +17,43 @@ public class Login {
|
|||
player.sendMessage(ChatColor.YELLOW + "Already logged in.");
|
||||
return true;
|
||||
} else {
|
||||
String playerKey = player.getUniqueId() + "-login";
|
||||
|
||||
Long cooldownEnd = PerSessionDataStorage.getData(playerKey + "-cooldown", Long.class);
|
||||
if (cooldownEnd != null && System.currentTimeMillis() < cooldownEnd) {
|
||||
long remainingSeconds = (cooldownEnd - System.currentTimeMillis()) / 1000;
|
||||
player.sendMessage(ChatColor.RED + "You must wait " + remainingSeconds + " seconds before trying again.");
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
if (Hashing.sha256().hashString(pass, StandardCharsets.UTF_8).toString().equals(playerStats.getStat("pass", String.class))) {
|
||||
GAuthBaseCommand.login(player, true);
|
||||
PerSessionDataStorage.softSave(0, Integer.class, playerKey + "-attempts");
|
||||
PerSessionDataStorage.softSave(null, Long.class, playerKey + "-cooldown");
|
||||
player.sendMessage(ChatColor.GREEN + "Logged in.");
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Failed to login.");
|
||||
Integer failedAttempts = PerSessionDataStorage.getData(playerKey + "-attempts", Integer.class);
|
||||
if (failedAttempts == null) failedAttempts = 0;
|
||||
failedAttempts++;
|
||||
PerSessionDataStorage.softSave(failedAttempts, Integer.class, playerKey + "-attempts");
|
||||
|
||||
if (failedAttempts >= 3) {
|
||||
Integer cooldownMultiplier = PerSessionDataStorage.getData(playerKey + "-multiplier", Integer.class);
|
||||
if (cooldownMultiplier == null) cooldownMultiplier = 1;
|
||||
|
||||
long cooldownMillis = 60000L * cooldownMultiplier;
|
||||
cooldownEnd = System.currentTimeMillis() + cooldownMillis;
|
||||
PerSessionDataStorage.softSave(cooldownEnd, Long.class, playerKey + "-cooldown");
|
||||
PerSessionDataStorage.softSave(cooldownMultiplier * 2, Integer.class, playerKey + "-multiplier");
|
||||
PerSessionDataStorage.softSave(0, Integer.class, playerKey + "-attempts");
|
||||
|
||||
player.kickPlayer(ChatColor.RED + "Too many failed login attempts. Wait " + (cooldownMillis / 60000) + " minute(s) before rejoining.");
|
||||
return false;
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.RED + "Failed to login. Attempts: " + failedAttempts + "/3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue