mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-08 03:29:41 +01:00
- Create IP address manager for handling and caching IP addresses -> outside of the manager I do not want to care about caching details - Make more processes use the ProcessService in favor of statically injected objects
This commit is contained in:
parent
86042070e9
commit
aeb8307a46
@ -1,8 +1,6 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
@ -35,6 +33,7 @@ import fr.xephi.authme.listener.AuthMeServerListener;
|
||||
import fr.xephi.authme.listener.AuthMeTabCompletePacketAdapter;
|
||||
import fr.xephi.authme.listener.AuthMeTablistPacketAdapter;
|
||||
import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.manager.IpAddressManager;
|
||||
import fr.xephi.authme.output.ConsoleFilter;
|
||||
import fr.xephi.authme.output.Log4JFilter;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
@ -74,8 +73,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
@ -113,7 +110,7 @@ public class AuthMe extends JavaPlugin {
|
||||
public final ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, String> realIp = new ConcurrentHashMap<>();
|
||||
|
||||
/*
|
||||
* Public Instances
|
||||
* TODO #432: Encapsulation
|
||||
@ -141,6 +138,7 @@ public class AuthMe extends JavaPlugin {
|
||||
private JsonCache playerBackup;
|
||||
private PasswordSecurity passwordSecurity;
|
||||
private DataSource database;
|
||||
private IpAddressManager ipAddressManager;
|
||||
|
||||
/**
|
||||
* Get the plugin's instance.
|
||||
@ -253,10 +251,11 @@ public class AuthMe extends JavaPlugin {
|
||||
MigrationService.changePlainTextToSha256(newSettings, database, new SHA256());
|
||||
passwordSecurity = new PasswordSecurity(getDataSource(), newSettings.getProperty(SecuritySettings.PASSWORD_HASH),
|
||||
Bukkit.getPluginManager(), newSettings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH));
|
||||
ipAddressManager = new IpAddressManager(newSettings);
|
||||
|
||||
// Set up the permissions manager and command handler
|
||||
permsMan = initializePermissionsManager();
|
||||
commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings);
|
||||
commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings, ipAddressManager);
|
||||
|
||||
// Setup otherAccounts file
|
||||
this.otherAccounts = OtherAccounts.getInstance();
|
||||
@ -305,11 +304,11 @@ public class AuthMe extends JavaPlugin {
|
||||
setupApi();
|
||||
|
||||
// Set up the management
|
||||
ProcessService processService = new ProcessService(newSettings, messages, this);
|
||||
ProcessService processService = new ProcessService(newSettings, messages, this, ipAddressManager);
|
||||
management = new Management(this, processService, database, PlayerCache.getInstance());
|
||||
|
||||
// Set up the BungeeCord hook
|
||||
setupBungeeCordHook();
|
||||
setupBungeeCordHook(newSettings, ipAddressManager);
|
||||
|
||||
// Reload support hook
|
||||
reloadSupportHook();
|
||||
@ -410,20 +409,22 @@ public class AuthMe extends JavaPlugin {
|
||||
/**
|
||||
* Set up the BungeeCord hook.
|
||||
*/
|
||||
private void setupBungeeCordHook() {
|
||||
if (newSettings.getProperty(HooksSettings.BUNGEECORD)) {
|
||||
private void setupBungeeCordHook(NewSetting settings, IpAddressManager ipAddressManager) {
|
||||
if (settings.getProperty(HooksSettings.BUNGEECORD)) {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordMessage(this));
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(
|
||||
this, "BungeeCord", new BungeeCordMessage(this, ipAddressManager));
|
||||
}
|
||||
}
|
||||
|
||||
private CommandHandler initializeCommandHandler(PermissionsManager permissionsManager, Messages messages,
|
||||
PasswordSecurity passwordSecurity, NewSetting settings) {
|
||||
PasswordSecurity passwordSecurity, NewSetting settings,
|
||||
IpAddressManager ipAddressManager) {
|
||||
HelpProvider helpProvider = new HelpProvider(permissionsManager, settings.getProperty(HELP_HEADER));
|
||||
Set<CommandDescription> baseCommands = CommandInitializer.buildCommands();
|
||||
CommandMapper mapper = new CommandMapper(baseCommands, permissionsManager);
|
||||
CommandService commandService = new CommandService(
|
||||
this, mapper, helpProvider, messages, passwordSecurity, permissionsManager, settings);
|
||||
this, mapper, helpProvider, messages, passwordSecurity, permissionsManager, settings, ipAddressManager);
|
||||
return new CommandHandler(commandService);
|
||||
}
|
||||
|
||||
@ -804,59 +805,28 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
public String replaceAllInfo(String message, Player player) {
|
||||
String playersOnline = Integer.toString(Utils.getOnlinePlayers().size());
|
||||
String ipAddress = ipAddressManager.getPlayerIp(player);
|
||||
return message
|
||||
.replace("&", "\u00a7")
|
||||
.replace("{PLAYER}", player.getName())
|
||||
.replace("{ONLINE}", playersOnline)
|
||||
.replace("{MAXPLAYERS}", Integer.toString(server.getMaxPlayers()))
|
||||
.replace("{IP}", getIP(player))
|
||||
.replace("{IP}", ipAddress)
|
||||
.replace("{LOGINS}", Integer.toString(PlayerCache.getInstance().getLogged()))
|
||||
.replace("{WORLD}", player.getWorld().getName())
|
||||
.replace("{SERVER}", server.getServerName())
|
||||
.replace("{VERSION}", server.getBukkitVersion())
|
||||
.replace("{COUNTRY}", GeoLiteAPI.getCountryName(getIP(player)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player's real IP through VeryGames method.
|
||||
*
|
||||
* @param player The player to process.
|
||||
*/
|
||||
@Deprecated
|
||||
public void getVerygamesIp(final Player player) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
String currentIp = player.getAddress().getAddress().getHostAddress();
|
||||
if (realIp.containsKey(name)) {
|
||||
currentIp = realIp.get(name);
|
||||
}
|
||||
String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
|
||||
sUrl = sUrl.replace("%IP%", currentIp).replace("%PORT%", "" + player.getAddress().getPort());
|
||||
try {
|
||||
String result = Resources.toString(new URL(sUrl), Charsets.UTF_8);
|
||||
if (!StringUtils.isEmpty(result) && !result.equalsIgnoreCase("error") && !result.contains("error")) {
|
||||
currentIp = result;
|
||||
realIp.put(name, currentIp);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Could not fetch Very Games API with URL '" +
|
||||
sUrl + "' - " + StringUtils.formatException(e));
|
||||
}
|
||||
}
|
||||
|
||||
public String getIP(final Player player) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
String ip = player.getAddress().getAddress().getHostAddress();
|
||||
if (realIp.containsKey(name)) {
|
||||
ip = realIp.get(name);
|
||||
}
|
||||
return ip;
|
||||
.replace("{COUNTRY}", GeoLiteAPI.getCountryName(ipAddress));
|
||||
}
|
||||
|
||||
public boolean isLoggedIp(String name, String ip) {
|
||||
int count = 0;
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
if (ip.equalsIgnoreCase(getIP(player)) && database.isLogged(player.getName().toLowerCase()) && !player.getName().equalsIgnoreCase(name))
|
||||
count++;
|
||||
if (ip.equalsIgnoreCase(ipAddressManager.getPlayerIp(player))
|
||||
&& database.isLogged(player.getName().toLowerCase())
|
||||
&& !player.getName().equalsIgnoreCase(name)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count >= Settings.getMaxLoginPerIp;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package fr.xephi.authme.command;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.manager.IpAddressManager;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
@ -28,6 +29,7 @@ public class CommandService {
|
||||
private final PasswordSecurity passwordSecurity;
|
||||
private final PermissionsManager permissionsManager;
|
||||
private final NewSetting settings;
|
||||
private final IpAddressManager ipAddressManager;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -41,8 +43,8 @@ public class CommandService {
|
||||
* @param settings The settings manager
|
||||
*/
|
||||
public CommandService(AuthMe authMe, CommandMapper commandMapper, HelpProvider helpProvider, Messages messages,
|
||||
PasswordSecurity passwordSecurity, PermissionsManager permissionsManager,
|
||||
NewSetting settings) {
|
||||
PasswordSecurity passwordSecurity, PermissionsManager permissionsManager, NewSetting settings,
|
||||
IpAddressManager ipAddressManager) {
|
||||
this.authMe = authMe;
|
||||
this.messages = messages;
|
||||
this.helpProvider = helpProvider;
|
||||
@ -50,6 +52,7 @@ public class CommandService {
|
||||
this.passwordSecurity = passwordSecurity;
|
||||
this.permissionsManager = permissionsManager;
|
||||
this.settings = settings;
|
||||
this.ipAddressManager = ipAddressManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,4 +195,8 @@ public class CommandService {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public IpAddressManager getIpAddressManager() {
|
||||
return ipAddressManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,18 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import java.util.List;
|
||||
|
||||
public class GetIpCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the player query
|
||||
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
|
||||
|
||||
@ -25,9 +22,12 @@ public class GetIpCommand implements ExecutableCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO ljacqu 20151212: Revise the messages (actual IP vs. real IP...?)
|
||||
sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress()
|
||||
sender.sendMessage(player.getName() + "'s IP is: " + player.getAddress().getAddress().getHostAddress()
|
||||
+ ":" + player.getAddress().getPort());
|
||||
sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player));
|
||||
|
||||
if (commandService.getProperty(HooksSettings.ENABLE_VERYGAMES_IP_CHECK)) {
|
||||
sender.sendMessage(player.getName() + "'s real IP is: "
|
||||
+ commandService.getIpAddressManager().getPlayerIp(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ 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.manager.IpAddressManager;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
@ -15,30 +16,32 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
*/
|
||||
public class BungeeCordMessage implements PluginMessageListener {
|
||||
|
||||
public final AuthMe plugin;
|
||||
private final AuthMe plugin;
|
||||
private final IpAddressManager ipAddressManager;
|
||||
|
||||
/**
|
||||
* Constructor for BungeeCordMessage.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
*/
|
||||
public BungeeCordMessage(AuthMe plugin) {
|
||||
public BungeeCordMessage(AuthMe plugin, IpAddressManager ipAddressManager) {
|
||||
this.plugin = plugin;
|
||||
this.ipAddressManager = ipAddressManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if (!channel.equals("BungeeCord")) {
|
||||
if (!"BungeeCord".equals(channel)) {
|
||||
return;
|
||||
}
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||
String subChannel = in.readUTF();
|
||||
if (subChannel.equals("IP")) { // We need only the IP channel
|
||||
if ("IP".equals(subChannel)) { // We need only the IP channel
|
||||
String ip = in.readUTF();
|
||||
// Put the IP (only the ip not the port) in the hashMap
|
||||
plugin.realIp.put(player.getName().toLowerCase(), ip);
|
||||
ipAddressManager.addCache(player.getName(), ip);
|
||||
}
|
||||
if (subChannel.equalsIgnoreCase("AuthMe")) {
|
||||
if ("AuthMe".equalsIgnoreCase(subChannel)) {
|
||||
String str = in.readUTF();
|
||||
final String[] args = str.split(";");
|
||||
final String act = args[0];
|
||||
@ -65,10 +68,10 @@ public class BungeeCordMessage implements PluginMessageListener {
|
||||
ConsoleLogger.info("Player " + auth.getNickname()
|
||||
+ " has registered out from one of your server!");
|
||||
} else if ("changepassword".equals(act)) {
|
||||
final String password = args[2];
|
||||
final String password = args[2];
|
||||
final String salt = args.length >= 4 ? args[3] : null;
|
||||
auth.setPassword(new HashedPassword(password, salt));
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
auth.setPassword(new HashedPassword(password, salt));
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
dataSource.updatePassword(auth);
|
||||
}
|
||||
|
||||
|
79
src/main/java/fr/xephi/authme/manager/IpAddressManager.java
Normal file
79
src/main/java/fr/xephi/authme/manager/IpAddressManager.java
Normal file
@ -0,0 +1,79 @@
|
||||
package fr.xephi.authme.manager;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Stateful manager for looking up IP address appropriately, including caching.
|
||||
*/
|
||||
public class IpAddressManager {
|
||||
|
||||
/** Cache for IP lookups per player. */
|
||||
private final ConcurrentHashMap<String, String> ipCache;
|
||||
/** Whether or not to use the VeryGames API for IP lookups. */
|
||||
private final boolean useVeryGamesIpCheck;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param settings The settings instance
|
||||
*/
|
||||
public IpAddressManager(NewSetting settings) {
|
||||
this.useVeryGamesIpCheck = settings.getProperty(HooksSettings.ENABLE_VERYGAMES_IP_CHECK);
|
||||
this.ipCache = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public String getPlayerIp(Player player) {
|
||||
final String playerName = player.getName().toLowerCase();
|
||||
final String cachedValue = ipCache.get(playerName);
|
||||
if (cachedValue != null) {
|
||||
return cachedValue;
|
||||
}
|
||||
|
||||
final String plainIp = player.getAddress().getAddress().getHostAddress();
|
||||
if (useVeryGamesIpCheck) {
|
||||
String veryGamesResult = getVeryGamesIp(plainIp, player.getAddress().getPort());
|
||||
if (veryGamesResult != null) {
|
||||
ipCache.put(playerName, veryGamesResult);
|
||||
return veryGamesResult;
|
||||
}
|
||||
} else {
|
||||
ipCache.put(playerName, plainIp);
|
||||
}
|
||||
return plainIp;
|
||||
}
|
||||
|
||||
public void addCache(String player, String ip) {
|
||||
ipCache.put(player.toLowerCase(), ip);
|
||||
}
|
||||
|
||||
public void removeCache(String player) {
|
||||
ipCache.remove(player.toLowerCase());
|
||||
}
|
||||
|
||||
// returns null if IP could not be looked up --> expect that it won't be cached
|
||||
private String getVeryGamesIp(final String plainIp, final int port) {
|
||||
final String sUrl = String.format("http://monitor-1.verygames.net/api/?action=ipclean-real-ip"
|
||||
+ "&out=raw&ip=%s&port=%d", plainIp, port);
|
||||
|
||||
try {
|
||||
String result = Resources.toString(new URL(sUrl), Charsets.UTF_8);
|
||||
if (!StringUtils.isEmpty(result) && !result.contains("error")) {
|
||||
return result;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.logException("Could not fetch Very Games API with URL '" + sUrl + "':", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -43,14 +43,7 @@ public class Management {
|
||||
}
|
||||
|
||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new AsynchronousLogin(player, password, forceLogin, plugin, dataSource, settings)
|
||||
.process();
|
||||
}
|
||||
});
|
||||
runTask(new AsynchronousLogin(player, password, forceLogin, plugin, dataSource, processService));
|
||||
}
|
||||
|
||||
public void performLogout(final Player player) {
|
||||
@ -64,23 +57,11 @@ public class Management {
|
||||
}
|
||||
|
||||
public void performRegister(final Player player, final String password, final String email) {
|
||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new AsyncRegister(player, password, email, plugin, dataSource, settings).process();
|
||||
}
|
||||
});
|
||||
runTask(new AsyncRegister(player, password, email, plugin, dataSource, processService));
|
||||
}
|
||||
|
||||
public void performUnregister(final Player player, final String password, final boolean force) {
|
||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new AsynchronousUnregister(player, password, force, plugin).process();
|
||||
}
|
||||
});
|
||||
runTask(new AsynchronousUnregister(player, password, force, plugin, processService));
|
||||
}
|
||||
|
||||
public void performJoin(final Player player) {
|
||||
@ -88,14 +69,7 @@ public class Management {
|
||||
}
|
||||
|
||||
public void performQuit(final Player player, final boolean isKick) {
|
||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new AsynchronousQuit(player, plugin, dataSource, isKick).process();
|
||||
}
|
||||
|
||||
});
|
||||
runTask(new AsynchronousQuit(player, plugin, dataSource, isKick, processService));
|
||||
}
|
||||
|
||||
public void performAddEmail(final Player player, final String newEmail) {
|
||||
@ -103,12 +77,7 @@ public class Management {
|
||||
}
|
||||
|
||||
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new AsyncChangeEmail(player, plugin, oldEmail, newEmail, dataSource, playerCache, settings).process();
|
||||
}
|
||||
});
|
||||
runTask(new AsyncChangeEmail(player, plugin, oldEmail, newEmail, dataSource, playerCache, settings));
|
||||
}
|
||||
|
||||
private void runTask(Process process) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.manager.IpAddressManager;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
@ -17,11 +18,13 @@ public class ProcessService {
|
||||
private final NewSetting settings;
|
||||
private final Messages messages;
|
||||
private final AuthMe authMe;
|
||||
private final IpAddressManager ipAddressManager;
|
||||
|
||||
public ProcessService(NewSetting settings, Messages messages, AuthMe authMe) {
|
||||
public ProcessService(NewSetting settings, Messages messages, AuthMe authMe, IpAddressManager ipAddressManager) {
|
||||
this.settings = settings;
|
||||
this.messages = messages;
|
||||
this.authMe = authMe;
|
||||
this.ipAddressManager = ipAddressManager;
|
||||
}
|
||||
|
||||
public <T> T getProperty(Property<T> property) {
|
||||
@ -36,7 +39,15 @@ public class ProcessService {
|
||||
messages.send(sender, key);
|
||||
}
|
||||
|
||||
public String retrieveMessage(MessageKey key) {
|
||||
public void send(CommandSender sender, MessageKey key, String... replacements) {
|
||||
messages.send(sender, key, replacements);
|
||||
}
|
||||
|
||||
public String[] retrieveMessage(MessageKey key) {
|
||||
return messages.retrieve(key);
|
||||
}
|
||||
|
||||
public String retrieveSingleMessage(MessageKey key) {
|
||||
return messages.retrieveSingle(key);
|
||||
}
|
||||
|
||||
@ -60,4 +71,8 @@ public class ProcessService {
|
||||
return authMe;
|
||||
}
|
||||
|
||||
public IpAddressManager getIpAddressManager() {
|
||||
return ipAddressManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
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.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
@ -14,7 +15,7 @@ import org.bukkit.entity.Player;
|
||||
/**
|
||||
* Async task for changing the email.
|
||||
*/
|
||||
public class AsyncChangeEmail {
|
||||
public class AsyncChangeEmail implements Process {
|
||||
|
||||
private final Player player;
|
||||
private final String oldEmail;
|
||||
@ -35,7 +36,8 @@ public class AsyncChangeEmail {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@Override
|
||||
public void run() {
|
||||
String playerName = player.getName().toLowerCase();
|
||||
if (playerCache.isAuthenticated(playerName)) {
|
||||
PlayerAuth auth = playerCache.getAuth(playerName);
|
||||
|
@ -59,15 +59,11 @@ public class AsynchronousJoin implements Process {
|
||||
return;
|
||||
}
|
||||
|
||||
if (service.getProperty(HooksSettings.ENABLE_VERYGAMES_IP_CHECK)) {
|
||||
plugin.getVerygamesIp(player);
|
||||
}
|
||||
|
||||
if (plugin.ess != null && service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) {
|
||||
plugin.ess.getUser(player).setSocialSpyEnabled(false);
|
||||
}
|
||||
|
||||
final String ip = plugin.getIP(player);
|
||||
final String ip = service.getIpAddressManager().getPlayerIp(player);
|
||||
|
||||
|
||||
if (isNameRestricted(name, ip, player.getAddress().getHostName(), service.getSettings())) {
|
||||
@ -75,7 +71,7 @@ public class AsynchronousJoin implements Process {
|
||||
@Override
|
||||
public void run() {
|
||||
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
|
||||
player.kickPlayer(service.retrieveMessage(MessageKey.NOT_OWNER_ERROR));
|
||||
player.kickPlayer(service.retrieveSingleMessage(MessageKey.NOT_OWNER_ERROR));
|
||||
if (Settings.banUnsafeIp) {
|
||||
plugin.getServer().banIP(ip);
|
||||
}
|
||||
@ -87,7 +83,7 @@ public class AsynchronousJoin implements Process {
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& !"127.0.0.1".equalsIgnoreCase(ip)
|
||||
&& !"localhost".equalsIgnoreCase(ip)
|
||||
&& hasJoinedIp(player.getName(), ip, service.getSettings(), service.getAuthMe())) {
|
||||
&& hasJoinedIp(player.getName(), ip, service.getSettings())) {
|
||||
service.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -295,11 +291,13 @@ public class AsynchronousJoin implements Process {
|
||||
return nameFound;
|
||||
}
|
||||
|
||||
private boolean hasJoinedIp(String name, String ip, NewSetting settings, AuthMe authMe) {
|
||||
private boolean hasJoinedIp(String name, String ip, NewSetting settings) {
|
||||
int count = 0;
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
if (ip.equalsIgnoreCase(authMe.getIP(player)) && !player.getName().equalsIgnoreCase(name))
|
||||
if (ip.equalsIgnoreCase(service.getIpAddressManager().getPlayerIp(player))
|
||||
&& !player.getName().equalsIgnoreCase(name)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count >= settings.getProperty(RestrictionSettings.MAX_JOIN_PER_IP);
|
||||
}
|
||||
|
@ -8,14 +8,15 @@ import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.Process;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
@ -27,7 +28,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AsynchronousLogin {
|
||||
public class AsynchronousLogin implements Process {
|
||||
|
||||
private final Player player;
|
||||
private final String name;
|
||||
@ -36,23 +37,11 @@ public class AsynchronousLogin {
|
||||
private final boolean forceLogin;
|
||||
private final AuthMe plugin;
|
||||
private final DataSource database;
|
||||
private final Messages m;
|
||||
private final String ip;
|
||||
private final NewSetting settings;
|
||||
private final ProcessService service;
|
||||
|
||||
/**
|
||||
* Constructor for AsynchronousLogin.
|
||||
*
|
||||
* @param player Player
|
||||
* @param password String
|
||||
* @param forceLogin boolean
|
||||
* @param plugin AuthMe
|
||||
* @param data DataSource
|
||||
* @param settings The settings
|
||||
*/
|
||||
public AsynchronousLogin(Player player, String password, boolean forceLogin, AuthMe plugin, DataSource data,
|
||||
NewSetting settings) {
|
||||
this.m = plugin.getMessages();
|
||||
ProcessService service) {
|
||||
this.player = player;
|
||||
this.name = player.getName().toLowerCase();
|
||||
this.password = password;
|
||||
@ -60,12 +49,12 @@ public class AsynchronousLogin {
|
||||
this.forceLogin = forceLogin;
|
||||
this.plugin = plugin;
|
||||
this.database = data;
|
||||
this.ip = plugin.getIP(player);
|
||||
this.settings = settings;
|
||||
this.ip = service.getIpAddressManager().getPlayerIp(player);
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
private boolean needsCaptcha() {
|
||||
if (Settings.useCaptcha) {
|
||||
if (service.getProperty(SecuritySettings.USE_CAPTCHA)) {
|
||||
if (!plugin.captcha.containsKey(name)) {
|
||||
plugin.captcha.putIfAbsent(name, 1);
|
||||
} else {
|
||||
@ -75,7 +64,7 @@ public class AsynchronousLogin {
|
||||
}
|
||||
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) > Settings.maxLoginTry) {
|
||||
plugin.cap.putIfAbsent(name, RandomString.generate(Settings.captchaLength));
|
||||
m.send(player, MessageKey.USAGE_CAPTCHA, plugin.cap.get(name));
|
||||
service.send(player, MessageKey.USAGE_CAPTCHA, plugin.cap.get(name));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -90,30 +79,27 @@ public class AsynchronousLogin {
|
||||
*/
|
||||
private PlayerAuth preAuth() {
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return null;
|
||||
}
|
||||
|
||||
PlayerAuth pAuth = database.getAuth(name);
|
||||
if (pAuth == null) {
|
||||
m.send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
service.send(player, MessageKey.USER_NOT_REGISTERED);
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId().cancel();
|
||||
String[] msg;
|
||||
if (Settings.emailRegistration) {
|
||||
msg = m.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||
} else {
|
||||
msg = m.retrieve(MessageKey.REGISTER_MESSAGE);
|
||||
}
|
||||
BukkitTask msgT = Bukkit.getScheduler().runTask(plugin,
|
||||
new MessageTask(plugin, name, msg, settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||
String[] msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? service.retrieveMessage(MessageKey.REGISTER_EMAIL_MESSAGE)
|
||||
: service.retrieveMessage(MessageKey.REGISTER_MESSAGE);
|
||||
BukkitTask messageTask = service.runTask(
|
||||
new MessageTask(plugin, name, msg, service.getProperty(RegistrationSettings.MESSAGE_INTERVAL)));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(messageTask);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Settings.getMySQLColumnGroup.isEmpty() && pAuth.getGroupId() == Settings.getNonActivatedGroup) {
|
||||
m.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -121,7 +107,7 @@ public class AsynchronousLogin {
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("localhost")) {
|
||||
if (plugin.isLoggedIp(name, ip)) {
|
||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -134,7 +120,8 @@ public class AsynchronousLogin {
|
||||
return pAuth;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerAuth pAuth = preAuth();
|
||||
if (pAuth == null || needsCaptcha()) {
|
||||
return;
|
||||
@ -170,12 +157,12 @@ public class AsynchronousLogin {
|
||||
|
||||
player.setNoDamageTicks(0);
|
||||
if (!forceLogin)
|
||||
m.send(player, MessageKey.LOGIN_SUCCESS);
|
||||
service.send(player, MessageKey.LOGIN_SUCCESS);
|
||||
|
||||
displayOtherAccounts(auth);
|
||||
|
||||
if (Settings.recallEmail && (StringUtils.isEmpty(email) || "your@email.com".equalsIgnoreCase(email))) {
|
||||
m.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||
service.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||
}
|
||||
|
||||
if (!Settings.noConsoleSpam) {
|
||||
@ -191,7 +178,8 @@ public class AsynchronousLogin {
|
||||
// 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.
|
||||
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(player, plugin, database, settings);
|
||||
ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(
|
||||
player, plugin, database, service.getSettings());
|
||||
if (syncPlayerLogin.getLimbo() != null) {
|
||||
if (syncPlayerLogin.getLimbo().getTimeoutTaskId() != null) {
|
||||
syncPlayerLogin.getLimbo().getTimeoutTaskId().cancel();
|
||||
@ -206,14 +194,13 @@ public class AsynchronousLogin {
|
||||
ConsoleLogger.info(realName + " used the wrong password");
|
||||
if (Settings.isKickOnWrongPasswordEnabled) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.kickPlayer(m.retrieveSingle(MessageKey.WRONG_PASSWORD));
|
||||
player.kickPlayer(service.retrieveSingleMessage(MessageKey.WRONG_PASSWORD));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
m.send(player, MessageKey.WRONG_PASSWORD);
|
||||
service.send(player, MessageKey.WRONG_PASSWORD);
|
||||
}
|
||||
} else {
|
||||
ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... ");
|
||||
|
@ -7,7 +7,10 @@ import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.process.Process;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -15,7 +18,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class AsynchronousQuit {
|
||||
public class AsynchronousQuit implements Process {
|
||||
|
||||
private final AuthMe plugin;
|
||||
private final DataSource database;
|
||||
@ -23,26 +26,28 @@ public class AsynchronousQuit {
|
||||
private final String name;
|
||||
private boolean isOp = false;
|
||||
private boolean needToChange = false;
|
||||
private boolean isKick = false;
|
||||
private final boolean isKick;
|
||||
private final ProcessService service;
|
||||
|
||||
public AsynchronousQuit(Player p, AuthMe plugin, DataSource database,
|
||||
boolean isKick) {
|
||||
public AsynchronousQuit(Player p, AuthMe plugin, DataSource database, boolean isKick, ProcessService service) {
|
||||
this.player = p;
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.name = p.getName().toLowerCase();
|
||||
this.isKick = isKick;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (player == null || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String ip = plugin.getIP(player);
|
||||
String ip = service.getIpAddressManager().getPlayerIp(player);
|
||||
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
if (Settings.isSaveQuitLocationEnabled) {
|
||||
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
||||
Location loc = player.getLocation();
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(name).location(loc)
|
||||
@ -76,7 +81,7 @@ public class AsynchronousQuit {
|
||||
|
||||
plugin.sessions.put(name, task);
|
||||
} else {
|
||||
//plugin is disable we canno schedule more tasks so run it directly here
|
||||
//plugin is disabled; we cannot schedule more tasks so run it directly here
|
||||
postLogout();
|
||||
}
|
||||
}
|
||||
@ -85,7 +90,7 @@ public class AsynchronousQuit {
|
||||
database.setUnlogged(name);
|
||||
}
|
||||
|
||||
plugin.realIp.remove(name);
|
||||
service.getIpAddressManager().removeCache(player.getName());
|
||||
if (plugin.isEnabled()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, isOp, needToChange));
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
package fr.xephi.authme.process.register;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||
import fr.xephi.authme.process.Process;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.security.crypts.TwoFactor;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AsyncRegister {
|
||||
public class AsyncRegister implements Process {
|
||||
|
||||
private final Player player;
|
||||
private final String name;
|
||||
@ -28,66 +28,65 @@ public class AsyncRegister {
|
||||
private final String email;
|
||||
private final AuthMe plugin;
|
||||
private final DataSource database;
|
||||
private final Messages m;
|
||||
private final NewSetting settings;
|
||||
private final ProcessService service;
|
||||
|
||||
public AsyncRegister(Player player, String password, String email, AuthMe plugin, DataSource data,
|
||||
NewSetting settings) {
|
||||
this.m = plugin.getMessages();
|
||||
ProcessService service) {
|
||||
this.player = player;
|
||||
this.password = password;
|
||||
this.name = player.getName().toLowerCase();
|
||||
this.email = email;
|
||||
this.plugin = plugin;
|
||||
this.database = data;
|
||||
this.ip = plugin.getIP(player);
|
||||
this.settings = settings;
|
||||
this.ip = service.getIpAddressManager().getPlayerIp(player);
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
private boolean preRegisterCheck() {
|
||||
String passLow = password.toLowerCase();
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
return false;
|
||||
} else if (!Settings.isRegistrationEnabled) {
|
||||
m.send(player, MessageKey.REGISTRATION_DISABLED);
|
||||
service.send(player, MessageKey.REGISTRATION_DISABLED);
|
||||
return false;
|
||||
}
|
||||
|
||||
//check the password safety only if it's not a automatically generated password
|
||||
if (Settings.getPasswordHash != HashAlgorithm.TWO_FACTOR) {
|
||||
if (service.getProperty(SecuritySettings.PASSWORD_HASH) != HashAlgorithm.TWO_FACTOR) {
|
||||
if (!passLow.matches(Settings.getPassRegex)) {
|
||||
m.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
service.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
return false;
|
||||
} else if (passLow.equalsIgnoreCase(player.getName())) {
|
||||
m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
service.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR);
|
||||
return false;
|
||||
} else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) {
|
||||
m.send(player, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
service.send(player, MessageKey.INVALID_PASSWORD_LENGTH);
|
||||
return false;
|
||||
} else if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(password.toLowerCase())) {
|
||||
m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
service.send(player, MessageKey.PASSWORD_UNSAFE_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//check this in both possiblities so don't use 'else if'
|
||||
Integer size = 0;
|
||||
//check this in both possibilities so don't use 'else if'
|
||||
int size;
|
||||
if (database.isAuthAvailable(name)) {
|
||||
m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
|
||||
service.send(player, MessageKey.NAME_ALREADY_REGISTERED);
|
||||
return false;
|
||||
} else if (Settings.getmaxRegPerIp > 0
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& !ip.equalsIgnoreCase("127.0.0.1")
|
||||
&& !ip.equalsIgnoreCase("localhost")
|
||||
&& (size = database.getAllAuthsByIp(ip).size()) >= Settings.getmaxRegPerIp) {
|
||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED, size.toString());
|
||||
service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(size));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (preRegisterCheck()) {
|
||||
if (!StringUtils.isEmpty(email)) {
|
||||
emailRegister();
|
||||
@ -98,11 +97,11 @@ public class AsyncRegister {
|
||||
}
|
||||
|
||||
private void emailRegister() {
|
||||
Integer size = 0;
|
||||
int size;
|
||||
if (Settings.getmaxRegPerEmail > 0
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& (size = database.countAuthsByEmail(email)) >= Settings.getmaxRegPerEmail) {
|
||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED, size.toString());
|
||||
service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(size));
|
||||
return;
|
||||
}
|
||||
final HashedPassword hashedPassword = plugin.getPasswordSecurity().computeHash(password, name);
|
||||
@ -116,13 +115,13 @@ public class AsyncRegister {
|
||||
.build();
|
||||
|
||||
if (!database.saveAuth(auth)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
service.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
database.updateEmail(auth);
|
||||
database.updateSession(auth);
|
||||
plugin.mail.main(auth, password);
|
||||
ProcessSyncEmailRegister sync = new ProcessSyncEmailRegister(player, plugin);
|
||||
ProcessSyncEmailRegister sync = new ProcessSyncEmailRegister(player, service);
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, sync);
|
||||
|
||||
}
|
||||
@ -138,7 +137,7 @@ public class AsyncRegister {
|
||||
.build();
|
||||
|
||||
if (!database.saveAuth(auth)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
service.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -150,13 +149,13 @@ public class AsyncRegister {
|
||||
}
|
||||
|
||||
plugin.otherAccounts.addPlayer(player.getUniqueId());
|
||||
ProcessSyncPasswordRegister sync = new ProcessSyncPasswordRegister(player, plugin, settings);
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, sync);
|
||||
ProcessSyncPasswordRegister sync = new ProcessSyncPasswordRegister(player, plugin, service);
|
||||
service.scheduleSyncDelayedTask(sync);
|
||||
|
||||
//give the user the secret code to setup their app code generation
|
||||
if (Settings.getPasswordHash == HashAlgorithm.TWO_FACTOR) {
|
||||
String qrCodeUrl = TwoFactor.getQRBarcodeURL(player.getName(), Bukkit.getIp(), hashedPassword.getHash());
|
||||
m.send(player, MessageKey.TWO_FACTOR_CREATE, hashedPassword.getHash(), qrCodeUrl);
|
||||
service.send(player, MessageKey.TWO_FACTOR_CREATE, hashedPassword.getHash(), qrCodeUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package fr.xephi.authme.process.register;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.task.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
@ -20,51 +21,43 @@ public class ProcessSyncEmailRegister implements Runnable {
|
||||
|
||||
protected final Player player;
|
||||
protected final String name;
|
||||
private final AuthMe plugin;
|
||||
private final Messages m;
|
||||
private final ProcessService service;
|
||||
|
||||
/**
|
||||
* Constructor for ProcessSyncEmailRegister.
|
||||
*
|
||||
* @param player Player
|
||||
* @param plugin AuthMe
|
||||
* @param player The player to process an email registration for
|
||||
* @param service The process service
|
||||
*/
|
||||
public ProcessSyncEmailRegister(Player player, AuthMe plugin) {
|
||||
this.m = plugin.getMessages();
|
||||
public ProcessSyncEmailRegister(Player player, ProcessService service) {
|
||||
this.player = player;
|
||||
this.name = player.getName().toLowerCase();
|
||||
this.plugin = plugin;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
||||
if (!Settings.getRegisteredGroup.isEmpty()) {
|
||||
Utils.setGroup(player, Utils.GroupType.REGISTERED);
|
||||
}
|
||||
m.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
int time = Settings.getRegistrationTimeout * 20;
|
||||
int msgInterval = Settings.getWarnMessageInterval;
|
||||
|
||||
BukkitScheduler sched = plugin.getServer().getScheduler();
|
||||
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||
int time = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
|
||||
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
|
||||
if (limbo != null) {
|
||||
if (time != 0) {
|
||||
BukkitTask id = sched.runTaskLater(plugin, new TimeoutTask(plugin, name, player), time);
|
||||
BukkitTask id = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), time);
|
||||
limbo.setTimeoutTaskId(id);
|
||||
}
|
||||
BukkitTask nwMsg = sched.runTask(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), msgInterval));
|
||||
limbo.setMessageTaskId(nwMsg);
|
||||
BukkitTask messageTask = service.runTask(new MessageTask(
|
||||
service.getAuthMe(), name, service.retrieveMessage(MessageKey.LOGIN_MESSAGE), msgInterval));
|
||||
limbo.setMessageTaskId(messageTask);
|
||||
}
|
||||
|
||||
player.saveData();
|
||||
if (!Settings.noConsoleSpam) {
|
||||
ConsoleLogger.info(player.getName() + " registered " + plugin.getIP(player));
|
||||
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
||||
ConsoleLogger.info(player.getName() + " registered " + service.getIpAddressManager().getPlayerIp(player));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,42 +9,34 @@ import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.process.Process;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
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.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ProcessSyncPasswordRegister implements Runnable {
|
||||
public class ProcessSyncPasswordRegister implements Process {
|
||||
|
||||
protected final Player player;
|
||||
protected final String name;
|
||||
private final AuthMe plugin;
|
||||
private final Messages m;
|
||||
private final NewSetting settings;
|
||||
private final ProcessService service;
|
||||
|
||||
/**
|
||||
* Constructor for ProcessSyncPasswordRegister.
|
||||
*
|
||||
* @param player Player
|
||||
* @param plugin AuthMe
|
||||
* @param settings The plugin settings
|
||||
*/
|
||||
public ProcessSyncPasswordRegister(Player player, AuthMe plugin, NewSetting settings) {
|
||||
this.m = plugin.getMessages();
|
||||
public ProcessSyncPasswordRegister(Player player, AuthMe plugin, ProcessService service) {
|
||||
this.player = player;
|
||||
this.name = player.getName().toLowerCase();
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
private void sendBungeeMessage() {
|
||||
@ -70,15 +62,14 @@ public class ProcessSyncPasswordRegister implements Runnable {
|
||||
Utils.teleportToSpawn(player);
|
||||
LimboCache cache = LimboCache.getInstance();
|
||||
cache.updateLimboPlayer(player);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = plugin.getServer().getScheduler();
|
||||
int delay = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
BukkitTask task;
|
||||
if (delay != 0) {
|
||||
task = sched.runTaskLater(plugin, new TimeoutTask(plugin, name, player), delay);
|
||||
task = service.runTaskLater(new TimeoutTask(service.getAuthMe(), name, player), delay);
|
||||
cache.getLimboPlayer(name).setTimeoutTaskId(task);
|
||||
}
|
||||
task = sched.runTask(plugin, new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
task = service.runTask(new MessageTask(plugin, name, MessageKey.LOGIN_MESSAGE, interval));
|
||||
cache.getLimboPlayer(name).setMessageTaskId(task);
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
player.getVehicle().eject();
|
||||
@ -106,13 +97,13 @@ public class ProcessSyncPasswordRegister implements Runnable {
|
||||
Utils.setGroup(player, Utils.GroupType.REGISTERED);
|
||||
}
|
||||
|
||||
m.send(player, MessageKey.REGISTER_SUCCESS);
|
||||
service.send(player, MessageKey.REGISTER_SUCCESS);
|
||||
|
||||
if (!Settings.getmailAccount.isEmpty()) {
|
||||
m.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||
service.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||
}
|
||||
|
||||
if (Settings.applyBlindEffect) {
|
||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
player.removePotionEffect(PotionEffectType.BLINDNESS);
|
||||
}
|
||||
|
||||
@ -121,23 +112,23 @@ public class ProcessSyncPasswordRegister implements Runnable {
|
||||
player.saveData();
|
||||
|
||||
if (!Settings.noConsoleSpam) {
|
||||
ConsoleLogger.info(player.getName() + " registered " + plugin.getIP(player));
|
||||
ConsoleLogger.info(player.getName() + " registered " + service.getIpAddressManager().getPlayerIp(player));
|
||||
}
|
||||
|
||||
// Kick Player after Registration is enabled, kick the player
|
||||
if (Settings.forceRegKick) {
|
||||
player.kickPlayer(m.retrieveSingle(MessageKey.REGISTER_SUCCESS));
|
||||
player.kickPlayer(service.retrieveSingleMessage(MessageKey.REGISTER_SUCCESS));
|
||||
return;
|
||||
}
|
||||
|
||||
// Register is finish and player is logged, display welcome message
|
||||
if (Settings.useWelcomeMessage) {
|
||||
if (Settings.broadcastWelcomeMessage) {
|
||||
for (String s : settings.getWelcomeMessage()) {
|
||||
if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
|
||||
if (service.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
|
||||
for (String s : service.getSettings().getWelcomeMessage()) {
|
||||
plugin.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
|
||||
}
|
||||
} else {
|
||||
for (String s : settings.getWelcomeMessage()) {
|
||||
for (String s : service.getSettings().getWelcomeMessage()) {
|
||||
player.sendMessage(plugin.replaceAllInfo(s, player));
|
||||
}
|
||||
}
|
||||
@ -160,10 +151,10 @@ public class ProcessSyncPasswordRegister implements Runnable {
|
||||
}
|
||||
|
||||
private void sendTo() {
|
||||
if (!settings.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
|
||||
if (!service.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(settings.getProperty(HooksSettings.BUNGEECORD_SERVER));
|
||||
out.writeUTF(service.getProperty(HooksSettings.BUNGEECORD_SERVER));
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,11 @@ import fr.xephi.authme.cache.backup.JsonCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.process.Process;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
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.TimeoutTask;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
@ -20,15 +23,15 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class AsynchronousUnregister {
|
||||
public class AsynchronousUnregister implements Process {
|
||||
|
||||
private final Player player;
|
||||
private final String name;
|
||||
private final String password;
|
||||
private final boolean force;
|
||||
private final AuthMe plugin;
|
||||
private final Messages m;
|
||||
private final JsonCache playerCache;
|
||||
private final ProcessService service;
|
||||
|
||||
/**
|
||||
* Constructor for AsynchronousUnregister.
|
||||
@ -38,29 +41,27 @@ public class AsynchronousUnregister {
|
||||
* @param force boolean
|
||||
* @param plugin AuthMe
|
||||
*/
|
||||
public AsynchronousUnregister(Player player, String password, boolean force, AuthMe plugin) {
|
||||
this.m = plugin.getMessages();
|
||||
public AsynchronousUnregister(Player player, String password, boolean force, AuthMe plugin,
|
||||
ProcessService service) {
|
||||
this.player = player;
|
||||
this.name = player.getName().toLowerCase();
|
||||
this.password = password;
|
||||
this.force = force;
|
||||
this.plugin = plugin;
|
||||
this.playerCache = new JsonCache();
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
protected String getIp() {
|
||||
return plugin.getIP(player);
|
||||
}
|
||||
|
||||
public void process() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerAuth cachedAuth = PlayerCache.getInstance().getAuth(name);
|
||||
if (force || plugin.getPasswordSecurity().comparePassword(
|
||||
password, cachedAuth.getPassword(), player.getName())) {
|
||||
if (!plugin.getDataSource().removeAuth(name)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
service.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
int timeOut = Settings.getRegistrationTimeout * 20;
|
||||
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
|
||||
if (Settings.isForcedRegistrationEnabled) {
|
||||
Utils.teleportToSpawn(player);
|
||||
player.saveData();
|
||||
@ -70,7 +71,7 @@ public class AsynchronousUnregister {
|
||||
}
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
LimboPlayer limboPlayer = LimboCache.getInstance().getLimboPlayer(name);
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
BukkitScheduler scheduler = plugin.getServer().getScheduler();
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = scheduler.runTaskLater(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
||||
@ -78,7 +79,7 @@ public class AsynchronousUnregister {
|
||||
}
|
||||
limboPlayer.setMessageTaskId(scheduler.runTask(plugin,
|
||||
new MessageTask(plugin, name, MessageKey.REGISTER_MESSAGE, interval)));
|
||||
m.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||
return;
|
||||
}
|
||||
@ -92,14 +93,14 @@ public class AsynchronousUnregister {
|
||||
playerCache.removeCache(player);
|
||||
}
|
||||
// Apply blind effect
|
||||
if (Settings.applyBlindEffect) {
|
||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2));
|
||||
}
|
||||
m.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
|
||||
Utils.teleportToSpawn(player);
|
||||
} else {
|
||||
m.send(player, MessageKey.WRONG_PASSWORD);
|
||||
service.send(player, MessageKey.WRONG_PASSWORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public final class Settings {
|
||||
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
|
||||
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
||||
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
||||
noConsoleSpam = configFile.getBoolean("Security.console.noConsoleSpam", false);
|
||||
noConsoleSpam = load(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE);
|
||||
removePassword = configFile.getBoolean("Security.console.removePassword", true);
|
||||
getmailAccount = configFile.getString("Email.mailAccount", "");
|
||||
getMailPort = configFile.getInt("Email.mailPort", 465);
|
||||
@ -197,10 +197,10 @@ public final class Settings {
|
||||
forceCommandsAsConsole = configFile.getStringList("settings.forceCommandsAsConsole");
|
||||
recallEmail = configFile.getBoolean("Email.recallPlayers", false);
|
||||
delayRecall = configFile.getInt("Email.delayRecall", 5);
|
||||
useWelcomeMessage = configFile.getBoolean("settings.useWelcomeMessage", true);
|
||||
useWelcomeMessage = load(RegistrationSettings.USE_WELCOME_MESSAGE);
|
||||
unsafePasswords = configFile.getStringList("settings.security.unsafePasswords");
|
||||
countriesBlacklist = configFile.getStringList("Protection.countriesBlacklist");
|
||||
broadcastWelcomeMessage = configFile.getBoolean("settings.broadcastWelcomeMessage", false);
|
||||
broadcastWelcomeMessage = load(RegistrationSettings.BROADCAST_WELCOME_MESSAGE);
|
||||
forceRegKick = configFile.getBoolean("settings.registration.forceKickAfterRegister", false);
|
||||
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
|
||||
spawnPriority = load(RestrictionSettings.SPAWN_PRIORITY);
|
||||
|
@ -22,13 +22,13 @@ public class MessageTask implements Runnable {
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
* @param name String
|
||||
* @param strings String[]
|
||||
* @param lines String[]
|
||||
* @param interval int
|
||||
*/
|
||||
public MessageTask(AuthMe plugin, String name, String[] strings, int interval) {
|
||||
public MessageTask(AuthMe plugin, String name, String[] lines, int interval) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.msg = strings;
|
||||
this.msg = lines;
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,9 @@ public class GeoLiteAPI {
|
||||
private static LookupService lookupService;
|
||||
private static Thread downloadTask;
|
||||
|
||||
private GeoLiteAPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Download (if absent) the GeoIpLite data file and then try to load it.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package fr.xephi.authme.command;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.manager.IpAddressManager;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
@ -41,6 +42,7 @@ public class CommandServiceTest {
|
||||
private CommandService commandService;
|
||||
private PermissionsManager permissionsManager;
|
||||
private NewSetting settings;
|
||||
private IpAddressManager ipAddressManager;
|
||||
|
||||
@Before
|
||||
public void setUpService() {
|
||||
@ -51,8 +53,9 @@ public class CommandServiceTest {
|
||||
passwordSecurity = mock(PasswordSecurity.class);
|
||||
permissionsManager = mock(PermissionsManager.class);
|
||||
settings = mock(NewSetting.class);
|
||||
commandService = new CommandService(
|
||||
authMe, commandMapper, helpProvider, messages, passwordSecurity, permissionsManager, settings);
|
||||
ipAddressManager = mock(IpAddressManager.class);
|
||||
commandService = new CommandService(authMe, commandMapper, helpProvider, messages, passwordSecurity,
|
||||
permissionsManager, settings, ipAddressManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -216,4 +219,13 @@ public class CommandServiceTest {
|
||||
// then
|
||||
assertThat(result, equalTo(authMe));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnIpAddressManager() {
|
||||
// given/when
|
||||
IpAddressManager ipManager = commandService.getIpAddressManager();
|
||||
|
||||
// then
|
||||
assertThat(ipManager, equalTo(ipAddressManager));
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class AsyncChangeEmailTest {
|
||||
given(dataSource.updateEmail(auth)).willReturn(true);
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource).updateEmail(auth);
|
||||
@ -76,7 +76,7 @@ public class AsyncChangeEmailTest {
|
||||
given(dataSource.updateEmail(auth)).willReturn(false);
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource).updateEmail(auth);
|
||||
@ -94,7 +94,7 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
|
||||
@ -112,7 +112,7 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
|
||||
@ -130,7 +130,7 @@ public class AsyncChangeEmailTest {
|
||||
given(playerCache.getAuth("bobby")).willReturn(auth);
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
|
||||
@ -149,7 +149,7 @@ public class AsyncChangeEmailTest {
|
||||
given(dataSource.isEmailStored("new@example.com")).willReturn(true);
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
|
||||
@ -166,7 +166,7 @@ public class AsyncChangeEmailTest {
|
||||
given(dataSource.isAuthAvailable("Bobby")).willReturn(true);
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
|
||||
@ -184,7 +184,7 @@ public class AsyncChangeEmailTest {
|
||||
Settings.emailRegistration = true;
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
|
||||
@ -202,7 +202,7 @@ public class AsyncChangeEmailTest {
|
||||
Settings.emailRegistration = false;
|
||||
|
||||
// when
|
||||
process.process();
|
||||
process.run();
|
||||
|
||||
// then
|
||||
verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
|
||||
|
Loading…
Reference in New Issue
Block a user