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:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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!"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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!"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user