1.4r4
This commit is contained in:
parent
d62578f398
commit
0ec10b3302
10 changed files with 100 additions and 31 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -17,38 +17,76 @@ public class GAuthBaseCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
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"))) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage(ChatColor.RED + "This command requires a password.");
|
sender.sendMessage(ChatColor.RED + "Usage: /gAuth <login|register|unregister|autologin|clearcooldown> [args]");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
Player player = (Player) sender;
|
|
||||||
boolean var10000;
|
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "login":
|
case "login":
|
||||||
var10000 = Login.subCommand(player, args[1]);
|
if (!(sender instanceof Player)) {
|
||||||
break;
|
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":
|
case "register":
|
||||||
var10000 = Register.subCommand(player, args[1]);
|
if (!(sender instanceof Player)) {
|
||||||
break;
|
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":
|
case "unregister":
|
||||||
var10000 = Unregister.subCommand(player, args[1]);
|
if (!(sender instanceof Player)) {
|
||||||
break;
|
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":
|
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)) {
|
if (!isLoggedIn(player)) {
|
||||||
player.sendMessage(ChatColor.RED + "Failed to login.");
|
player.sendMessage(ChatColor.RED + "Failed to login.");
|
||||||
var10000 = false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||||
playerStats.setStat("autologin", !(Boolean) playerStats.getStat("autologin", Boolean.class));
|
playerStats.setStat("autologin", !(Boolean) playerStats.getStat("autologin", Boolean.class));
|
||||||
player.sendMessage(ChatColor.GREEN + "Toggled autologin, remember that this is considered unsafe.");
|
player.sendMessage(ChatColor.GREEN + "Toggled autologin, remember that this is considered unsafe.");
|
||||||
var10000 = true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
var10000 = false;
|
sender.sendMessage(ChatColor.RED + "Unknown subcommand. Usage: /gAuth <login|register|unregister|autologin|clearcooldown> [args]");
|
||||||
}
|
return false;
|
||||||
|
|
||||||
return var10000;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package org.gsdistance.grimmsServer.Commands.GAuthCommand;
|
||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.gsdistance.grimmsServer.Data.PerSessionDataStorage;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
@ -16,13 +17,43 @@ public class Login {
|
||||||
player.sendMessage(ChatColor.YELLOW + "Already logged in.");
|
player.sendMessage(ChatColor.YELLOW + "Already logged in.");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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);
|
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||||
if (Hashing.sha256().hashString(pass, StandardCharsets.UTF_8).toString().equals(playerStats.getStat("pass", String.class))) {
|
if (Hashing.sha256().hashString(pass, StandardCharsets.UTF_8).toString().equals(playerStats.getStat("pass", String.class))) {
|
||||||
GAuthBaseCommand.login(player, true);
|
GAuthBaseCommand.login(player, true);
|
||||||
|
PerSessionDataStorage.softSave(0, Integer.class, playerKey + "-attempts");
|
||||||
|
PerSessionDataStorage.softSave(null, Long.class, playerKey + "-cooldown");
|
||||||
player.sendMessage(ChatColor.GREEN + "Logged in.");
|
player.sendMessage(ChatColor.GREEN + "Logged in.");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue