#450 Move Settings#getRestrictedIp()

This commit is contained in:
ljacqu 2016-01-31 18:50:57 +01:00
parent fbd5265a0b
commit 9653354135
5 changed files with 39 additions and 53 deletions

View File

@ -49,14 +49,14 @@ public class AsynchronousJoin {
}
public void process() {
if (Settings.checkVeryGames) {
plugin.getVerygamesIp(player);
}
if (Utils.isUnrestricted(player)) {
return;
}
if (Settings.checkVeryGames) {
plugin.getVerygamesIp(player);
}
if (plugin.ess != null && Settings.disableSocialSpy) {
plugin.ess.getUser(player).setSocialSpyEnabled(false);
}
@ -64,13 +64,13 @@ public class AsynchronousJoin {
final String ip = plugin.getIP(player);
if (Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip, player.getAddress().getHostName())) {
if (Settings.isAllowRestrictedIp && !isNameRestricted(name, ip, player.getAddress().getHostName())) {
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
player.kickPlayer("You are not the Owner of this account, please try another name!");
player.kickPlayer("You are not the owner of this account. Please try another name!");
if (Settings.banUnsafeIp)
plugin.getServer().banIP(ip);
}
@ -282,4 +282,30 @@ public class AsynchronousJoin {
});
}
/**
* Return whether the name is restricted based on the restriction setting.
*
* @param name The name to check
* @param ip The IP address of the player
* @param domain The hostname of the IP address
* @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
*/
private static boolean isNameRestricted(String name, String ip, String domain) {
boolean nameFound = false;
for (String entry : Settings.getRestrictedIp) {
String[] args = entry.split(";");
String testName = args[0];
String testIp = args[1];
if (testName.equalsIgnoreCase(name)) {
nameFound = true;
if ((ip != null && testIp.equals(ip))
|| (domain != null && testIp.equalsIgnoreCase(domain))) {
return false;
}
}
}
return nameFound;
}
}

View File

@ -47,7 +47,7 @@ public class NewSetting {
messagesFile = buildMessagesFile();
PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
if (SettingsMigrationService.checkAndMigrate(configuration, propertyMap)) {
if (SettingsMigrationService.checkAndMigrate(configuration, propertyMap, pluginFolder)) {
ConsoleLogger.info("Merged new config options");
ConsoleLogger.info("Please check your config.yml file for new settings!");
save(propertyMap);
@ -67,7 +67,7 @@ public class NewSetting {
this.configFile = configFile;
this.pluginFolder = new File("");
if (propertyMap != null && SettingsMigrationService.checkAndMigrate(configuration, propertyMap)) {
if (propertyMap != null && SettingsMigrationService.checkAndMigrate(configuration, propertyMap, pluginFolder)) {
save(propertyMap);
}
}

View File

@ -340,43 +340,6 @@ public final class Settings {
}
}
/**
* Config option for setting and check restricted user by username;ip ,
* return false if ip and name doesn't match with player that join the
* server, so player has a restricted access
*
* @param name String
* @param ip String
* @param domain String
*
* @return boolean
*/
public static boolean getRestrictedIp(String name, String ip, String domain) {
Iterator<String> iterator = getRestrictedIp.iterator();
boolean trueOnce = false;
boolean nameFound = false;
while (iterator.hasNext()) {
String[] args = iterator.next().split(";");
String testName = args[0];
String testIp = args[1];
if (testName.equalsIgnoreCase(name)) {
nameFound = true;
if (ip != null) {
if (testIp.equalsIgnoreCase(ip)) {
trueOnce = true;
}
}
if (domain != null) {
if (testIp.equalsIgnoreCase(domain)) {
trueOnce = true;
}
}
}
}
return !nameFound || trueOnce;
}
/**
* Saves the configuration to disk
*

View File

@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.propertymap.PropertyMap;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
@ -27,22 +26,21 @@ public final class SettingsMigrationService {
*
* @param configuration The file configuration to check and migrate
* @param propertyMap The property map of all existing properties
* @param pluginFolder The plugin folder
* @return True if there is a change and the config must be saved, false if the config is up-to-date
*/
public static boolean checkAndMigrate(FileConfiguration configuration, PropertyMap propertyMap) {
return performMigrations(configuration) || hasDeprecatedProperties(configuration)
public static boolean checkAndMigrate(FileConfiguration configuration, PropertyMap propertyMap, File pluginFolder) {
return performMigrations(configuration, pluginFolder) || hasDeprecatedProperties(configuration)
|| !containsAllSettings(configuration, propertyMap);
}
private static boolean performMigrations(FileConfiguration configuration) {
private static boolean performMigrations(FileConfiguration configuration, File pluginFolder) {
boolean changes = false;
if ("[a-zA-Z0-9_?]*".equals(configuration.getString(ALLOWED_NICKNAME_CHARACTERS.getPath()))) {
configuration.set(ALLOWED_NICKNAME_CHARACTERS.getPath(), "[a-zA-Z0-9_]*");
changes = true;
}
// TODO #450: Don't get the data folder statically
Wrapper w = Wrapper.getInstance();
changes = changes || performMailTextToFileMigration(configuration, w.getDataFolder());
changes = changes || performMailTextToFileMigration(configuration, pluginFolder);
return changes;
}

View File

@ -42,7 +42,6 @@ public class NewSettingIntegrationTest {
// given
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(getConfigFile(COMPLETE_FILE));
File file = new File("unused");
assumeThat(file.exists(), equalTo(false));
// when / then
NewSetting settings = new NewSetting(configuration, file, propertyMap);