Merge branch '547-process-architecture' of https://github.com/AuthMe-Team/AuthMeReloaded into master2
This commit is contained in:
commit
5c43aea21f
@ -42,6 +42,7 @@ import fr.xephi.authme.output.Messages;
|
|||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.SHA256;
|
import fr.xephi.authme.security.crypts.SHA256;
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
@ -304,7 +305,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
setupApi();
|
setupApi();
|
||||||
|
|
||||||
// Set up the management
|
// Set up the management
|
||||||
management = new Management(this, newSettings);
|
ProcessService processService = new ProcessService(newSettings, messages, this);
|
||||||
|
management = new Management(this, processService, database, PlayerCache.getInstance());
|
||||||
|
|
||||||
// Set up the BungeeCord hook
|
// Set up the BungeeCord hook
|
||||||
setupBungeeCordHook();
|
setupBungeeCordHook();
|
||||||
@ -859,15 +861,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
return count >= Settings.getMaxLoginPerIp;
|
return count >= Settings.getMaxLoginPerIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasJoinedIp(String name, String ip) {
|
|
||||||
int count = 0;
|
|
||||||
for (Player player : Utils.getOnlinePlayers()) {
|
|
||||||
if (ip.equalsIgnoreCase(getIP(player)) && !player.getName().equalsIgnoreCase(name))
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count >= Settings.getMaxJoinPerIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Bukkit commands.
|
* Handle Bukkit commands.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package fr.xephi.authme.process;
|
|||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.process.email.AsyncAddEmail;
|
import fr.xephi.authme.process.email.AsyncAddEmail;
|
||||||
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||||
import fr.xephi.authme.process.join.AsynchronousJoin;
|
import fr.xephi.authme.process.join.AsynchronousJoin;
|
||||||
@ -20,18 +21,25 @@ public class Management {
|
|||||||
|
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final BukkitScheduler sched;
|
private final BukkitScheduler sched;
|
||||||
|
private final ProcessService processService;
|
||||||
|
private final DataSource dataSource;
|
||||||
|
private final PlayerCache playerCache;
|
||||||
private final NewSetting settings;
|
private final NewSetting settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for Management.
|
* Constructor for Management.
|
||||||
*
|
*
|
||||||
* @param plugin AuthMe
|
* @param plugin AuthMe
|
||||||
* @param settings The plugin settings
|
|
||||||
*/
|
*/
|
||||||
public Management(AuthMe plugin, NewSetting settings) {
|
public Management(AuthMe plugin, ProcessService processService, DataSource dataSource, PlayerCache playerCache) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.sched = this.plugin.getServer().getScheduler();
|
this.sched = this.plugin.getServer().getScheduler();
|
||||||
this.settings = settings;
|
this.processService = processService;
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
this.playerCache = playerCache;
|
||||||
|
|
||||||
|
// FIXME don't pass settings anymore -> go through the service in the processes
|
||||||
|
this.settings = processService.getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||||
@ -39,7 +47,7 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsynchronousLogin(player, password, forceLogin, plugin, plugin.getDataSource(), settings)
|
new AsynchronousLogin(player, password, forceLogin, plugin, dataSource, settings)
|
||||||
.process();
|
.process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -60,7 +68,7 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsyncRegister(player, password, email, plugin, plugin.getDataSource(), settings).process();
|
new AsyncRegister(player, password, email, plugin, dataSource, settings).process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -76,14 +84,7 @@ public class Management {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void performJoin(final Player player) {
|
public void performJoin(final Player player) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
runTask(new AsynchronousJoin(player, plugin, dataSource, playerCache, processService));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
new AsynchronousJoin(player, plugin, plugin.getDataSource()).process();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performQuit(final Player player, final boolean isKick) {
|
public void performQuit(final Player player, final boolean isKick) {
|
||||||
@ -91,28 +92,26 @@ public class Management {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsynchronousQuit(player, plugin, plugin.getDataSource(), isKick).process();
|
new AsynchronousQuit(player, plugin, dataSource, isKick).process();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performAddEmail(final Player player, final String newEmail) {
|
public void performAddEmail(final Player player, final String newEmail) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
runTask(new AsyncAddEmail(player, newEmail, dataSource, playerCache, processService));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
new AsyncAddEmail(player, plugin, newEmail, plugin.getDataSource(),
|
|
||||||
PlayerCache.getInstance(), settings).process();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
||||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsyncChangeEmail(player, plugin, oldEmail, newEmail, plugin.getDataSource(), PlayerCache.getInstance(), settings).process();
|
new AsyncChangeEmail(player, plugin, oldEmail, newEmail, dataSource, playerCache, settings).process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runTask(Process process) {
|
||||||
|
sched.runTaskAsynchronously(plugin, process);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/main/java/fr/xephi/authme/process/Process.java
Normal file
8
src/main/java/fr/xephi/authme/process/Process.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package fr.xephi.authme.process;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common interface for AuthMe processes.
|
||||||
|
*/
|
||||||
|
public interface Process extends Runnable {
|
||||||
|
|
||||||
|
}
|
||||||
63
src/main/java/fr/xephi/authme/process/ProcessService.java
Normal file
63
src/main/java/fr/xephi/authme/process/ProcessService.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package fr.xephi.authme.process;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.output.MessageKey;
|
||||||
|
import fr.xephi.authme.output.Messages;
|
||||||
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
|
import fr.xephi.authme.settings.domain.Property;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service for asynchronous and synchronous processes.
|
||||||
|
*/
|
||||||
|
public class ProcessService {
|
||||||
|
|
||||||
|
private final NewSetting settings;
|
||||||
|
private final Messages messages;
|
||||||
|
private final AuthMe authMe;
|
||||||
|
|
||||||
|
public ProcessService(NewSetting settings, Messages messages, AuthMe authMe) {
|
||||||
|
this.settings = settings;
|
||||||
|
this.messages = messages;
|
||||||
|
this.authMe = authMe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getProperty(Property<T> property) {
|
||||||
|
return settings.getProperty(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NewSetting getSettings() {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(CommandSender sender, MessageKey key) {
|
||||||
|
messages.send(sender, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String retrieveMessage(MessageKey key) {
|
||||||
|
return messages.retrieveSingle(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BukkitTask runTask(Runnable task) {
|
||||||
|
return authMe.getServer().getScheduler().runTask(authMe, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BukkitTask runTaskLater(Runnable task, long delay) {
|
||||||
|
return authMe.getServer().getScheduler().runTaskLater(authMe, task, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int scheduleSyncDelayedTask(Runnable task) {
|
||||||
|
return authMe.getServer().getScheduler().scheduleSyncDelayedTask(authMe, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void callEvent(Event event) {
|
||||||
|
authMe.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthMe getAuthMe() {
|
||||||
|
return authMe;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,40 +1,38 @@
|
|||||||
package fr.xephi.authme.process.email;
|
package fr.xephi.authme.process.email;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.output.Messages;
|
import fr.xephi.authme.process.Process;
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async task to add an email to an account.
|
* Async task to add an email to an account.
|
||||||
*/
|
*/
|
||||||
public class AsyncAddEmail {
|
public class AsyncAddEmail implements Process {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final String email;
|
private final String email;
|
||||||
private final Messages messages;
|
private final ProcessService service;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final PlayerCache playerCache;
|
private final PlayerCache playerCache;
|
||||||
private final NewSetting settings;
|
|
||||||
|
|
||||||
public AsyncAddEmail(Player player, AuthMe plugin, String email, DataSource dataSource,
|
public AsyncAddEmail(Player player, String email, DataSource dataSource, PlayerCache playerCache,
|
||||||
PlayerCache playerCache, NewSetting settings) {
|
ProcessService service) {
|
||||||
this.messages = plugin.getMessages();
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.playerCache = playerCache;
|
this.playerCache = playerCache;
|
||||||
this.settings = settings;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
@Override
|
||||||
|
public void run() {
|
||||||
String playerName = player.getName().toLowerCase();
|
String playerName = player.getName().toLowerCase();
|
||||||
|
|
||||||
if (playerCache.isAuthenticated(playerName)) {
|
if (playerCache.isAuthenticated(playerName)) {
|
||||||
@ -42,19 +40,19 @@ public class AsyncAddEmail {
|
|||||||
final String currentEmail = auth.getEmail();
|
final String currentEmail = auth.getEmail();
|
||||||
|
|
||||||
if (currentEmail != null && !"your@email.com".equals(currentEmail)) {
|
if (currentEmail != null && !"your@email.com".equals(currentEmail)) {
|
||||||
messages.send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
service.send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
||||||
} else if (!Utils.isEmailCorrect(email, settings)) {
|
} else if (!Utils.isEmailCorrect(email, service.getSettings())) {
|
||||||
messages.send(player, MessageKey.INVALID_EMAIL);
|
service.send(player, MessageKey.INVALID_EMAIL);
|
||||||
} else if (dataSource.isEmailStored(email)) {
|
} else if (dataSource.isEmailStored(email)) {
|
||||||
messages.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
service.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||||
} else {
|
} else {
|
||||||
auth.setEmail(email);
|
auth.setEmail(email);
|
||||||
if (dataSource.updateEmail(auth)) {
|
if (dataSource.updateEmail(auth)) {
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
messages.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
service.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
ConsoleLogger.showError("Could not save email for player '" + player + "'");
|
ConsoleLogger.showError("Could not save email for player '" + player + "'");
|
||||||
messages.send(player, MessageKey.ERROR);
|
service.send(player, MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -64,11 +62,11 @@ public class AsyncAddEmail {
|
|||||||
|
|
||||||
private void sendUnloggedMessage(DataSource dataSource) {
|
private void sendUnloggedMessage(DataSource dataSource) {
|
||||||
if (dataSource.isAuthAvailable(player.getName())) {
|
if (dataSource.isAuthAvailable(player.getName())) {
|
||||||
messages.send(player, MessageKey.LOGIN_MESSAGE);
|
service.send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
} else if (Settings.emailRegistration) {
|
} else if (service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)) {
|
||||||
messages.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
service.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
messages.send(player, MessageKey.REGISTER_MESSAGE);
|
service.send(player, MessageKey.REGISTER_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,66 +11,71 @@ import fr.xephi.authme.events.ProtectInventoryEvent;
|
|||||||
import fr.xephi.authme.events.SpawnTeleportEvent;
|
import fr.xephi.authme.events.SpawnTeleportEvent;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.output.Messages;
|
|
||||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||||
|
import fr.xephi.authme.process.Process;
|
||||||
|
import fr.xephi.authme.process.ProcessService;
|
||||||
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.task.MessageTask;
|
import fr.xephi.authme.task.MessageTask;
|
||||||
import fr.xephi.authme.task.TimeoutTask;
|
import fr.xephi.authme.task.TimeoutTask;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import fr.xephi.authme.util.Utils.GroupType;
|
import fr.xephi.authme.util.Utils.GroupType;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class AsynchronousJoin {
|
public class AsynchronousJoin implements Process {
|
||||||
|
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final DataSource database;
|
private final DataSource database;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Messages m;
|
private final ProcessService service;
|
||||||
private final BukkitScheduler sched;
|
private final PlayerCache playerCache;
|
||||||
|
|
||||||
public AsynchronousJoin(Player player, AuthMe plugin, DataSource database) {
|
public AsynchronousJoin(Player player, AuthMe plugin, DataSource database, PlayerCache playerCache,
|
||||||
this.m = plugin.getMessages();
|
ProcessService service) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.sched = plugin.getServer().getScheduler();
|
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.name = player.getName().toLowerCase();
|
this.name = player.getName().toLowerCase();
|
||||||
|
this.service = service;
|
||||||
|
this.playerCache = playerCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
@Override
|
||||||
|
public void run() {
|
||||||
if (Utils.isUnrestricted(player)) {
|
if (Utils.isUnrestricted(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.checkVeryGames) {
|
if (service.getProperty(HooksSettings.ENABLE_VERYGAMES_IP_CHECK)) {
|
||||||
plugin.getVerygamesIp(player);
|
plugin.getVerygamesIp(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.ess != null && Settings.disableSocialSpy) {
|
if (plugin.ess != null && service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) {
|
||||||
plugin.ess.getUser(player).setSocialSpyEnabled(false);
|
plugin.ess.getUser(player).setSocialSpyEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = plugin.getIP(player);
|
final String ip = plugin.getIP(player);
|
||||||
|
|
||||||
|
|
||||||
if (Settings.isAllowRestrictedIp && isNameRestricted(name, ip, player.getAddress().getHostName())) {
|
if (isNameRestricted(name, ip, player.getAddress().getHostName(), service.getSettings())) {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
|
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
|
||||||
player.kickPlayer(m.retrieveSingle(MessageKey.NOT_OWNER_ERROR));
|
player.kickPlayer(service.retrieveMessage(MessageKey.NOT_OWNER_ERROR));
|
||||||
if (Settings.banUnsafeIp) {
|
if (Settings.banUnsafeIp) {
|
||||||
plugin.getServer().banIP(ip);
|
plugin.getServer().banIP(ip);
|
||||||
}
|
}
|
||||||
@ -78,38 +83,34 @@ public class AsynchronousJoin {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Settings.getMaxJoinPerIp > 0
|
if (service.getProperty(RestrictionSettings.MAX_JOIN_PER_IP) > 0
|
||||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||||
&& !ip.equalsIgnoreCase("127.0.0.1")
|
&& !"127.0.0.1".equalsIgnoreCase(ip)
|
||||||
&& !ip.equalsIgnoreCase("localhost")
|
&& !"localhost".equalsIgnoreCase(ip)
|
||||||
&& plugin.hasJoinedIp(player.getName(), ip)) {
|
&& hasJoinedIp(player.getName(), ip, service.getSettings(), service.getAuthMe())) {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.kickPlayer("A player with the same IP is already in game!");
|
player.kickPlayer("A player with the same IP is already in game!");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location spawnLoc = plugin.getSpawnLocation(player);
|
final Location spawnLoc = Spawn.getInstance().getSpawnLocation(player);
|
||||||
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
||||||
if (isAuthAvailable) {
|
if (isAuthAvailable) {
|
||||||
if (!Settings.noTeleport) {
|
if (!Settings.noTeleport) {
|
||||||
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, playerCache.isAuthenticated(name));
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
service.callEvent(tpEvent);
|
||||||
if (!tpEvent.isCancelled() && player.isOnline() && tpEvent.getTo() != null
|
if (!tpEvent.isCancelled() && player.isOnline() && tpEvent.getTo() != null
|
||||||
&& tpEvent.getTo().getWorld() != null) {
|
&& tpEvent.getTo().getWorld() != null) {
|
||||||
player.teleport(tpEvent.getTo());
|
player.teleport(tpEvent.getTo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,12 +124,12 @@ public class AsynchronousJoin {
|
|||||||
if (ev.isCancelled()) {
|
if (ev.isCancelled()) {
|
||||||
plugin.inventoryProtector.sendInventoryPacket(player);
|
plugin.inventoryProtector.sendInventoryPacket(player);
|
||||||
if (!Settings.noConsoleSpam) {
|
if (!Settings.noConsoleSpam) {
|
||||||
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
|
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + "...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.isSessionsEnabled && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) {
|
if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (playerCache.isAuthenticated(name) || database.isLogged(name))) {
|
||||||
if (plugin.sessions.containsKey(name)) {
|
if (plugin.sessions.containsKey(name)) {
|
||||||
plugin.sessions.get(name).cancel();
|
plugin.sessions.get(name).cancel();
|
||||||
plugin.sessions.remove(name);
|
plugin.sessions.remove(name);
|
||||||
@ -137,11 +138,11 @@ public class AsynchronousJoin {
|
|||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
if (auth != null && auth.getIp().equals(ip)) {
|
if (auth != null && auth.getIp().equals(ip)) {
|
||||||
m.send(player, MessageKey.SESSION_RECONNECTION);
|
service.send(player, MessageKey.SESSION_RECONNECTION);
|
||||||
plugin.getManagement().performLogin(player, "dontneed", true);
|
plugin.getManagement().performLogin(player, "dontneed", true);
|
||||||
return;
|
return;
|
||||||
} else if (Settings.sessionExpireOnIpChange) {
|
} else if (Settings.sessionExpireOnIpChange) {
|
||||||
m.send(player, MessageKey.SESSION_EXPIRED);
|
service.send(player, MessageKey.SESSION_EXPIRED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -154,21 +155,18 @@ public class AsynchronousJoin {
|
|||||||
|
|
||||||
if (!Settings.noTeleport && !needFirstSpawn() && Settings.isTeleportToSpawnEnabled
|
if (!Settings.noTeleport && !needFirstSpawn() && Settings.isTeleportToSpawnEnabled
|
||||||
|| (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
|| (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
service.callEvent(tpEvent);
|
||||||
if (!tpEvent.isCancelled() && player.isOnline() && tpEvent.getTo() != null
|
if (!tpEvent.isCancelled() && player.isOnline() && tpEvent.getTo() != null
|
||||||
&& tpEvent.getTo().getWorld() != null) {
|
&& tpEvent.getTo().getWorld() != null) {
|
||||||
player.teleport(tpEvent.getTo());
|
player.teleport(tpEvent.getTo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LimboCache.getInstance().hasLimboPlayer(name)) {
|
if (!LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||||
@ -176,9 +174,9 @@ public class AsynchronousJoin {
|
|||||||
}
|
}
|
||||||
Utils.setGroup(player, isAuthAvailable ? GroupType.NOTLOGGEDIN : GroupType.UNREGISTERED);
|
Utils.setGroup(player, isAuthAvailable ? GroupType.NOTLOGGEDIN : GroupType.UNREGISTERED);
|
||||||
|
|
||||||
final int timeOut = Settings.getRegistrationTimeout * 20;
|
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
|
||||||
|
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
@ -186,27 +184,22 @@ public class AsynchronousJoin {
|
|||||||
player.setFlySpeed(0.0f);
|
player.setFlySpeed(0.0f);
|
||||||
player.setWalkSpeed(0.0f);
|
player.setWalkSpeed(0.0f);
|
||||||
}
|
}
|
||||||
player.setNoDamageTicks(timeOut);
|
player.setNoDamageTicks(registrationTimeout);
|
||||||
if (Settings.useEssentialsMotd) {
|
if (service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
|
||||||
player.performCommand("motd");
|
player.performCommand("motd");
|
||||||
}
|
}
|
||||||
if (Settings.applyBlindEffect) {
|
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||||
int blindTimeOut;
|
|
||||||
// Allow infinite blindness effect
|
// Allow infinite blindness effect
|
||||||
if (timeOut <= 0) {
|
int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout;
|
||||||
blindTimeOut = 99999;
|
|
||||||
} else {
|
|
||||||
blindTimeOut = timeOut;
|
|
||||||
}
|
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
int msgInterval = Settings.getWarnMessageInterval;
|
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||||
if (timeOut > 0) {
|
if (registrationTimeout > 0) {
|
||||||
BukkitTask id = sched.runTaskLater(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout);
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +212,7 @@ public class AsynchronousJoin {
|
|||||||
: MessageKey.REGISTER_MESSAGE;
|
: MessageKey.REGISTER_MESSAGE;
|
||||||
}
|
}
|
||||||
if (msgInterval > 0 && LimboCache.getInstance().getLimboPlayer(name) != null) {
|
if (msgInterval > 0 && LimboCache.getInstance().getLimboPlayer(name) != null) {
|
||||||
BukkitTask msgTask = sched.runTask(plugin, new MessageTask(plugin, name, msg, msgInterval));
|
BukkitTask msgTask = service.runTask(new MessageTask(plugin, name, msg, msgInterval));
|
||||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask);
|
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,13 +228,11 @@ public class AsynchronousJoin {
|
|||||||
if (!tpEvent.isCancelled()) {
|
if (!tpEvent.isCancelled()) {
|
||||||
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
||||||
final Location fLoc = tpEvent.getTo();
|
final Location fLoc = tpEvent.getTo();
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.teleport(fLoc);
|
player.teleport(fLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,25 +240,23 @@ public class AsynchronousJoin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void placePlayerSafely(final Player player, final Location spawnLoc) {
|
private void placePlayerSafely(final Player player, final Location spawnLoc) {
|
||||||
if (spawnLoc == null)
|
if (spawnLoc == null || service.getProperty(RestrictionSettings.NO_TELEPORT))
|
||||||
return;
|
|
||||||
if (!Settings.noTeleport)
|
|
||||||
return;
|
return;
|
||||||
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())))
|
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())))
|
||||||
return;
|
return;
|
||||||
if (!player.hasPlayedBefore())
|
if (!player.hasPlayedBefore())
|
||||||
return;
|
return;
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
service.scheduleSyncDelayedTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (spawnLoc.getWorld() == null) {
|
if (spawnLoc.getWorld() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Material cur = player.getLocation().getBlock().getType();
|
Material cur = player.getLocation().getBlock().getType();
|
||||||
Material top = player.getLocation().add(0D, 1D, 0D).getBlock().getType();
|
Material top = player.getLocation().add(0, 1, 0).getBlock().getType();
|
||||||
if (cur == Material.PORTAL || cur == Material.ENDER_PORTAL
|
if (cur == Material.PORTAL || cur == Material.ENDER_PORTAL
|
||||||
|| top == Material.PORTAL || top == Material.ENDER_PORTAL) {
|
|| top == Material.PORTAL || top == Material.ENDER_PORTAL) {
|
||||||
m.send(player, MessageKey.UNSAFE_QUIT_LOCATION);
|
service.send(player, MessageKey.UNSAFE_QUIT_LOCATION);
|
||||||
player.teleport(spawnLoc);
|
player.teleport(spawnLoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,12 +270,17 @@ public class AsynchronousJoin {
|
|||||||
* @param name The name to check
|
* @param name The name to check
|
||||||
* @param ip The IP address of the player
|
* @param ip The IP address of the player
|
||||||
* @param domain The hostname of the IP address
|
* @param domain The hostname of the IP address
|
||||||
|
* @param settings The settings instance
|
||||||
* @return True if the name is restricted (IP/domain is not allowed for the given name),
|
* @return True if the name is restricted (IP/domain is not allowed for the given name),
|
||||||
* false if the restrictions are met or if the name has no restrictions to it
|
* false if the restrictions are met or if the name has no restrictions to it
|
||||||
*/
|
*/
|
||||||
private static boolean isNameRestricted(String name, String ip, String domain) {
|
private static boolean isNameRestricted(String name, String ip, String domain, NewSetting settings) {
|
||||||
|
if (!settings.getProperty(RestrictionSettings.ENABLE_RESTRICTED_USERS)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
boolean nameFound = false;
|
boolean nameFound = false;
|
||||||
for (String entry : Settings.getRestrictedIp) {
|
for (String entry : settings.getProperty(RestrictionSettings.ALLOWED_RESTRICTED_USERS)) {
|
||||||
String[] args = entry.split(";");
|
String[] args = entry.split(";");
|
||||||
String testName = args[0];
|
String testName = args[0];
|
||||||
String testIp = args[1];
|
String testIp = args[1];
|
||||||
@ -301,4 +295,12 @@ public class AsynchronousJoin {
|
|||||||
return nameFound;
|
return nameFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasJoinedIp(String name, String ip, NewSetting settings, AuthMe authMe) {
|
||||||
|
int count = 0;
|
||||||
|
for (Player player : Utils.getOnlinePlayers()) {
|
||||||
|
if (ip.equalsIgnoreCase(authMe.getIP(player)) && !player.getName().equalsIgnoreCase(name))
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return count >= settings.getProperty(RestrictionSettings.MAX_JOIN_PER_IP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,7 @@ public final class Settings {
|
|||||||
useCaptcha, emailRegistration, multiverse, bungee,
|
useCaptcha, emailRegistration, multiverse, bungee,
|
||||||
banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange,
|
banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange,
|
||||||
disableSocialSpy, useEssentialsMotd, usePurge,
|
disableSocialSpy, useEssentialsMotd, usePurge,
|
||||||
purgePlayerDat, purgeEssentialsFile, supportOldPassword,
|
purgePlayerDat, purgeEssentialsFile,
|
||||||
purgeLimitedCreative, purgeAntiXray, purgePermissions,
|
purgeLimitedCreative, purgeAntiXray, purgePermissions,
|
||||||
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
|
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
|
||||||
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
|
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
|
||||||
@ -72,18 +72,16 @@ public final class Settings {
|
|||||||
getMySQLColumnGroup, unRegisteredGroup,
|
getMySQLColumnGroup, unRegisteredGroup,
|
||||||
backupWindowsPath, getRegisteredGroup,
|
backupWindowsPath, getRegisteredGroup,
|
||||||
rakamakUsers, rakamakUsersIp, getmailAccount, defaultWorld,
|
rakamakUsers, rakamakUsersIp, getmailAccount, defaultWorld,
|
||||||
getPhpbbPrefix, getWordPressPrefix,
|
|
||||||
spawnPriority, crazyloginFileName, getPassRegex, sendPlayerTo;
|
spawnPriority, crazyloginFileName, getPassRegex, sendPlayerTo;
|
||||||
public static int getWarnMessageInterval, getSessionTimeout,
|
public static int getWarnMessageInterval, getSessionTimeout,
|
||||||
getRegistrationTimeout, getMaxNickLength, getMinNickLength,
|
getRegistrationTimeout, getMaxNickLength, getMinNickLength,
|
||||||
getPasswordMinLen, getMovementRadius, getmaxRegPerIp,
|
getPasswordMinLen, getMovementRadius, getmaxRegPerIp,
|
||||||
getNonActivatedGroup, passwordMaxLength, getRecoveryPassLength,
|
getNonActivatedGroup, passwordMaxLength, getRecoveryPassLength,
|
||||||
getMailPort, maxLoginTry, captchaLength, saltLength,
|
getMailPort, maxLoginTry, captchaLength, saltLength,
|
||||||
getmaxRegPerEmail, bCryptLog2Rounds, getPhpbbGroup,
|
getmaxRegPerEmail, bCryptLog2Rounds,
|
||||||
antiBotSensibility, antiBotDuration, delayRecall, getMaxLoginPerIp,
|
antiBotSensibility, antiBotDuration, delayRecall, getMaxLoginPerIp,
|
||||||
getMaxJoinPerIp;
|
getMaxJoinPerIp;
|
||||||
protected static FileConfiguration configFile;
|
protected static FileConfiguration configFile;
|
||||||
private static AuthMe plugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for Settings.
|
* Constructor for Settings.
|
||||||
@ -91,28 +89,27 @@ public final class Settings {
|
|||||||
* @param pl AuthMe
|
* @param pl AuthMe
|
||||||
*/
|
*/
|
||||||
public Settings(AuthMe pl) {
|
public Settings(AuthMe pl) {
|
||||||
plugin = pl;
|
configFile = pl.getConfig();
|
||||||
configFile = plugin.getConfig();
|
|
||||||
loadVariables();
|
loadVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadVariables() {
|
private static void loadVariables() {
|
||||||
isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK);
|
isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK);
|
||||||
isForcedRegistrationEnabled = configFile.getBoolean("settings.registration.force", true);
|
isForcedRegistrationEnabled = configFile.getBoolean("settings.registration.force", true);
|
||||||
isRegistrationEnabled = configFile.getBoolean("settings.registration.enabled", true);
|
isRegistrationEnabled = configFile.getBoolean("settings.registration.enabled", true);
|
||||||
isTeleportToSpawnEnabled = configFile.getBoolean("settings.restrictions.teleportUnAuthedToSpawn", false);
|
isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN);
|
||||||
getWarnMessageInterval = configFile.getInt("settings.registration.messageInterval", 5);
|
getWarnMessageInterval = load(RegistrationSettings.MESSAGE_INTERVAL);
|
||||||
isSessionsEnabled = configFile.getBoolean("settings.sessions.enabled", false);
|
isSessionsEnabled = load(PluginSettings.SESSIONS_ENABLED);
|
||||||
getSessionTimeout = configFile.getInt("settings.sessions.timeout", 10);
|
getSessionTimeout = configFile.getInt("settings.sessions.timeout", 10);
|
||||||
getRegistrationTimeout = configFile.getInt("settings.restrictions.timeout", 30);
|
getRegistrationTimeout = load(RestrictionSettings.TIMEOUT);
|
||||||
isChatAllowed = configFile.getBoolean("settings.restrictions.allowChat", false);
|
isChatAllowed = load(RestrictionSettings.ALLOW_CHAT);
|
||||||
getMaxNickLength = configFile.getInt("settings.restrictions.maxNicknameLength", 20);
|
getMaxNickLength = configFile.getInt("settings.restrictions.maxNicknameLength", 20);
|
||||||
getMinNickLength = configFile.getInt("settings.restrictions.minNicknameLength", 3);
|
getMinNickLength = configFile.getInt("settings.restrictions.minNicknameLength", 3);
|
||||||
getPasswordMinLen = configFile.getInt("settings.security.minPasswordLength", 4);
|
getPasswordMinLen = configFile.getInt("settings.security.minPasswordLength", 4);
|
||||||
getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*");
|
getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*");
|
||||||
nickPattern = Pattern.compile(getNickRegex);
|
nickPattern = Pattern.compile(getNickRegex);
|
||||||
isAllowRestrictedIp = configFile.getBoolean("settings.restrictions.AllowRestrictedUser", false);
|
isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS);
|
||||||
getRestrictedIp = configFile.getStringList("settings.restrictions.AllowedRestrictedUser");
|
getRestrictedIp = load(RestrictionSettings.ALLOWED_RESTRICTED_USERS);
|
||||||
isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false);
|
isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false);
|
||||||
isRemoveSpeedEnabled = configFile.getBoolean("settings.restrictions.removeSpeed", true);
|
isRemoveSpeedEnabled = configFile.getBoolean("settings.restrictions.removeSpeed", true);
|
||||||
getMovementRadius = configFile.getInt("settings.restrictions.allowedMovementRadius", 100);
|
getMovementRadius = configFile.getInt("settings.restrictions.allowedMovementRadius", 100);
|
||||||
@ -170,7 +167,7 @@ public final class Settings {
|
|||||||
useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false);
|
useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false);
|
||||||
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
|
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
|
||||||
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
|
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
|
||||||
emailRegistration = configFile.getBoolean("settings.registration.enableEmailRegistrationSystem", false);
|
emailRegistration = load(RegistrationSettings.USE_EMAIL_REGISTRATION);
|
||||||
saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8);
|
saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8);
|
||||||
getmaxRegPerEmail = configFile.getInt("Email.maxRegPerEmail", 1);
|
getmaxRegPerEmail = configFile.getInt("Email.maxRegPerEmail", 1);
|
||||||
multiverse = load(HooksSettings.MULTIVERSE);
|
multiverse = load(HooksSettings.MULTIVERSE);
|
||||||
@ -188,10 +185,6 @@ public final class Settings {
|
|||||||
purgePlayerDat = configFile.getBoolean("Purge.removePlayerDat", false);
|
purgePlayerDat = configFile.getBoolean("Purge.removePlayerDat", false);
|
||||||
purgeEssentialsFile = configFile.getBoolean("Purge.removeEssentialsFile", false);
|
purgeEssentialsFile = configFile.getBoolean("Purge.removeEssentialsFile", false);
|
||||||
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
|
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
|
||||||
getPhpbbPrefix = configFile.getString("ExternalBoardOptions.phpbbTablePrefix", "phpbb_");
|
|
||||||
getPhpbbGroup = configFile.getInt("ExternalBoardOptions.phpbbActivatedGroupId", 2);
|
|
||||||
supportOldPassword = configFile.getBoolean("settings.security.supportOldPasswordHash", false);
|
|
||||||
getWordPressPrefix = configFile.getString("ExternalBoardOptions.wordpressTablePrefix", "wp_");
|
|
||||||
purgeLimitedCreative = configFile.getBoolean("Purge.removeLimitedCreativesInventories", false);
|
purgeLimitedCreative = configFile.getBoolean("Purge.removeLimitedCreativesInventories", false);
|
||||||
purgeAntiXray = configFile.getBoolean("Purge.removeAntiXRayFile", false);
|
purgeAntiXray = configFile.getBoolean("Purge.removeAntiXRayFile", false);
|
||||||
purgePermissions = configFile.getBoolean("Purge.removePermissions", false);
|
purgePermissions = configFile.getBoolean("Purge.removePermissions", false);
|
||||||
@ -211,13 +204,13 @@ public final class Settings {
|
|||||||
forceRegKick = configFile.getBoolean("settings.registration.forceKickAfterRegister", false);
|
forceRegKick = configFile.getBoolean("settings.registration.forceKickAfterRegister", false);
|
||||||
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
|
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
|
||||||
spawnPriority = load(RestrictionSettings.SPAWN_PRIORITY);
|
spawnPriority = load(RestrictionSettings.SPAWN_PRIORITY);
|
||||||
getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0);
|
getMaxLoginPerIp = load(RestrictionSettings.MAX_LOGIN_PER_IP);
|
||||||
getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0);
|
getMaxJoinPerIp = load(RestrictionSettings.MAX_JOIN_PER_IP);
|
||||||
checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false);
|
checkVeryGames = load(HooksSettings.ENABLE_VERYGAMES_IP_CHECK);
|
||||||
removeJoinMessage = load(RegistrationSettings.REMOVE_JOIN_MESSAGE);
|
removeJoinMessage = load(RegistrationSettings.REMOVE_JOIN_MESSAGE);
|
||||||
removeLeaveMessage = load(RegistrationSettings.REMOVE_LEAVE_MESSAGE);
|
removeLeaveMessage = load(RegistrationSettings.REMOVE_LEAVE_MESSAGE);
|
||||||
delayJoinMessage = load(RegistrationSettings.DELAY_JOIN_MESSAGE);
|
delayJoinMessage = load(RegistrationSettings.DELAY_JOIN_MESSAGE);
|
||||||
noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false);
|
noTeleport = load(RestrictionSettings.NO_TELEPORT);
|
||||||
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
|
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
|
||||||
getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
|
getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
|
||||||
applyBlindEffect = configFile.getBoolean("settings.applyBlindEffect", false);
|
applyBlindEffect = configFile.getBoolean("settings.applyBlindEffect", false);
|
||||||
|
|||||||
@ -64,7 +64,7 @@ public class RestrictionSettings implements SettingsClass {
|
|||||||
|
|
||||||
@Comment({
|
@Comment({
|
||||||
"To activate the restricted user feature you need",
|
"To activate the restricted user feature you need",
|
||||||
"to enable this option and configure the AllowedRestrctedUser field."})
|
"to enable this option and configure the AllowedRestrictedUser field."})
|
||||||
public static final Property<Boolean> ENABLE_RESTRICTED_USERS =
|
public static final Property<Boolean> ENABLE_RESTRICTED_USERS =
|
||||||
newProperty("settings.restrictions.AllowRestrictedUser", false);
|
newProperty("settings.restrictions.AllowRestrictedUser", false);
|
||||||
|
|
||||||
|
|||||||
@ -53,12 +53,12 @@ public class ChangePasswordTask implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF("Forward");
|
out.writeUTF("Forward");
|
||||||
out.writeUTF("ALL");
|
out.writeUTF("ALL");
|
||||||
out.writeUTF("AuthMe");
|
out.writeUTF("AuthMe");
|
||||||
out.writeUTF("changepassword;" + name + ";" + hash + ";" + salt);
|
out.writeUTF("changepassword;" + name + ";" + hash + ";" + salt);
|
||||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -154,8 +154,7 @@ public final class Utils {
|
|||||||
|
|
||||||
public static boolean isUnrestricted(Player player) {
|
public static boolean isUnrestricted(Player player) {
|
||||||
return Settings.isAllowRestrictedIp
|
return Settings.isAllowRestrictedIp
|
||||||
&& !Settings.getUnrestrictedName.isEmpty()
|
&& Settings.getUnrestrictedName.contains(player.getName().toLowerCase());
|
||||||
&& (Settings.getUnrestrictedName.contains(player.getName().toLowerCase()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void packCoords(double x, double y, double z, String w, final Player pl) {
|
public static void packCoords(double x, double y, double z, String w, final Player pl) {
|
||||||
@ -216,8 +215,7 @@ public final class Utils {
|
|||||||
ConsoleLogger.showError("Unknown list of online players of type " + type);
|
ConsoleLogger.showError("Unknown list of online players of type " + type);
|
||||||
}
|
}
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||||
ConsoleLogger.showError("Could not retrieve list of online players: ["
|
ConsoleLogger.logException("Could not retrieve list of online players:", e);
|
||||||
+ e.getClass().getName() + "] " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
package fr.xephi.authme.process.email;
|
package fr.xephi.authme.process.email;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLoggerTestInitializer;
|
import fr.xephi.authme.ConsoleLoggerTestInitializer;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.output.Messages;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.util.WrapperMock;
|
import fr.xephi.authme.util.WrapperMock;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -27,11 +26,10 @@ import static org.mockito.Mockito.when;
|
|||||||
*/
|
*/
|
||||||
public class AsyncAddEmailTest {
|
public class AsyncAddEmailTest {
|
||||||
|
|
||||||
private Messages messages;
|
|
||||||
private Player player;
|
private Player player;
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
private NewSetting settings;
|
private ProcessService service;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
@ -42,10 +40,10 @@ public class AsyncAddEmailTest {
|
|||||||
// Clean up the fields to ensure that no test uses elements of another test
|
// Clean up the fields to ensure that no test uses elements of another test
|
||||||
@After
|
@After
|
||||||
public void removeFieldValues() {
|
public void removeFieldValues() {
|
||||||
messages = null;
|
|
||||||
player = null;
|
player = null;
|
||||||
dataSource = null;
|
dataSource = null;
|
||||||
playerCache = null;
|
playerCache = null;
|
||||||
|
service = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -61,11 +59,11 @@ public class AsyncAddEmailTest {
|
|||||||
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(true);
|
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(dataSource).updateEmail(auth);
|
verify(dataSource).updateEmail(auth);
|
||||||
verify(messages).send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
verify(service).send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
||||||
verify(auth).setEmail("my.mail@example.org");
|
verify(auth).setEmail("my.mail@example.org");
|
||||||
verify(playerCache).updatePlayer(auth);
|
verify(playerCache).updatePlayer(auth);
|
||||||
}
|
}
|
||||||
@ -83,11 +81,11 @@ public class AsyncAddEmailTest {
|
|||||||
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(false);
|
given(dataSource.updateEmail(any(PlayerAuth.class))).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(dataSource).updateEmail(auth);
|
verify(dataSource).updateEmail(auth);
|
||||||
verify(messages).send(player, MessageKey.ERROR);
|
verify(service).send(player, MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -102,10 +100,10 @@ public class AsyncAddEmailTest {
|
|||||||
given(dataSource.isEmailStored("some.mail@example.org")).willReturn(false);
|
given(dataSource.isEmailStored("some.mail@example.org")).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(messages).send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
verify(service).send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
||||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +119,10 @@ public class AsyncAddEmailTest {
|
|||||||
given(dataSource.isEmailStored("invalid_mail")).willReturn(false);
|
given(dataSource.isEmailStored("invalid_mail")).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(messages).send(player, MessageKey.INVALID_EMAIL);
|
verify(service).send(player, MessageKey.INVALID_EMAIL);
|
||||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,10 +138,10 @@ public class AsyncAddEmailTest {
|
|||||||
given(dataSource.isEmailStored("player@mail.tld")).willReturn(true);
|
given(dataSource.isEmailStored("player@mail.tld")).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(messages).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
verify(service).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,10 +154,10 @@ public class AsyncAddEmailTest {
|
|||||||
given(dataSource.isAuthAvailable("Username12")).willReturn(true);
|
given(dataSource.isAuthAvailable("Username12")).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(messages).send(player, MessageKey.LOGIN_MESSAGE);
|
verify(service).send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,13 +168,13 @@ public class AsyncAddEmailTest {
|
|||||||
given(player.getName()).willReturn("user");
|
given(player.getName()).willReturn("user");
|
||||||
given(playerCache.isAuthenticated("user")).willReturn(false);
|
given(playerCache.isAuthenticated("user")).willReturn(false);
|
||||||
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
||||||
Settings.emailRegistration = true;
|
given(service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(messages).send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
verify(service).send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,13 +185,13 @@ public class AsyncAddEmailTest {
|
|||||||
given(player.getName()).willReturn("user");
|
given(player.getName()).willReturn("user");
|
||||||
given(playerCache.isAuthenticated("user")).willReturn(false);
|
given(playerCache.isAuthenticated("user")).willReturn(false);
|
||||||
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
||||||
Settings.emailRegistration = false;
|
given(service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.process();
|
process.run();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(messages).send(player, MessageKey.REGISTER_MESSAGE);
|
verify(service).send(player, MessageKey.REGISTER_MESSAGE);
|
||||||
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,14 +202,12 @@ public class AsyncAddEmailTest {
|
|||||||
* @return The created process
|
* @return The created process
|
||||||
*/
|
*/
|
||||||
private AsyncAddEmail createProcess(String email) {
|
private AsyncAddEmail createProcess(String email) {
|
||||||
messages = mock(Messages.class);
|
|
||||||
AuthMe authMe = mock(AuthMe.class);
|
|
||||||
when(authMe.getMessages()).thenReturn(messages);
|
|
||||||
player = mock(Player.class);
|
player = mock(Player.class);
|
||||||
dataSource = mock(DataSource.class);
|
dataSource = mock(DataSource.class);
|
||||||
playerCache = mock(PlayerCache.class);
|
playerCache = mock(PlayerCache.class);
|
||||||
settings = mock(NewSetting.class);
|
service = mock(ProcessService.class);
|
||||||
return new AsyncAddEmail(player, authMe, email, dataSource, playerCache, settings);
|
when(service.getSettings()).thenReturn(mock(NewSetting.class));
|
||||||
|
return new AsyncAddEmail(player, email, dataSource, playerCache, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user