Attempt to update player's IP on login if they have default IP in database.
This commit is contained in:
parent
4161dcaa94
commit
774b7513c9
@ -33,6 +33,7 @@ public class AsynchronousLogin {
|
|||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final DataSource database;
|
private final DataSource database;
|
||||||
private final Messages m;
|
private final Messages m;
|
||||||
|
private final String ip;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for AsynchronousLogin.
|
* Constructor for AsynchronousLogin.
|
||||||
@ -52,10 +53,7 @@ public class AsynchronousLogin {
|
|||||||
this.forceLogin = forceLogin;
|
this.forceLogin = forceLogin;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = data;
|
this.database = data;
|
||||||
}
|
this.ip = plugin.getIP(player);
|
||||||
|
|
||||||
protected String getIP() {
|
|
||||||
return plugin.getIP(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean needsCaptcha() {
|
protected boolean needsCaptcha() {
|
||||||
@ -87,7 +85,9 @@ public class AsynchronousLogin {
|
|||||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!database.isAuthAvailable(name)) {
|
|
||||||
|
PlayerAuth pAuth = database.getAuth(name);
|
||||||
|
if (pAuth == null) {
|
||||||
m.send(player, MessageKey.USER_NOT_REGISTERED);
|
m.send(player, MessageKey.USER_NOT_REGISTERED);
|
||||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||||
LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId().cancel();
|
LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId().cancel();
|
||||||
@ -97,42 +97,45 @@ public class AsynchronousLogin {
|
|||||||
} else {
|
} else {
|
||||||
msg = m.retrieve(MessageKey.REGISTER_MESSAGE);
|
msg = m.retrieve(MessageKey.REGISTER_MESSAGE);
|
||||||
}
|
}
|
||||||
BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval));
|
BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin,
|
||||||
|
new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval));
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS) && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) {
|
|
||||||
if (plugin.isLoggedIp(name, getIP())) {
|
|
||||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlayerAuth pAuth = database.getAuth(name);
|
|
||||||
if (pAuth == null) {
|
|
||||||
m.send(player, MessageKey.USER_NOT_REGISTERED);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!Settings.getMySQLColumnGroup.isEmpty() && pAuth.getGroupId() == Settings.getNonActivatedGroup) {
|
if (!Settings.getMySQLColumnGroup.isEmpty() && pAuth.getGroupId() == Settings.getNonActivatedGroup) {
|
||||||
m.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
m.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.preventOtherCase && !player.getName().equals(pAuth.getRealName())) {
|
if (Settings.getMaxLoginPerIp > 0
|
||||||
m.send(player, MessageKey.USERNAME_ALREADY_ONLINE_ERROR);
|
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||||
return null;
|
&& !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("localhost")) {
|
||||||
|
if (plugin.isLoggedIp(name, ip)) {
|
||||||
|
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player);
|
AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (!event.canLogin())
|
if (!event.canLogin()) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
return pAuth;
|
return pAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
PlayerAuth pAuth = preAuth();
|
PlayerAuth pAuth = preAuth();
|
||||||
if (pAuth == null || needsCaptcha())
|
if (pAuth == null || needsCaptcha()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pAuth.getIp().equals("127.0.0.1") && !pAuth.getIp().equals(ip)) {
|
||||||
|
pAuth.setIp(ip);
|
||||||
|
database.saveAuth(pAuth);
|
||||||
|
}
|
||||||
|
|
||||||
String email = pAuth.getEmail();
|
String email = pAuth.getEmail();
|
||||||
boolean passwordVerified = forceLogin || plugin.getPasswordSecurity()
|
boolean passwordVerified = forceLogin || plugin.getPasswordSecurity()
|
||||||
@ -142,7 +145,7 @@ public class AsynchronousLogin {
|
|||||||
PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
.realName(realName)
|
.realName(realName)
|
||||||
.ip(getIP())
|
.ip(ip)
|
||||||
.lastLogin(new Date().getTime())
|
.lastLogin(new Date().getTime())
|
||||||
.email(email)
|
.email(email)
|
||||||
.password(pAuth.getPassword())
|
.password(pAuth.getPassword())
|
||||||
@ -183,14 +186,16 @@ public class AsynchronousLogin {
|
|||||||
// task, we schedule it in the end
|
// task, we schedule it in the end
|
||||||
// so that we can be sure, and have not to care if it might be
|
// so that we can be sure, and have not to care if it might be
|
||||||
// processed in other order.
|
// processed in other order.
|
||||||
ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player, plugin, database);
|
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(player, plugin, database);
|
||||||
if (syncronousPlayerLogin.getLimbo() != null) {
|
if (syncPlayerLogin.getLimbo() != null) {
|
||||||
if (syncronousPlayerLogin.getLimbo().getTimeoutTaskId() != null)
|
if (syncPlayerLogin.getLimbo().getTimeoutTaskId() != null) {
|
||||||
syncronousPlayerLogin.getLimbo().getTimeoutTaskId().cancel();
|
syncPlayerLogin.getLimbo().getTimeoutTaskId().cancel();
|
||||||
if (syncronousPlayerLogin.getLimbo().getMessageTaskId() != null)
|
}
|
||||||
syncronousPlayerLogin.getLimbo().getMessageTaskId().cancel();
|
if (syncPlayerLogin.getLimbo().getMessageTaskId() != null) {
|
||||||
|
syncPlayerLogin.getLimbo().getMessageTaskId().cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncPlayerLogin);
|
||||||
} else if (player.isOnline()) {
|
} else if (player.isOnline()) {
|
||||||
if (!Settings.noConsoleSpam)
|
if (!Settings.noConsoleSpam)
|
||||||
ConsoleLogger.info(realName + " used the wrong password");
|
ConsoleLogger.info(realName + " used the wrong password");
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import fr.xephi.authme.util.Utils.GroupType;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class ProcessSyncronousPlayerLogin implements Runnable {
|
public class ProcessSyncPlayerLogin implements Runnable {
|
||||||
|
|
||||||
private final LimboPlayer limbo;
|
private final LimboPlayer limbo;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
@ -38,14 +38,14 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
|||||||
private final JsonCache playerCache;
|
private final JsonCache playerCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for ProcessSyncronousPlayerLogin.
|
* Constructor for ProcessSyncPlayerLogin.
|
||||||
*
|
*
|
||||||
* @param player Player
|
* @param player Player
|
||||||
* @param plugin AuthMe
|
* @param plugin AuthMe
|
||||||
* @param data DataSource
|
* @param data DataSource
|
||||||
*/
|
*/
|
||||||
public ProcessSyncronousPlayerLogin(Player player, AuthMe plugin,
|
public ProcessSyncPlayerLogin(Player player, AuthMe plugin,
|
||||||
DataSource data) {
|
DataSource data) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = data;
|
this.database = data;
|
||||||
this.pm = plugin.getServer().getPluginManager();
|
this.pm = plugin.getServer().getPluginManager();
|
||||||
Loading…
x
Reference in New Issue
Block a user