Update 3.3.2

//Changes 3.3.2://
* Fix Vault support
* Fix Group permission problems
* Rewrite /register and /login command, would be much faster
* Fix useWelcomeMessage
* Add a way to broadcast welcome message
* Remove Join/Quit message only if enableProtection is true
* Fix /login and /register requested at the same time
* Some other fixes
This commit is contained in:
Xephi 2014-02-10 02:46:51 +01:00
parent fec466dd29
commit 46acf9d74b
24 changed files with 898 additions and 791 deletions

View File

@ -24,7 +24,7 @@
</plugin>
</plugins>
</build>
<version>3.3.2-DEV-1</version>
<version>3.3.2</version>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>

View File

@ -65,6 +65,7 @@ import fr.xephi.authme.plugin.manager.BungeeCordMessage;
import fr.xephi.authme.plugin.manager.CitizensCommunicator;
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import fr.xephi.authme.plugin.manager.EssSpawn;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings;
@ -79,7 +80,7 @@ public class AuthMe extends JavaPlugin {
public DataSource database = null;
private Settings settings;
private Messages m;
private PlayersLogs pllog;
public PlayersLogs pllog;
public static Server server;
public static Logger authmeLogger = Logger.getLogger("AuthMe");
public static AuthMe authme;
@ -135,11 +136,13 @@ public class AuthMe extends JavaPlugin {
m = Messages.getInstance();
setMessages(Messages.getInstance());
pllog = PlayersLogs.getInstance();
server = getServer();
//Find Permissions
checkVault();
//Set Console Filter
if (Settings.removePassword) {
this.getLogger().setFilter(new ConsoleFilter());
@ -293,11 +296,8 @@ public class AuthMe extends JavaPlugin {
ConsoleLogger.info("Successfully hook with ChestShop!");
}
//Find Permissions
checkVault();
this.getCommand("authme").setExecutor(new AdminCommand(this, database));
this.getCommand("register").setExecutor(new RegisterCommand(database, this));
this.getCommand("register").setExecutor(new RegisterCommand(this));
this.getCommand("login").setExecutor(new LoginCommand(this));
this.getCommand("changepassword").setExecutor(new ChangePasswordCommand(database, this));
this.getCommand("logout").setExecutor(new LogoutCommand(this,database));
@ -355,8 +355,7 @@ public class AuthMe extends JavaPlugin {
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
ConsoleLogger.info("Vault plugin detected, hook with " + permission.getName() + " system");
}
else {
} else {
ConsoleLogger.showError("Vault plugin is detected but not the permissions plugin!");
}
} else {
@ -483,7 +482,7 @@ public class AuthMe extends JavaPlugin {
@Override
public void onDisable() {
if (Bukkit.getOnlinePlayers() != null)
if (Bukkit.getOnlinePlayers().length != 0)
for(Player player : Bukkit.getOnlinePlayers()) {
this.savePlayer(player);
}
@ -538,15 +537,9 @@ public class AuthMe extends JavaPlugin {
} catch (Exception e) { }
try {
String name = player.getName().toLowerCase();
if ((PlayerCache.getInstance().isAuthenticated(name)) && (!player.isDead()) &&
(Settings.isSaveQuitLocationEnabled.booleanValue())) {
final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), (int)player.getLocation().getX(), (int)player.getLocation().getY(), (int)player.getLocation().getZ(), player.getWorld().getName());
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
database.updateQuitLoc(auth);
}
});
if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead() && Settings.isSaveQuitLocationEnabled) {
final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getWorld().getName());
database.updateQuitLoc(auth);
}
if (LimboCache.getInstance().hasLimboPlayer(name))
{
@ -820,16 +813,18 @@ public class AuthMe extends JavaPlugin {
}
public String replaceAllInfos(String message, Player player) {
message = message.replace("&", "\u00a7");
message = message.replace("{PLAYER}", player.getName());
message = message.replace("{ONLINE}", ""+this.getServer().getOnlinePlayers().length);
message = message.replace("{MAXPLAYERS}", ""+this.getServer().getMaxPlayers());
message = message.replace("{IP}", player.getAddress().getAddress().getHostAddress());
message = message.replace("{LOGINS}", ""+PlayerCache.getInstance().getLogged());
message = message.replace("{WORLD}", player.getWorld().getName());
message = message.replace("{SERVER}", this.getServer().getServerName());
message = message.replace("{VERSION}", this.getServer().getBukkitVersion());
message = message.replace("{COUNTRY}", this.getCountryName(player.getAddress().getAddress()));
try {
message = message.replace("&", "\u00a7");
message = message.replace("{PLAYER}", player.getName());
message = message.replace("{ONLINE}", ""+this.getServer().getOnlinePlayers().length);
message = message.replace("{MAXPLAYERS}", ""+this.getServer().getMaxPlayers());
message = message.replace("{IP}", player.getAddress().getAddress().getHostAddress());
message = message.replace("{LOGINS}", ""+PlayerCache.getInstance().getLogged());
message = message.replace("{WORLD}", player.getWorld().getName());
message = message.replace("{SERVER}", this.getServer().getServerName());
message = message.replace("{VERSION}", this.getServer().getBukkitVersion());
message = message.replace("{COUNTRY}", this.getCountryName(player.getAddress().getAddress()));
} catch (Exception e) {}
return message;
}
}

View File

@ -19,7 +19,7 @@ public class ConsoleLogger {
public static void info(String message) {
if (AuthMe.getInstance().isEnabled()) {
log.info(message);
log.info("[AuthMe] " + message);
if (Settings.useLogging) {
Calendar date = Calendar.getInstance();
final String actually = "[" + DateFormat.getDateInstance().format(date.getTime()) + ", " + date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE) + ":" + date.get(Calendar.SECOND) + "] " + message;
@ -35,7 +35,7 @@ public class ConsoleLogger {
public static void showError(String message) {
if (AuthMe.getInstance().isEnabled()) {
log.warning(" ERROR: " + message);
log.warning("[AuthMe] ERROR: " + message);
if (Settings.useLogging) {
Calendar date = Calendar.getInstance();
final String actually = "[" + DateFormat.getDateInstance().format(date.getTime()) + ", " + date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE) + ":" + date.get(Calendar.SECOND) + "] ERROR : " + message;

View File

@ -1,472 +0,0 @@
package fr.xephi.authme;
import java.util.Date;
import java.util.List;
import me.muizers.Notifications.Notification;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import fr.xephi.authme.Utils.groupType;
import fr.xephi.authme.api.API;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.backup.FileCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings;
/**
*
* @authors Xephi59, <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
*
*/
public class Management extends Thread {
private Messages m = Messages.getInstance();
private PlayersLogs pllog = PlayersLogs.getInstance();
private Utils utils = Utils.getInstance();
private FileCache playerCache = new FileCache();
private DataSource database;
public AuthMe plugin;
public static RandomString rdm = new RandomString(Settings.captchaLength);
public PluginManager pm;
public Management(DataSource database, AuthMe plugin) {
this.database = database;
this.plugin = plugin;
this.pm = plugin.getServer().getPluginManager();
}
public void run() {
}
public void performLogin(final Player player, final String password, final boolean passpartu, final boolean forceLogin) {
if (passpartu) {
// Passpartu-Login Bypasses Password-Authentication.
new AsyncronousPasspartuLogin(player).pass();
} else {
new AsyncronousLogin(player, password, forceLogin).process();
}
}
class AsyncronousLogin {
protected Player player;
protected String name;
protected String password;
protected String realName;
protected boolean forceLogin;
public AsyncronousLogin(Player player, String password, boolean forceLogin) {
this.player = player;
this.password = password;
name = player.getName().toLowerCase();
realName = player.getName();
this.forceLogin = forceLogin;
}
protected String getIP() {
String ip = player.getAddress().getAddress().getHostAddress();
if (Settings.bungee) {
if (plugin.realIp.containsKey(name))
ip = plugin.realIp.get(name);
}
return ip;
}
protected boolean needsCaptcha() {
if (Settings.useCaptcha) {
if (!plugin.captcha.containsKey(name)) {
plugin.captcha.put(name, 1);
} else {
int i = plugin.captcha.get(name) + 1;
plugin.captcha.remove(name);
plugin.captcha.put(name, i);
}
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
plugin.cap.put(name, rdm.nextString());
for (String s : m._("need_captcha")) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
}
return true;
} else if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
try {
plugin.captcha.remove(name);
plugin.cap.remove(name);
} catch (NullPointerException npe) {
}
}
}
return false;
}
/**
* Checks the precondition for authentication (like user known) and returns the playerAuth-State
*/
protected PlayerAuth preAuth() {
if (PlayerCache.getInstance().isAuthenticated(name)) {
m._(player, "logged_in");
return null;
}
if (!database.isAuthAvailable(name)) {
m._(player, "user_unknown");
return null;
}
PlayerAuth pAuth = database.getAuth(name);
if (pAuth == null) {
m._(player, "user_unknown");
return null;
}
if (!Settings.getMySQLColumnGroup.isEmpty() && pAuth.getGroupId() == Settings.getNonActivatedGroup) {
m._(player, "vb_nonActiv");
return null;
}
return pAuth;
}
protected void process() {
PlayerAuth pAuth = preAuth();
if (pAuth == null || needsCaptcha())
return;
String hash = pAuth.getHash();
String email = pAuth.getEmail();
boolean passwordVerified = true;
if (!forceLogin)
try {
passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, name);
} catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage());
m._(player, "error");
return;
}
if (passwordVerified && player.isOnline()) {
PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName);
database.updateSession(auth);
pllog.addPlayer(player);
if (Settings.useCaptcha) {
if (plugin.captcha.containsKey(name)) {
plugin.captcha.remove(name);
}
if (plugin.cap.containsKey(name)) {
plugin.cap.remove(name);
}
}
player.setNoDamageTicks(0);
m._(player, "login");
displayOtherAccounts(auth);
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " logged in!");
if (plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " logged in!"));
}
// makes player isLoggedin via API
PlayerCache.getInstance().addPlayer(auth);
// As the scheduling executes the Task most likely after the current task, we schedule it in the end
// so that we can be sure, and have not to care if it might be processed in other order.
ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player);
if (syncronousPlayerLogin.getLimbo() != null) {
player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getTimeoutTaskId());
player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getMessageTaskId());
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin);
} else if (player.isOnline()) {
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " used the wrong password");
if (Settings.isKickOnWrongPasswordEnabled) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (AuthMePlayerListener.gameMode != null && AuthMePlayerListener.gameMode.containsKey(name)) {
player.setGameMode(AuthMePlayerListener.gameMode.get(name));
}
player.kickPlayer(m._("wrong_pwd")[0]);
}
});
} else {
m._(player, "wrong_pwd");
return;
}
} else {
ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... ");
}
}
}
class AsyncronousPasspartuLogin extends AsyncronousLogin {
public AsyncronousPasspartuLogin(Player player) {
super(player, null, false);
}
public void pass() {
PlayerAuth pAuth = preAuth();
if (pAuth == null)
return;
String hash = pAuth.getHash();
String email = pAuth.getEmail();
PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName);
database.updateSession(auth);
pllog.addPlayer(player);
if (Settings.useCaptcha) {
if (plugin.captcha.containsKey(name)) {
plugin.captcha.remove(name);
}
if (plugin.cap.containsKey(name)) {
plugin.cap.remove(name);
}
}
player.setNoDamageTicks(0);
m._(player, "login");
displayOtherAccounts(auth);
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " logged in!");
if (plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " logged in!"));
}
// makes player isLoggedin via API
PlayerCache.getInstance().addPlayer(auth);
// As the scheduling executes the Task most likely after the current task, we schedule it in the end
// so that we can be sure, and have not to care if it might be processed in other order.
ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player);
if (syncronousPlayerLogin.getLimbo() != null) {
player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getTimeoutTaskId());
player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getMessageTaskId());
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin);
}
}
class ProcessSyncronousPlayerLogin implements Runnable {
private LimboPlayer limbo;
private Player player;
private String name;
private PlayerAuth auth;
public ProcessSyncronousPlayerLogin(Player player) {
this.player = player;
this.name = player.getName().toLowerCase();
this.limbo = LimboCache.getInstance().getLimboPlayer(name);
this.auth = database.getAuth(name);
}
public LimboPlayer getLimbo() {
return limbo;
}
protected void restoreOpState() {
player.setOp(limbo.getOperator());
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(limbo.isFlying());
player.setFlying(limbo.isFlying());
}
}
protected void packQuitLocation() {
utils.packCoords(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), player);
}
protected void teleportBackFromSpawn() {
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limbo.getLoc());
pm.callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
Location fLoc = tpEvent.getTo();
if (!fLoc.getChunk().isLoaded()) {
fLoc.getChunk().load();
}
player.teleport(fLoc);
}
}
protected void teleportToSpawn() {
Location spawnL = plugin.getSpawnLocation(player.getWorld());
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true);
pm.callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
Location fLoc = tpEvent.getTo();
if (!fLoc.getChunk().isLoaded()) {
fLoc.getChunk().load();
}
player.teleport(fLoc);
}
}
protected void restoreInventory() {
RestoreInventoryEvent event = new RestoreInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
API.setPlayerInventory(player, event.getInventory(), event.getArmor());
}
}
protected void forceCommands() {
for (String command : Settings.forceCommands) {
try {
player.performCommand(command.replace("%p", player.getName()));
} catch (Exception e) {}
}
}
@Override
public void run() {
// Limbo contains the State of the Player before /login
if (limbo != null) {
// Op & Flying
restoreOpState();
/*
* Restore Inventories and GameMode
* We need to restore them before teleport the player
* Cause in AuthMePlayerListener, we call ProtectInventoryEvent after Teleporting
* Also it's the current world inventory !
*/
if (!Settings.forceOnlyAfterLogin) {
player.setGameMode(limbo.getGameMode());
// Inventory - Make it after restore GameMode , cause we need to restore the
// right inventory in the right gamemode
if (Settings.protectInventoryBeforeLogInEnabled && player.hasPlayedBefore()) {
restoreInventory();
}
}
else {
// Inventory - Make it before force the survival GameMode to cancel all
// inventory problem
if (Settings.protectInventoryBeforeLogInEnabled && player.hasPlayedBefore()) {
restoreInventory();
}
player.setGameMode(GameMode.SURVIVAL);
}
// Teleport the player
if(Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
// If we have force the spawn location on join
teleportToSpawn();
} else {
if (Settings.isTeleportToSpawnEnabled) {
// If and only if teleport unauthed to spawn is activate
teleportBackFromSpawn();
} else {
if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
// Teleport the player on the saved location
packQuitLocation();
} else {
// Do not move the player from his position
}
}
}
// Teleport
if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
packQuitLocation();
} else {
teleportBackFromSpawn();
}
} else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
teleportToSpawn();
} else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
packQuitLocation();
} else {
teleportBackFromSpawn();
}
// Re-Force Survival GameMode if we need due to world change specification
if (Settings.isForceSurvivalModeEnabled)
Utils.forceGM(player);
// Restore Permission Group
utils.setGroup(player, groupType.LOGGEDIN);
// Cleanup no longer used temporary data
LimboCache.getInstance().deleteLimboPlayer(name);
if (playerCache.doesCacheExist(name)) {
playerCache.removeCache(name);
}
}
// We can now display the join message
if (AuthMePlayerListener.joinMessage.containsKey(name) && AuthMePlayerListener.joinMessage.get(name) != null && !AuthMePlayerListener.joinMessage.get(name).isEmpty()) {
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (p.isOnline())
p.sendMessage(AuthMePlayerListener.joinMessage.get(name));
}
AuthMePlayerListener.joinMessage.remove(name);
}
// The Loginevent now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData();
// Login is finish, display welcome message
if(Settings.useWelcomeMessage)
if(Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) {
Bukkit.getServer().broadcastMessage(s);
}
} else {
for (String s : Settings.welcomeMsg) {
player.sendMessage(plugin.replaceAllInfos(s, player));
}
}
// Login is now finish , we can force all commands
forceCommands();
}
}
private void displayOtherAccounts(PlayerAuth auth) {
if (!Settings.displayOtherAccounts) {
return;
}
if (auth == null) {
return;
}
if (this.database.getAllAuthsByName(auth).isEmpty() || this.database.getAllAuthsByName(auth) == null) {
return;
}
if (this.database.getAllAuthsByName(auth).size() == 1) {
return;
}
List<String> accountList = this.database.getAllAuthsByName(auth);
String message = "[AuthMe] ";
int i = 0;
for (String account : accountList) {
i++;
message = message + account;
if (i != accountList.size()) {
message = message + ", ";
} else {
message = message + ".";
}
}
for (Player player : AuthMe.getInstance().getServer().getOnlinePlayers()) {
if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) {
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has "
+ String.valueOf(accountList.size()) + " accounts");
player.sendMessage(message);
}
}
}
}

View File

@ -35,7 +35,13 @@ public class Utils {
return;
if(plugin.permission == null)
return;
currentGroup = plugin.permission.getPrimaryGroup(player);
try {
currentGroup = plugin.permission.getPrimaryGroup(player);
} catch (UnsupportedOperationException e) {
ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!");
plugin.permission = null;
return;
}
World world = null;
String name = player.getName();
switch(group) {
@ -69,14 +75,20 @@ public class Utils {
}
public boolean addNormal(Player player, String group) {
if(!Utils.getInstance().useGroupSystem()){
if(!useGroupSystem()){
return false;
}
if(plugin.permission == null) return false;
World world = null;
if(plugin.permission.playerRemoveGroup(world,player.getName().toString(),Settings.getUnloggedinGroup) && plugin.permission.playerAddGroup(world,player.getName().toString(),group)) {
return true;
}
try {
if(plugin.permission.playerRemoveGroup(world,player.getName().toString(),Settings.getUnloggedinGroup) && plugin.permission.playerAddGroup(world,player.getName().toString(),group)) {
return true;
}
} catch (UnsupportedOperationException e) {
ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!");
plugin.permission = null;
return false;
}
return false;
}

View File

@ -174,6 +174,6 @@ public class API {
* @param Player player
*/
public static void forceLogin(Player player) {
instance.management.performLogin(player, "dontneed", false, true);
instance.management.performLogin(player, "dontneed", true);
}
}

View File

@ -15,7 +15,7 @@ public class PlayerAuth {
private String world = "world";
private String salt = "";
private String vBhash = null;
private int groupId;
private int groupId = -1;
private String email = "your@email.com";
private String realName = "";

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.backup.FileCache;
import fr.xephi.authme.events.ResetInventoryEvent;
import fr.xephi.authme.events.StoreInventoryEvent;
@ -66,8 +67,14 @@ public class LimboCache {
if(player.isFlying())
flying = true;
else flying = false;
if (plugin.permission != null)
playerGroup = plugin.permission.getPrimaryGroup(player);
if (plugin.permission != null) {
try {
playerGroup = plugin.permission.getPrimaryGroup(player);
} catch (UnsupportedOperationException e) {
ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!");
plugin.permission = null;
}
}
}
if(Settings.isForceSurvivalModeEnabled) {

View File

@ -14,7 +14,7 @@ public class LimboPlayer {
private int messageTaskId = -1;
private GameMode gameMode = GameMode.SURVIVAL;
private boolean operator = false;
private String group = null;
private String group = "";
private boolean flying = false;
public LimboPlayer(String name, Location loc, ItemStack[] inventory, ItemStack[] armour, GameMode gameMode, boolean operator, String group, boolean flying) {

View File

@ -35,7 +35,7 @@ public class LoginCommand implements CommandExecutor {
m._(player, "no_perm");
return true;
}
plugin.management.performLogin(player, args[0], false, false);
plugin.management.performLogin(player, args[0], false);
return true;
}
}

View File

@ -39,7 +39,7 @@ public class PasspartuCommand implements CommandExecutor {
if ((sender instanceof Player) && args.length == 1) {
if(utils.readToken(args[0])) {
//bypass login!
plugin.management.performLogin((Player) sender, "dontneed", true, false);
plugin.management.performLogin((Player) sender, "dontneed", true);
return true;
}
sender.sendMessage("Time is expired or Token is Wrong!");

View File

@ -1,297 +1,69 @@
package fr.xephi.authme.commands;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import me.muizers.Notifications.Notification;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RegisterTeleportEvent;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
public class RegisterCommand implements CommandExecutor {
private Messages m = Messages.getInstance();
private PlayersLogs pllog = PlayersLogs.getInstance();
private DataSource database;
public PlayerAuth auth;
public AuthMe plugin;
public RegisterCommand(DataSource database, AuthMe plugin) {
this.database = database;
public RegisterCommand(AuthMe plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmnd, String label, String[] args) {
if (!(sender instanceof Player)) {
return true;
sender.sendMessage("Player Only! Use 'authme register <playername> <password>' instead");
return true;
}
if (!plugin.authmePermissible(sender, "authme." + label.toLowerCase())) {
m._(sender, "no_perm");
return true;
}
final Player player = (Player) sender;
final String name = player.getName().toLowerCase();
String ipA = player.getAddress().getAddress().getHostAddress();
if (Settings.bungee) {
if (plugin.realIp.containsKey(name))
ipA = plugin.realIp.get(name);
}
final String ip = ipA;
if (PlayerCache.getInstance().isAuthenticated(name)) {
m._(player, "logged_in");
return true;
}
if (!Settings.isRegistrationEnabled) {
m._(player, "reg_disabled");
return true;
}
if (database.isAuthAvailable(player.getName().toLowerCase())) {
m._(player, "user_regged");
if (pllog.getStringList("players").contains(player.getName())) {
pllog.getStringList("players").remove(player.getName());
}
return true;
}
if(Settings.getmaxRegPerIp > 0 ){
if(!plugin.authmePermissible(sender, "authme.allow2accounts") && database.getAllAuthsByIp(ipA).size() >= Settings.getmaxRegPerIp) {
m._(player, "max_reg");
return true;
}
}
if(Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
if(!args[0].contains("@")) {
if(Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) {
if(Settings.doubleEmailCheck) {
if(args.length < 2) {
m._(player, "usage_reg");
return true;
}
if(Settings.doubleEmailCheck) {
if(args.length < 2) {
m._(player, "usage_reg");
return true;
}
if(!args[0].equals(args[1])) {
m._(player, "usage_reg");
return true;
}
}
final String email = args[0];
if(Settings.getmaxRegPerEmail > 0) {
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m._(player, "max_reg");
return true;
}
}
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
final String thePass = rand.nextString();
if (!thePass.isEmpty()) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if (PasswordSecurity.userSalt.containsKey(name)) {
try {
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name);
final PlayerAuth fAuth = new PlayerAuth(name, hashnew, PasswordSecurity.userSalt.get(name), ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
database.saveAuth(fAuth);
database.updateEmail(fAuth);
database.updateSession(fAuth);
plugin.mail.main(fAuth, thePass);
} catch (NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage());
}
} else {
try {
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name);
final PlayerAuth fAuth = new PlayerAuth(name, hashnew, ip, new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
database.saveAuth(fAuth);
database.updateEmail(fAuth);
database.updateSession(fAuth);
plugin.mail.main(fAuth, thePass);
} catch (NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage());
}
}
}
});
if(!Settings.getRegisteredGroup.isEmpty()){
Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED);
}
m._(player, "vb_nonActiv");
int time = Settings.getRegistrationTimeout * 20;
int msgInterval = Settings.getWarnMessageInterval;
if (time != 0) {
Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getTimeoutTaskId());
int id = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new TimeoutTask(plugin, name), time);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
}
Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId());
int nwMsg = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("login_msg"), msgInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(nwMsg);
if (Settings.isTeleportToSpawnEnabled) {
World world = player.getWorld();
Location loca = plugin.getSpawnLocation(world);
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
plugin.getServer().getPluginManager().callEvent(tpEvent);
if(!tpEvent.isCancelled()) {
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
}
player.teleport(tpEvent.getTo());
}
}
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false);
player.setFlying(false);
}
player.saveData();
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress());
if(plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered by email!"));
}
return true;
}
}
if (args.length == 0 || (Settings.getEnablePasswordVerifier && args.length < 2) ) {
}
if(!args[0].equals(args[1])) {
m._(player, "usage_reg");
return true;
}
}
if(!args[0].contains("@")) {
m._(player, "usage_reg");
return true;
}
if(args[0].length() < Settings.getPasswordMinLen || args[0].length() > Settings.passwordMaxLength) {
m._(player, "pass_len");
return true;
}
if(!Settings.unsafePasswords.isEmpty()) {
if (Settings.unsafePasswords.contains(args[0].toLowerCase())) {
m._(player, "password_error");
return true;
}
}
try {
String hash;
if(Settings.getEnablePasswordVerifier) {
if (args[0].equals(args[1])) {
hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name);
} else {
m._(player, "password_error");
return true;
}
} else
hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[0], name);
if (Settings.getMySQLColumnSalt.isEmpty())
{
auth = new PlayerAuth(name, hash, ip, new Date().getTime(), "your@email.com", player.getName());
} else {
auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), ip, new Date().getTime(), player.getName());
}
if (!database.saveAuth(auth)) {
m._(player, "error");
return true;
}
PlayerCache.getInstance().addPlayer(auth);
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
if (limbo != null) {
player.setGameMode(limbo.getGameMode());
if (Settings.isTeleportToSpawnEnabled) {
World world = player.getWorld();
Location loca = plugin.getSpawnLocation(world);
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
plugin.getServer().getPluginManager().callEvent(tpEvent);
if(!tpEvent.isCancelled()) {
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
}
player.teleport(tpEvent.getTo());
}
}
sender.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
sender.getServer().getScheduler().cancelTask(limbo.getMessageTaskId());
LimboCache.getInstance().deleteLimboPlayer(name);
}
if(!Settings.getRegisteredGroup.isEmpty()){
Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED);
}
m._(player, "registered");
if (!Settings.getmailAccount.isEmpty())
m._(player, "add_email");
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false);
player.setFlying(false);
}
// The Loginevent now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData();
// Register is finish and player is logged, display welcome message
if(Settings.useWelcomeMessage)
if(Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) {
Bukkit.getServer().broadcastMessage(s);
}
} else {
for (String s : Settings.welcomeMsg) {
player.sendMessage(plugin.replaceAllInfos(s, player));
}
}
// Register is now finish , we can force all commands
forceCommands(player);
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress());
if(plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!"));
}
} catch (NoSuchAlgorithmException ex) {
ConsoleLogger.showError(ex.getMessage());
m._(sender, "error");
}
}
final String email = args[0];
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
final String thePass = rand.nextString();
plugin.management.performRegister(player, thePass, email);
return true;
}
if (args.length == 0 || (Settings.getEnablePasswordVerifier && args.length < 2)) {
m._(player, "usage_reg");
return true;
}
if (args.length > 1 && Settings.getEnablePasswordVerifier)
if(!args[0].equals(args[1])) {
m._(player, "password_error");
return true;
}
plugin.management.performRegister(player, args[0], "");
return true;
}
protected void forceCommands(Player player) {
for (String command : Settings.forceCommands) {
try {
player.performCommand(command.replace("%p", player.getName()));
} catch (Exception e) {}
}
}
}

View File

@ -72,9 +72,9 @@ public class UnregisterCommand implements CommandExecutor {
return true;
}
if(Settings.isForcedRegistrationEnabled) {
player.getInventory().setArmorContents(new ItemStack[4]);
player.getInventory().setContents(new ItemStack[36]);
player.saveData();
player.getInventory().setContents(new ItemStack[36]);
player.getInventory().setArmorContents(new ItemStack[4]);
player.saveData();
PlayerCache.getInstance().removePlayer(player.getName().toLowerCase());
LimboCache.getInstance().addLimboPlayer(player);
Utils.getInstance().setGroup(player, groupType.UNREGISTERED);
@ -85,11 +85,11 @@ public class UnregisterCommand implements CommandExecutor {
int id = sched.scheduleSyncDelayedTask(plugin, new TimeoutTask(plugin, name), delay);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
}
sched.scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("reg_msg"), interval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("reg_msg"), interval)));
if(!Settings.unRegisteredGroup.isEmpty()){
Utils.getInstance().setGroup(player, Utils.groupType.UNREGISTERED);
}
player.sendMessage("unregistered");
m._(player, "unregistered");
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
if(plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!"));
@ -108,7 +108,7 @@ public class UnregisterCommand implements CommandExecutor {
PlayersLogs.players.remove(player.getName());
pllog.save();
}
player.sendMessage("unregistered");
m._(player, "unregistered");
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
if(plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!"));

View File

@ -117,7 +117,7 @@ public class LoginScreen extends GenericPopup implements Clickable{
if (event.isCancelled() || event == null || event.getPlayer() == null) return;
if (b.equals(loginBtn))
{
plugin.management.performLogin(player, passBox.getText(), false, false);
plugin.management.performLogin(player, passBox.getText(), false);
}else if(b.equals(exitBtn))
{
event.getPlayer().kickPlayer(exitMsg);

View File

@ -588,7 +588,7 @@ public class AuthMePlayerListener implements Listener {
PlayerCache.getInstance().addPlayer(auth);
}
m._(player, "valid_session");
return;
return;
} else if (!Settings.sessionExpireOnIpChange){
GameMode gM = gameMode.get(name);
this.causeByAuthMe = true;
@ -615,7 +615,7 @@ public class AuthMePlayerListener implements Listener {
} else {
//Session is ended correctly
PlayerCache.getInstance().removePlayer(name);
}
}
}
// isent in session or session was ended correctly
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
@ -698,8 +698,10 @@ public class AuthMePlayerListener implements Listener {
player.performCommand("motd");
// Remove the join message while the player isn't logging in
joinMessage.put(name, event.getJoinMessage());
event.setJoinMessage(null);
if (Settings.enableProtection) {
joinMessage.put(name, event.getJoinMessage());
event.setJoinMessage(null);
}
}
private void placePlayerSafely(Player player, Location spawnLoc) {
@ -736,7 +738,7 @@ public class AuthMePlayerListener implements Listener {
}
}
if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name))
if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name) && Settings.enableProtection)
event.setQuitMessage(null);
if (LimboCache.getInstance().hasLimboPlayer(name)) {
@ -755,6 +757,7 @@ public class AuthMePlayerListener implements Listener {
player.setFlying(limbo.isFlying());
}
this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
this.plugin.getServer().getScheduler().cancelTask(limbo.getMessageTaskId());
LimboCache.getInstance().deleteLimboPlayer(name);
if(playerBackup.doesCacheExist(name)) {
playerBackup.removeCache(name);
@ -802,7 +805,7 @@ public class AuthMePlayerListener implements Listener {
} catch (NullPointerException npe) { }
}
if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name))
if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name) && Settings.enableProtection)
event.setLeaveMessage(null);
if (LimboCache.getInstance().hasLimboPlayer(name))
@ -837,6 +840,7 @@ public class AuthMePlayerListener implements Listener {
player.setFlying(limbo.isFlying());
}
this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
this.plugin.getServer().getScheduler().cancelTask(limbo.getMessageTaskId());
LimboCache.getInstance().deleteLimboPlayer(name);
if (this.playerBackup.doesCacheExist(name)) {
this.playerBackup.removeCache(name);

View File

@ -0,0 +1,40 @@
package fr.xephi.authme.process;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.process.login.AsyncronousLogin;
import fr.xephi.authme.process.register.AsyncronousRegister;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
/**
*
* @authors Xephi59, <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
*
*/
public class Management extends Thread {
public DataSource database;
public AuthMe plugin;
public static RandomString rdm = new RandomString(Settings.captchaLength);
public PluginManager pm;
public Management(DataSource database, AuthMe plugin) {
this.database = database;
this.plugin = plugin;
this.pm = plugin.getServer().getPluginManager();
}
public void run() {
}
public void performLogin(final Player player, final String password, final boolean forceLogin) {
new AsyncronousLogin(player, password, forceLogin, plugin, database).process();
}
public void performRegister(final Player player, final String password, final String email) {
new AsyncronousRegister(player, password, email, plugin, database).process();
}
}

View File

@ -0,0 +1,223 @@
package fr.xephi.authme.process.login;
import java.util.Date;
import java.util.List;
import me.muizers.Notifications.Notification;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
public class AsyncronousLogin {
protected Player player;
protected String name;
protected String password;
protected String realName;
protected boolean forceLogin;
private AuthMe plugin;
private DataSource database;
private static RandomString rdm = new RandomString(Settings.captchaLength);
private Messages m = Messages.getInstance();
public AsyncronousLogin(Player player, String password, boolean forceLogin, AuthMe plugin, DataSource data) {
this.player = player;
this.password = password;
name = player.getName().toLowerCase();
realName = player.getName();
this.forceLogin = forceLogin;
this.plugin = plugin;
this.database = data;
}
protected String getIP() {
String ip = player.getAddress().getAddress().getHostAddress();
if (Settings.bungee) {
if (plugin.realIp.containsKey(name))
ip = plugin.realIp.get(name);
}
return ip;
}
protected boolean needsCaptcha() {
if (Settings.useCaptcha) {
if (!plugin.captcha.containsKey(name)) {
plugin.captcha.put(name, 1);
} else {
int i = plugin.captcha.get(name) + 1;
plugin.captcha.remove(name);
plugin.captcha.put(name, i);
}
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
plugin.cap.put(name, rdm.nextString());
for (String s : m._("need_captcha")) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
}
return true;
} else if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
try {
plugin.captcha.remove(name);
plugin.cap.remove(name);
} catch (NullPointerException npe) {
}
}
}
return false;
}
/**
* Checks the precondition for authentication (like user known) and returns the playerAuth-State
*/
protected PlayerAuth preAuth() {
if (PlayerCache.getInstance().isAuthenticated(name)) {
m._(player, "logged_in");
return null;
}
if (!database.isAuthAvailable(name)) {
m._(player, "user_unknown");
if(LimboCache.getInstance().hasLimboPlayer(name)) {
Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId());
String[] msg;
if(Settings.emailRegistration) {
msg = m._("reg_email_msg");
} else {
msg = m._("reg_msg");
}
int msgT = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
}
return null;
}
PlayerAuth pAuth = database.getAuth(name);
if (pAuth == null) {
m._(player, "user_unknown");
return null;
}
if (!Settings.getMySQLColumnGroup.isEmpty() && pAuth.getGroupId() == Settings.getNonActivatedGroup) {
m._(player, "vb_nonActiv");
return null;
}
return pAuth;
}
public void process() {
PlayerAuth pAuth = preAuth();
if (pAuth == null || needsCaptcha())
return;
String hash = pAuth.getHash();
String email = pAuth.getEmail();
boolean passwordVerified = true;
if (!forceLogin)
try {
passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, name);
} catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage());
m._(player, "error");
return;
}
if (passwordVerified && player.isOnline()) {
PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName);
database.updateSession(auth);
plugin.pllog.addPlayer(player);
if (Settings.useCaptcha) {
if (plugin.captcha.containsKey(name)) {
plugin.captcha.remove(name);
}
if (plugin.cap.containsKey(name)) {
plugin.cap.remove(name);
}
}
player.setNoDamageTicks(0);
m._(player, "login");
displayOtherAccounts(auth);
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " logged in!");
if (plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " logged in!"));
}
// makes player isLoggedin via API
PlayerCache.getInstance().addPlayer(auth);
// As the scheduling executes the Task most likely after the current task, we schedule it in the end
// so that we can be sure, and have not to care if it might be processed in other order.
ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player, plugin, database);
if (syncronousPlayerLogin.getLimbo() != null) {
player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getTimeoutTaskId());
player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getMessageTaskId());
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin);
} else if (player.isOnline()) {
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " used the wrong password");
if (Settings.isKickOnWrongPasswordEnabled) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (AuthMePlayerListener.gameMode != null && AuthMePlayerListener.gameMode.containsKey(name)) {
player.setGameMode(AuthMePlayerListener.gameMode.get(name));
}
player.kickPlayer(m._("wrong_pwd")[0]);
}
});
} else {
m._(player, "wrong_pwd");
return;
}
} else {
ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... ");
}
}
public void displayOtherAccounts(PlayerAuth auth) {
if (!Settings.displayOtherAccounts) {
return;
}
if (auth == null) {
return;
}
if (this.database.getAllAuthsByName(auth).isEmpty() || this.database.getAllAuthsByName(auth) == null) {
return;
}
if (this.database.getAllAuthsByName(auth).size() == 1) {
return;
}
List<String> accountList = this.database.getAllAuthsByName(auth);
String message = "[AuthMe] ";
int i = 0;
for (String account : accountList) {
i++;
message = message + account;
if (i != accountList.size()) {
message = message + ", ";
} else {
message = message + ".";
}
}
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) {
player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has "
+ accountList.size() + " accounts");
player.sendMessage(message);
}
}
}
}

View File

@ -0,0 +1,202 @@
package fr.xephi.authme.process.login;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.Utils;
import fr.xephi.authme.Utils.groupType;
import fr.xephi.authme.api.API;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.backup.FileCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.settings.Settings;
public class ProcessSyncronousPlayerLogin implements Runnable {
private LimboPlayer limbo;
private Player player;
private String name;
private PlayerAuth auth;
private AuthMe plugin;
private DataSource database;
private PluginManager pm;
private FileCache playerCache = new FileCache();
public ProcessSyncronousPlayerLogin(Player player, AuthMe plugin, DataSource data) {
this.plugin = plugin;
this.database = data;
this.pm = plugin.getServer().getPluginManager();
this.player = player;
this.name = player.getName().toLowerCase();
this.limbo = LimboCache.getInstance().getLimboPlayer(name);
this.auth = database.getAuth(name);
}
public LimboPlayer getLimbo() {
return limbo;
}
protected void restoreOpState() {
player.setOp(limbo.getOperator());
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(limbo.isFlying());
player.setFlying(limbo.isFlying());
}
}
protected void packQuitLocation() {
Utils.getInstance().packCoords(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), player);
}
protected void teleportBackFromSpawn() {
AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limbo.getLoc());
pm.callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
Location fLoc = tpEvent.getTo();
if (!fLoc.getChunk().isLoaded()) {
fLoc.getChunk().load();
}
player.teleport(fLoc);
}
}
protected void teleportToSpawn() {
Location spawnL = plugin.getSpawnLocation(player.getWorld());
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true);
pm.callEvent(tpEvent);
if (!tpEvent.isCancelled()) {
Location fLoc = tpEvent.getTo();
if (!fLoc.getChunk().isLoaded()) {
fLoc.getChunk().load();
}
player.teleport(fLoc);
}
}
protected void restoreInventory() {
RestoreInventoryEvent event = new RestoreInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
API.setPlayerInventory(player, event.getInventory(), event.getArmor());
}
}
protected void forceCommands() {
for (String command : Settings.forceCommands) {
try {
player.performCommand(command.replace("%p", player.getName()));
} catch (Exception e) {}
}
}
@Override
public void run() {
// Limbo contains the State of the Player before /login
if (limbo != null) {
// Op & Flying
restoreOpState();
/*
* Restore Inventories and GameMode
* We need to restore them before teleport the player
* Cause in AuthMePlayerListener, we call ProtectInventoryEvent after Teleporting
* Also it's the current world inventory !
*/
if (!Settings.forceOnlyAfterLogin) {
player.setGameMode(limbo.getGameMode());
// Inventory - Make it after restore GameMode , cause we need to restore the
// right inventory in the right gamemode
if (Settings.protectInventoryBeforeLogInEnabled && player.hasPlayedBefore()) {
restoreInventory();
}
}
else {
// Inventory - Make it before force the survival GameMode to cancel all
// inventory problem
if (Settings.protectInventoryBeforeLogInEnabled && player.hasPlayedBefore()) {
restoreInventory();
}
player.setGameMode(GameMode.SURVIVAL);
}
// Teleport the player
if(Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
// If we have force the spawn location on join
teleportToSpawn();
} else {
if (Settings.isTeleportToSpawnEnabled) {
// If and only if teleport unauthed to spawn is activate
teleportBackFromSpawn();
} else {
if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
// Teleport the player on the saved location
packQuitLocation();
} else {
// Do not move the player from his position
}
}
}
// Teleport
if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
packQuitLocation();
} else {
teleportBackFromSpawn();
}
} else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) {
teleportToSpawn();
} else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) {
packQuitLocation();
} else {
teleportBackFromSpawn();
}
// Re-Force Survival GameMode if we need due to world change specification
if (Settings.isForceSurvivalModeEnabled)
Utils.forceGM(player);
// Restore Permission Group
Utils.getInstance().setGroup(player, groupType.LOGGEDIN);
// Cleanup no longer used temporary data
LimboCache.getInstance().deleteLimboPlayer(name);
if (playerCache.doesCacheExist(name)) {
playerCache.removeCache(name);
}
}
// We can now display the join message
if (AuthMePlayerListener.joinMessage.containsKey(name) && AuthMePlayerListener.joinMessage.get(name) != null && !AuthMePlayerListener.joinMessage.get(name).isEmpty()) {
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (p.isOnline())
p.sendMessage(AuthMePlayerListener.joinMessage.get(name));
}
AuthMePlayerListener.joinMessage.remove(name);
}
// The Loginevent now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData();
// Login is finish, display welcome message
if(Settings.useWelcomeMessage)
if(Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) {
Bukkit.getServer().broadcastMessage(s);
}
} else {
for (String s : Settings.welcomeMsg) {
player.sendMessage(plugin.replaceAllInfos(s, player));
}
}
// Login is now finish , we can force all commands
forceCommands();
}
}

View File

@ -0,0 +1,149 @@
package fr.xephi.authme.process.register;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
public class AsyncronousRegister {
protected Player player;
protected String name;
protected String password;
protected String realName;
protected String email = "";
protected boolean allowRegister;
private AuthMe plugin;
private DataSource database;
private Messages m = Messages.getInstance();
public AsyncronousRegister(Player player, String password, String email, AuthMe plugin, DataSource data) {
this.player = player;
this.password = password;
name = player.getName().toLowerCase();
realName = player.getName();
this.email = email;
this.plugin = plugin;
this.database = data;
this.allowRegister = true;
}
protected String getIp() {
String ip = player.getAddress().getAddress().getHostAddress();
if (Settings.bungee) {
if (plugin.realIp.containsKey(name))
ip = plugin.realIp.get(name);
}
return ip;
}
protected void preRegister() {
if (PlayerCache.getInstance().isAuthenticated(name)) {
m._(player, "logged_in");
allowRegister = false;
}
if (!Settings.isRegistrationEnabled) {
m._(player, "reg_disabled");
allowRegister = false;
}
if (database.isAuthAvailable(player.getName().toLowerCase())) {
m._(player, "user_regged");
if (plugin.pllog.getStringList("players").contains(player.getName())) {
plugin.pllog.getStringList("players").remove(player.getName());
}
allowRegister = false;
}
if(Settings.getmaxRegPerIp > 0 ){
if(!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp) {
m._(player, "max_reg");
allowRegister = false;
}
}
}
public void process() {
preRegister();
if(!allowRegister) return;
if(!email.isEmpty() && email != "") {
emailRegister();
return;
}
passwordRegister();
}
protected void emailRegister() {
if(Settings.getmaxRegPerEmail > 0) {
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m._(player, "max_reg");
return;
}
}
PlayerAuth auth = null;
try {
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
auth = new PlayerAuth(name, hashnew, getIp(), new Date().getTime(), (int) player.getLocation().getX() , (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, realName);
} catch (NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage());
m._(player, "error");
return;
}
if (PasswordSecurity.userSalt.containsKey(name)) {
auth.setSalt(PasswordSecurity.userSalt.get(name));
}
database.saveAuth(auth);
database.updateEmail(auth);
database.updateSession(auth);
plugin.mail.main(auth, password);
ProcessSyncronousEmailRegister syncronous = new ProcessSyncronousEmailRegister(player, plugin);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
return;
}
protected void passwordRegister() {
if(password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) {
m._(player, "pass_len");
return;
}
if(!Settings.unsafePasswords.isEmpty()) {
if (Settings.unsafePasswords.contains(password.toLowerCase())) {
m._(player, "password_error");
return;
}
}
PlayerAuth auth = null;
String hash = "";
try {
hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
} catch (NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage());
m._(player, "error");
return;
}
if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name))
{
auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com", player.getName());
} else {
auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime(), player.getName());
}
if (!database.saveAuth(auth)) {
m._(player, "error");
return;
}
PlayerCache.getInstance().addPlayer(auth);
ProcessSyncronousPasswordRegister syncronous = new ProcessSyncronousPasswordRegister(player, plugin);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
return;
}
}

View File

@ -0,0 +1,74 @@
package fr.xephi.authme.process.register;
import me.muizers.Notifications.Notification;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.events.RegisterTeleportEvent;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
public class ProcessSyncronousEmailRegister implements Runnable {
protected Player player;
protected String name;
private AuthMe plugin;
private Messages m = Messages.getInstance();
public ProcessSyncronousEmailRegister(Player player, AuthMe plugin) {
this.player = player;
this.name = player.getName().toLowerCase();
this.plugin = plugin;
}
@Override
public void run() {
if(!Settings.getRegisteredGroup.isEmpty()){
Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED);
}
m._(player, "vb_nonActiv");
int time = Settings.getRegistrationTimeout * 20;
int msgInterval = Settings.getWarnMessageInterval;
if (time != 0) {
Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getTimeoutTaskId());
int id = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new TimeoutTask(plugin, name), time);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
}
Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId());
int nwMsg = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("login_msg"), msgInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(nwMsg);
if (Settings.isTeleportToSpawnEnabled) {
World world = player.getWorld();
Location loca = plugin.getSpawnLocation(world);
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
plugin.getServer().getPluginManager().callEvent(tpEvent);
if(!tpEvent.isCancelled()) {
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
}
player.teleport(tpEvent.getTo());
}
}
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false);
player.setFlying(false);
}
player.saveData();
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress());
if(plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered by email!"));
}
}
}

View File

@ -0,0 +1,97 @@
package fr.xephi.authme.process.register;
import me.muizers.Notifications.Notification;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RegisterTeleportEvent;
import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings;
public class ProcessSyncronousPasswordRegister implements Runnable {
protected Player player;
protected String name;
private AuthMe plugin;
private Messages m = Messages.getInstance();
public ProcessSyncronousPasswordRegister(Player player, AuthMe plugin) {
this.player = player;
this.name = player.getName().toLowerCase();
this.plugin = plugin;
}
protected void forceCommands(Player player) {
for (String command : Settings.forceCommands) {
try {
player.performCommand(command.replace("%p", player.getName()));
} catch (Exception e) {}
}
}
@Override
public void run() {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
if (limbo != null) {
player.setGameMode(limbo.getGameMode());
if (Settings.isTeleportToSpawnEnabled) {
World world = player.getWorld();
Location loca = plugin.getSpawnLocation(world);
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
plugin.getServer().getPluginManager().callEvent(tpEvent);
if(!tpEvent.isCancelled()) {
if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) {
tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load();
}
player.teleport(tpEvent.getTo());
}
}
plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
plugin.getServer().getScheduler().cancelTask(limbo.getMessageTaskId());
LimboCache.getInstance().deleteLimboPlayer(name);
}
if(!Settings.getRegisteredGroup.isEmpty()){
Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED);
}
m._(player, "registered");
if (!Settings.getmailAccount.isEmpty())
m._(player, "add_email");
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false);
player.setFlying(false);
}
// The Loginevent now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData();
// Register is finish and player is logged, display welcome message
if(Settings.useWelcomeMessage)
if(Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) {
Bukkit.getServer().broadcastMessage(s);
}
} else {
for (String s : Settings.welcomeMsg) {
player.sendMessage(plugin.replaceAllInfos(s, player));
}
}
// Register is now finish , we can force all commands
forceCommands(player);
if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress());
if(plugin.notifications != null) {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!"));
}
}
}

View File

@ -512,8 +512,12 @@ public void mergeConfig() {
set("Email.delayRecall", 5);
if(!contains("settings.useWelcomeMessage"))
set("settings.useWelcomeMessage", true);
if(!contains("settings.security.unsafePasswords"))
set("settings.security.unsafePasswords", new ArrayList<String>());
if(!contains("settings.security.unsafePasswords")) {
List<String> str = new ArrayList<String>();
str.add("123456");
str.add("password");
set("settings.security.unsafePasswords", str);
}
if(!contains("Protection.countriesBlacklist")) {
countriesBlacklist = new ArrayList<String>();
countriesBlacklist.add("A1");

View File

@ -353,8 +353,8 @@ Hooks:
useEssentialsMotd: false
Performances:
# HIGHLY recommended to use this! This will increase database performance
# Default is false due to little servers
useMultiThreading: false
# Default is true, change it to false if you experience issues
useMultiThreading: true
Purge:
# On Enable , does AuthMe need to purge automatically old accounts unused ?
useAutoPurge: false

View File

@ -3,7 +3,7 @@ author: Xephi59
website: http://dev.bukkit.org/bukkit-plugins/authme-reloaded/
description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player.
main: fr.xephi.authme.AuthMe
version: 3.3.2-DEV-1
version: 3.3.2
softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag, Essentials, EssentialsSpawn]
commands:
register: