1
0
mirror of https://github.com/moparisthebest/xAuth synced 2024-12-22 07:08:51 -05:00

Release version 1.1.4

This commit is contained in:
CypherX 2011-03-26 22:41:40 -04:00
parent 5cca44837b
commit 721739abca
5 changed files with 64 additions and 50 deletions

View File

@ -1,9 +1,10 @@
package com.cypherx.xauth;
//import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.craftbukkit.CraftServer;
public class CommandHandler
{
@ -41,25 +42,35 @@ public class CommandHandler
{
if (args.length != 1)
player.sendMessage(xAuth.strings.getString("login.usage"));
//player.sendMessage(ChatColor.RED + "Correct Usage: /login <password>");
else if (!plugin.isRegistered(player.getName()))
player.sendMessage(xAuth.strings.getString("login.err.registered"));
//player.sendMessage(ChatColor.RED + "You are not registered.");
else if (plugin.sessionExists(player.getName()))
player.sendMessage(xAuth.strings.getString("login.err.logged"));
//player.sendMessage(ChatColor.RED + "You are already logged in.");
else
{
if (plugin.checkPass(player, args[0]))
{
plugin.clearStrikes(player);
plugin.login(player);
player.sendMessage(xAuth.strings.getString("login.success"));
//player.sendMessage(ChatColor.GREEN + "You are now logged in.");
System.out.println("[" + pdfFile.getName() + "] Player '" + player.getName() + "' has authenticated");
}
else
player.sendMessage(xAuth.strings.getString("login.err.password"));
//player.sendMessage(ChatColor.RED + "Incorrect password!");
{
plugin.addStrike(player);
if (plugin.getStrikes(player) >= xAuth.settings.getInt("login.strikes.amount"))
{
String addr = player.getAddress().getAddress().getHostAddress();
Server server = plugin.getServer();
server.dispatchCommand(((CraftServer)server).getServer().console, "ban-ip " + addr);
server.dispatchCommand(((CraftServer)server).getServer().console, "kick " + player.getName());
plugin.clearStrikes(player);
System.out.println("[" + pdfFile.getName() + "] " + addr + " banned by Strike system");
}
else
player.sendMessage(xAuth.strings.getString("login.err.password"));
}
}
}
else if (cmd.getName().equalsIgnoreCase("changepw"))
@ -70,18 +81,14 @@ public class CommandHandler
{
if (!plugin.sessionExists(player.getName()))
player.sendMessage(xAuth.strings.getString("changepw.err.login"));
//player.sendMessage(ChatColor.RED + "You must login before changing your password!");
else if (!xAuth.settings.getBool("misc.allow-changepw"))
player.sendMessage(xAuth.strings.getString("changepw.err.disabled"));
//player.sendMessage(ChatColor.RED + "Password changes are currently disabled.");
else if (args[0].length() < xAuth.settings.getInt("registration.pw-min-length"))
player.sendMessage(xAuth.strings.getString("register.err.password", xAuth.settings.getInt("registration.pw-min-length")));
//player.sendMessage(ChatColor.RED + "Your password must contain " + xAuth.settings.getInt("registration.pw-min-length") + " or more characters.");
else
{
plugin.changePass(player.getName(), args[0]);
player.sendMessage(xAuth.strings.getString("changepw.success.self", args[0]));
//player.sendMessage(ChatColor.GREEN + "Your password has been changed to: " + ChatColor.WHITE + args[0]);
System.out.println("[" + pdfFile.getName() + "] Player '" + player.getName() + "' has changed their password");
}
}
@ -89,38 +96,30 @@ public class CommandHandler
{
if (!plugin.isRegistered(args[0]))
player.sendMessage(xAuth.strings.getString("changepw.err.registered"));
//player.sendMessage(ChatColor.RED + "This player is not registered");
else
{
plugin.changePass(args[0], args[1]);
player.sendMessage(xAuth.strings.getString("changepw.success.other"));
//player.sendMessage(ChatColor.GREEN + args[0] + "'s password has been changed to: " + ChatColor.WHITE + args[1]);
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has changed " + args[0] + "'s password");
}
}
else
player.sendMessage(xAuth.strings.getString("changepw.usage2"));
//player.sendMessage(ChatColor.RED + "Correct usage: /changepw [player] <newpassword>");
}
else
{
if (args.length != 1)
player.sendMessage(xAuth.strings.getString("changepw.usage1"));
//player.sendMessage(ChatColor.RED + "Correct Usage: /changepw <newpassword>");
else if (!plugin.sessionExists(player.getName()))
player.sendMessage(xAuth.strings.getString("changepw.err.login"));
//player.sendMessage(ChatColor.RED + "You must login before changing your password!");
else if (!xAuth.settings.getBool("misc.allow-changepw"))
player.sendMessage(xAuth.strings.getString("changepw.err.disabled"));
//player.sendMessage(ChatColor.RED + "Password changes are currently disabled.");
else if (args[0].length() < xAuth.settings.getInt("registration.pw-min-length"))
player.sendMessage(xAuth.strings.getString("register.err.password", xAuth.settings.getInt("registration.pw-min-length")));
//player.sendMessage(ChatColor.RED + "Your password must contain " + xAuth.settings.getInt("registration.pw-min-length") + " or more characters.");
else
{
plugin.changePass(player.getName(), args[0]);
player.sendMessage(xAuth.strings.getString("changepw.success.self", args[0]));
//player.sendMessage(ChatColor.GREEN + "Your password has been changed to: " + ChatColor.WHITE + args[0]);
System.out.println("[" + pdfFile.getName() + "] Player '" + player.getName() + "' has changed their password");
}
}
@ -131,15 +130,12 @@ public class CommandHandler
{
if (args.length != 1)
player.sendMessage(xAuth.strings.getString("unregister.usage"));
//player.sendMessage(ChatColor.RED + "Correct Usage: /unregister <player>");
else if (!plugin.isRegistered(args[0]))
player.sendMessage(xAuth.strings.getString("changepw.err.registered"));
//player.sendMessage(ChatColor.RED + "This player is not registered!");
else
{
plugin.removeAuth(args[0]);
player.sendMessage(xAuth.strings.getString("unregister.success", args[0]));
//player.sendMessage(ChatColor.GREEN + args[0] + " has been unregistered.");
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has unregistered " + args[0]);
}
}
@ -150,7 +146,6 @@ public class CommandHandler
{
plugin.reload();
player.sendMessage(xAuth.strings.getString("reload.success"));
//player.sendMessage(ChatColor.YELLOW + "[" + pdfFile.getName() + "] Configuration & Accounts reloaded");
}
}
else if (cmd.getName().equalsIgnoreCase("toggle"))
@ -163,19 +158,16 @@ public class CommandHandler
{
if (args.length != 1)
player.sendMessage(xAuth.strings.getString("toggle.usage"));
//player.sendMessage(ChatColor.RED + "Correct Usage: /toggle <reg|changepw|autosave>");
else if (args[0].equalsIgnoreCase("reg"))
{
if (!canToggleReg)
player.sendMessage(xAuth.strings.getString("toggle.err.permission"));
//player.sendMessage(ChatColor.RED + "You aren't allow to toggle that!");
else
{
Boolean b = xAuth.settings.getBool("registration.enabled");
xAuth.settings.updateValue("registration.enabled", (b ? false : true));
player.sendMessage(xAuth.strings.getString("toggle.success.reg",
(b ? xAuth.strings.getString("misc.disabled") : xAuth.strings.getString("misc.enabled"))));
//player.sendMessage(ChatColor.YELLOW + "[" + pdfFile.getName() + "] Registrations are now " + (b ? "disabled." : "enabled."));
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has " + (b ? "disabled" : "enabled") + " registrations");
}
@ -184,14 +176,12 @@ public class CommandHandler
{
if (!canTogglePw)
player.sendMessage(xAuth.strings.getString("toggle.err.permission"));
//player.sendMessage(ChatColor.RED + "You aren't allow to toggle that!");
else
{
Boolean b = xAuth.settings.getBool("misc.allow-changepw");
xAuth.settings.updateValue("misc.allow-changepw", (b ? false : true));
player.sendMessage(xAuth.strings.getString("toggle.success.pw",
(b ? xAuth.strings.getString("misc.disabled") : xAuth.strings.getString("misc.enabled"))));
//player.sendMessage(ChatColor.YELLOW + "[" + pdfFile.getName() + "] Password changes are now " + (b ? "disabled." : "enabled."));
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has " + (b ? "disabled" : "enabled") + " password changes");
}
}
@ -199,20 +189,17 @@ public class CommandHandler
{
if (!canToggleSave)
player.sendMessage(xAuth.strings.getString("toggle.err.permission"));
//player.sendMessage(ChatColor.RED + "You aren't allow to toggle that!");
else
{
Boolean b = xAuth.settings.getBool("misc.autosave");
xAuth.settings.updateValue("misc.autosave", (b ? false : true));
player.sendMessage(xAuth.strings.getString("toggle.success.save",
(b ? xAuth.strings.getString("misc.disabled") : xAuth.strings.getString("misc.enabled"))));
//player.sendMessage(ChatColor.YELLOW + "[" + pdfFile.getName() + "] Autosaving of account modifications is now " + (b ? "disabled." : "enabled."));
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has " + (b ? "disabled" : "enabled") + " autosave");
}
}
else
player.sendMessage(xAuth.strings.getString("toggle.usage"));
//player.sendMessage(ChatColor.RED + "Correct Usage: /toggle <reg|changepw|autosave>");
}
}
}

View File

@ -16,7 +16,9 @@ public class Settings
"session.timeout",
"notify.limit",
"registration.pw-min-length",
"misc.allowed-cmds"
"misc.allowed-cmds",
"login.strikes.enabled",
"login.strikes.amount",
};
private static final String[][] keyUpdates =
@ -51,6 +53,8 @@ public class Settings
defaults.put("misc.allow-changepw", true);
defaults.put("misc.allowed-cmds", new String[]{"/register", "/login"});
defaults.put("misc.autosave", true);
defaults.put("login.strikes.enabled", true);
defaults.put("login.strikes.amount", 5);
}
public void updateKeys()
@ -100,6 +104,7 @@ public class Settings
@SuppressWarnings("unchecked")
public List<String> getStrList(String key)
{
//List<String> cmds = (List<String>)settings.get(key);
return (List<String>)settings.get(key);
}
}

View File

@ -1,3 +1,6 @@
//xAuth 1.1.4
//Built against Bukkit #461 and CraftBukkit #556
package com.cypherx.xauth;
import java.io.*;
@ -8,7 +11,6 @@ import java.util.Date;
import java.util.HashMap;
import net.minecraft.server.PropertyManager;
//import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
@ -41,27 +43,28 @@ public class xAuth extends JavaPlugin
private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
private static PluginDescriptionFile pdfFile;
//private static final String DIR = "plugins/xAuth/";
private static final String DIR = "plugins" + File.separator + "xAuth" + File.separator;
private static final String CONFIG_FILE = "config.yml";
private static final String STRINGS_FILE = "strings.yml";
private static final String AUTH_FILE = "auths.txt";
public static Settings settings;
public static Strings strings;
public static PermissionHandler Permissions;
//autosave test code
private static Boolean fullyEnabled = false;
private static Boolean fullyEnabled;
private ConcurrentHashMap<String, String> auths = new ConcurrentHashMap<String, String>();
private ConcurrentHashMap<Player, ItemStack[]> inventory = new ConcurrentHashMap<Player, ItemStack[]>();
private ConcurrentHashMap<Player, ItemStack[]> armor = new ConcurrentHashMap<Player, ItemStack[]>();
private ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<String, Session>();
private ConcurrentHashMap<Player, Date> lastNotifyTimes = new ConcurrentHashMap<Player, Date>();
private ConcurrentHashMap<String, Integer> strikes = new ConcurrentHashMap<String, Integer>();
public void onEnable()
{
fullyEnabled = false;
pdfFile = this.getDescription();
/*Whirlpool w = new Whirlpool();
@ -110,13 +113,12 @@ public class xAuth extends JavaPlugin
{
saveInventory(player);
player.sendMessage(strings.getString("misc.reloaded"));
//player.sendMessage(ChatColor.RED + "Server reloaded! You must log in again.");
}
}
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Lowest, this);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_ITEM, playerListener, Event.Priority.Highest, this);
@ -125,7 +127,6 @@ public class xAuth extends JavaPlugin
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Lowest, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
//pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Highest, this);
pm.registerEvent(Event.Type.BLOCK_INTERACT, blockListener, Priority.Highest, this);
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Highest, this);
@ -282,6 +283,35 @@ public class xAuth extends JavaPlugin
else
restoreInventory(player);
}
public void addStrike(Player player)
{
String addr = player.getAddress().getAddress().getHostAddress();
int newCount = 1;
if (strikes.containsKey(addr))
{
newCount = strikes.get(addr) + 1;
strikes.remove(addr);
}
strikes.put(addr, newCount);
}
public int getStrikes(Player player)
{
String addr = player.getAddress().getAddress().getHostAddress();
if (!strikes.containsKey(addr))
return 0;
return strikes.get(addr);
}
public void clearStrikes(Player player)
{
String addr = player.getAddress().getAddress().getHostAddress();
strikes.remove(addr);
}
//NOTIFY FUNCTIONS
public void handleEvent(Player player, Cancellable event)
@ -318,7 +348,6 @@ public class xAuth extends JavaPlugin
public void notifyPlayer(Player player)
{
player.sendMessage(strings.getString("misc.illegal"));
//player.sendMessage(ChatColor.GRAY + "You must be logged in to do that!");
updateNotifyTime(player, new Date());
}

View File

@ -26,13 +26,6 @@ public class xAuthBlockListener extends BlockListener
plugin.handleEvent(player, event);
}
//Prevents player from damaging a block
/*public void onBlockDamage(BlockDamageEvent event)
{
Player player = event.getPlayer();
plugin.handleEvent(player, event);
}*/
//Prevents player from using switches, buttons, etc.
public void onBlockInteract(BlockInteractEvent event)
{

View File

@ -2,7 +2,6 @@ package com.cypherx.xauth;
import org.bukkit.entity.Player;
import org.bukkit.event.player.*;
//import org.bukkit.ChatColor;
/**
* Handle events for all Player related events
@ -27,10 +26,8 @@ public class xAuthPlayerListener extends PlayerListener
if (!plugin.isRegistered(player.getName()))
player.sendMessage(xAuth.strings.getString("register.login"));
//player.sendMessage(ChatColor.RED + "You are not registered. Please register using /register <password>.");
else
player.sendMessage(xAuth.strings.getString("login.login"));
//player.sendMessage(ChatColor.RED + "Please log in using /login <password>.");
}
}
@ -49,7 +46,10 @@ public class xAuthPlayerListener extends PlayerListener
String[] msg = event.getMessage().split(" ");
if (!plugin.isCmdAllowed(msg[0]))
{
plugin.handleEvent(player, event);
event.setMessage("/");
}
}
//Prevents player from being able to chat