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

Added: /logout command

Changed: Forcing registration is now configurable, verification of IP addresses upon resuming a session is now configurable. /unregister now notifies the player if they are online.
This commit is contained in:
CypherX 2011-04-02 22:10:18 -04:00
parent fdf0548bee
commit 714bcd1e29
6 changed files with 159 additions and 34 deletions

View File

@ -27,8 +27,8 @@ public class CommandHandler
player.sendMessage(xAuth.strings.getString("register.err.disabled"));
else if (plugin.isRegistered(player.getName()))
player.sendMessage(xAuth.strings.getString("register.err.registered"));
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")));
else if (args[0].length() < xAuth.settings.getInt("security.password.min-length"))
player.sendMessage(xAuth.strings.getString("register.err.password", xAuth.settings.getInt("security.password.min-length")));
else
{
plugin.addAuth(player.getName(), args[0]);
@ -89,8 +89,8 @@ public class CommandHandler
player.sendMessage(xAuth.strings.getString("changepw.err.login"));
else if (!xAuth.settings.getBool("misc.allow-changepw"))
player.sendMessage(xAuth.strings.getString("changepw.err.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")));
else if (args[0].length() < xAuth.settings.getInt("security.password.min-length"))
player.sendMessage(xAuth.strings.getString("register.err.password", xAuth.settings.getInt("security.password.min-length")));
else
{
plugin.changePass(player.getName(), args[0]);
@ -120,8 +120,8 @@ public class CommandHandler
player.sendMessage(xAuth.strings.getString("changepw.err.login"));
else if (!xAuth.settings.getBool("misc.allow-changepw"))
player.sendMessage(xAuth.strings.getString("changepw.err.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")));
else if (args[0].length() < xAuth.settings.getInt("security.password.min-length"))
player.sendMessage(xAuth.strings.getString("register.err.password", xAuth.settings.getInt("security.password.min-length")));
else
{
plugin.changePass(player.getName(), args[0]);
@ -141,6 +141,15 @@ public class CommandHandler
else
{
plugin.removeAuth(args[0]);
Player target = plugin.getServer().getPlayer(args[0]);
if (target != null)
{
if (xAuth.settings.getBool("registration.forced"))
plugin.saveInventory(target);
target.sendMessage(xAuth.strings.getString("unregister.target"));
}
player.sendMessage(xAuth.strings.getString("unregister.success", args[0]));
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has unregistered " + args[0]);
}
@ -208,6 +217,35 @@ public class CommandHandler
player.sendMessage(xAuth.strings.getString("toggle.usage"));
}
}
else if (cmd.getName().equalsIgnoreCase("logout"))
{
//logout current player
if (args.length == 0)
plugin.killSession(player);
//logout other player
else
{
if (plugin.canUseCommand(player, "xauth.admin.logout"))
{
String target = buildName(args);
if (!plugin.sessionExists(target))
player.sendMessage(xAuth.strings.getString("logout.err.session"));
else
{
Player pTarget = plugin.getServer().getPlayer(target);
plugin.removeSession(target);
if (pTarget != null)
{
plugin.saveInventory(pTarget);
pTarget.sendMessage(xAuth.strings.getString("logout.success.ended"));
}
player.sendMessage(xAuth.strings.getString("logout.success.other", target));
}
}
}
}
}
public void handleConsoleCommand(Command cmd, String[] args)
@ -245,6 +283,15 @@ public class CommandHandler
else
{
plugin.removeAuth(args[0]);
Player target = plugin.getServer().getPlayer(args[0]);
if (target != null)
{
if (xAuth.settings.getBool("registration.forced"))
plugin.saveInventory(target);
target.sendMessage(xAuth.strings.getString("unregister.target"));
}
System.out.println(args[0] + " has been unregistered");
}
}
@ -275,5 +322,44 @@ public class CommandHandler
else
System.out.println("Correct Usage: /toggle <reg|changepw|autosave>");
}
else if (cmd.getName().equalsIgnoreCase("logout"))
{
if (args.length < 1)
System.out.println("Correct Usage: /logout <player>");
else
{
String target = buildName(args);
if (!plugin.sessionExists(target))
System.out.println("[" + pdfFile.getName() + "] This player does not have an active session.");
else
{
Player pTarget = plugin.getServer().getPlayer(target);
plugin.removeSession(target);
if (pTarget != null)
{
plugin.saveInventory(pTarget);
pTarget.sendMessage(xAuth.strings.getString("logout.success.ended"));
}
System.out.println("[" + pdfFile.getName() + "] " + target + "'s session has been terminated");
}
}
}
}
private String buildName(String[] args)
{
String s = "";
for (int i = 0; i < args.length; i++)
{
if (args[i] == null)
continue;
s += args[i] + " ";
}
return s.trim();
}
}

View File

@ -11,23 +11,26 @@ public class Settings
private static String[] keys =
{
"registration.enabled",
"registration.forced",
"misc.allow-changepw",
"misc.autosave",
"session.timeout",
"session.verifyip",
"notify.limit",
"registration.pw-min-length",
"misc.allowed-cmds",
"login.strikes.enabled",
"login.strikes.amount",
"security.filter.enabled",
"security.filter.allowed"
//"security.filter.blankname"
"security.filter.allowed",
"security.filter.blankname",
"security.password.min-length"
};
private static final String[][] keyUpdates =
{
{"misc.allow-change-pw", "misc.allow-changepw"},
{"misc.save-on-change", "misc.autosave"}
{"misc.save-on-change", "misc.autosave"},
{"registration.pw-min-length", "security.password.min-length"}
};
private static Configuration config;
@ -50,8 +53,9 @@ public class Settings
public void fillDefaults()
{
defaults.put("registration.enabled", true);
defaults.put("registration.pw-min-length", 3);
defaults.put("registration.forced", true);
defaults.put("session.timeout", 3600);
defaults.put("session.verifyip", true);
defaults.put("notify.limit", 5);
defaults.put("misc.allow-changepw", true);
defaults.put("misc.allowed-cmds", new String[]{"/register", "/login"});
@ -60,7 +64,8 @@ public class Settings
defaults.put("login.strikes.amount", 5);
defaults.put("security.filter.enabled", true);
defaults.put("security.filter.allowed", "abcdefghijklmnopqrstuvwxyz0123456789_- ()[]{}");
//defaults.put("security.filter.blankname", true);
defaults.put("security.filter.blankname", true);
defaults.put("security.password.min-length", 3);
}
public void updateKeys()
@ -118,7 +123,6 @@ 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

@ -13,9 +13,10 @@ public class Strings
"register.success1", "register.success2", "login.login", "login.usage", "login.err.registered", "login.err.logged",
"login.err.password", "login.err.kick", "login.success", "changepw.usage1", "changepw.usage2", "changepw.err.login",
"changepw.err.disabled", "changepw.err.registered", "changepw.success.self", "changepw.success.other",
"unregister.usage", "unregister.success", "reload.success", "toggle.usage", "toggle.err.permission", "toggle.success.reg",
"toggle.success.pw", "toggle.success.save", "misc.illegal", "misc.reloaded", "misc.enabled", "misc.disabled",
"misc.filterkickmsg"/*, "misc.blankkickmsg"*/
"unregister.usage", "unregister.target", "unregister.success", "reload.success", "toggle.usage", "toggle.err.permission",
"toggle.success.reg", "toggle.success.pw", "toggle.success.save", "logout.err.session", "logout.success.ended",
"logout.success.other", "misc.illegal", "misc.reloaded", "misc.enabled", "misc.disabled", "misc.filterkickmsg",
"misc.blankkickmsg"
};
private static final String[][] keyUpdates = {};
@ -64,6 +65,7 @@ public class Strings
defaults.put("changepw.success.other", "&aPassword changed.");
defaults.put("unregister.usage", "&cCorrect Usage: /unregister <player>");
defaults.put("unregister.target", "&cYou have been unregistered.");
defaults.put("unregister.success", "&a%1 has been unregistered.");
defaults.put("reload.success", "&e[xAuth] Configuration and Accounts reloaded");
@ -74,12 +76,16 @@ public class Strings
defaults.put("toggle.success.pw", "&e[xAuth] Password changes are now %1.");
defaults.put("toggle.success.save", "&e[xAuth] Autosaving of account modifications is now %1.");
defaults.put("logout.err.session", "&cThis player does not have an active session.");
defaults.put("logout.success.ended", "&cYour session has been terminated. You must log in again.");
defaults.put("logout.success.other", "&a%1's session has been terminated.");
defaults.put("misc.illegal", "&7You must be logged in to do that!");
defaults.put("misc.reloaded", "&cServer reloaded! You must log in again.");
defaults.put("misc.enabled", "enabled");
defaults.put("misc.disabled", "disabled");
defaults.put("misc.filterkickmsg", "Your name contains one or more illegal characters.");
//defaults.put("misc.blankkickmsg", "Blank names are not allowed.");
defaults.put("misc.blankkickmsg", "Blank names are not allowed.");
}
private void updateKeys()

View File

@ -1,5 +1,5 @@
//xAuth 1.1.6
//Built against Bukkit #493 and CraftBukkit #612
//xAuth 1.2
//Built against Bukkit #493 and CraftBukkit #617
package com.cypherx.xauth;
@ -86,7 +86,7 @@ public class xAuth extends JavaPlugin
}
File fDir = new File(DIR);
if (!fDir.exists())
fDir.mkdir();
@ -113,8 +113,11 @@ public class xAuth extends JavaPlugin
{
for (Player player : players)
{
saveInventory(player);
player.sendMessage(strings.getString("misc.reloaded"));
if (isRegistered(player.getName()))
{
saveInventory(player);
player.sendMessage(strings.getString("misc.reloaded"));
}
}
}
@ -189,14 +192,14 @@ public class xAuth extends JavaPlugin
{
if (!this.isEnabled())
return false;
CommandHandler cmdHandler = new CommandHandler(this);
if (sender instanceof Player)
cmdHandler.handlePlayerCommand((Player)sender, cmd, args);
else if (sender instanceof ConsoleCommandSender)
cmdHandler.handleConsoleCommand(cmd, args);
return true;
}
@ -322,6 +325,9 @@ public class xAuth extends JavaPlugin
//NOTIFY FUNCTIONS
public void handleEvent(Player player, Cancellable event)
{
if (!settings.getBool("registration.forced") && !isRegistered(player.getName()))
return;
if (!sessionExists(player.getName()))
{
event.setCancelled(true);
@ -424,7 +430,7 @@ public class xAuth extends JavaPlugin
removeSession(player.getName());
}
return false;
}
@ -433,10 +439,10 @@ public class xAuth extends JavaPlugin
Session session = sessions.get(player.getName().toLowerCase());
if (session.isExpired(new Date(session.getLoginTime() + (settings.getInt("session.timeout") * 1000))))
return false;
if (!session.isValidAddr(player.getAddress().getAddress().getHostAddress()))
if (settings.getBool("session.verifyip") && !session.isValidAddr(player.getAddress().getAddress().getHostAddress()))
return false;
return true;
}
@ -446,6 +452,18 @@ public class xAuth extends JavaPlugin
if (sessionExists(pName))
sessions.remove(pName);
}
public void killSession(Player player)
{
String pName = player.getName();
removeSession(pName);
if (player != null)
{
saveInventory(player);
player.sendMessage(strings.getString("logout.success.ended"));
}
}
//MISC FUNCTIONS
private void setupPermissions()

View File

@ -24,8 +24,8 @@ public class xAuthPlayerListener extends PlayerListener
if (xAuth.settings.getBool("security.filter.enabled") && !plugin.isNameLegal(player.getName()))
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, xAuth.strings.getString("misc.filterkickmsg"));
//if (xAuth.settings.getBool("security.filter.blankname") && player.getName().trim().equals(""))
//event.disallow(PlayerLoginEvent.Result.KICK_OTHER, xAuth.strings.getString("misc.blankkickmsg"));
if (xAuth.settings.getBool("security.filter.blankname") && player.getName().trim().equals(""))
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, xAuth.strings.getString("misc.blankkickmsg"));
}
public void onPlayerJoin(PlayerJoinEvent event)
@ -34,12 +34,18 @@ public class xAuthPlayerListener extends PlayerListener
if (!plugin.isLoggedIn(player))
{
plugin.saveInventory(player);
if (!plugin.isRegistered(player.getName()))
{
if (xAuth.settings.getBool("registration.forced"))
plugin.saveInventory(player);
player.sendMessage(xAuth.strings.getString("register.login"));
}
else
{
plugin.saveInventory(player);
player.sendMessage(xAuth.strings.getString("login.login"));
}
}
}

View File

@ -1,6 +1,6 @@
name: xAuth
main: com.cypherx.xauth.xAuth
version: 1.1.6
version: 1.2
commands:
register:
@ -25,4 +25,9 @@ commands:
usage: |
/toggle reg
/toggle changepw
/toggle autosave
/toggle autosave
logout:
description: End a players session and force them to re-authenticate
usage: |
/logout
/logout <player>