Merge master into 477-lastlogin-timestamp

Conflicts:
    - Settings.java
This commit is contained in:
ljacqu
2016-02-13 20:03:06 +01:00
81 changed files with 1948 additions and 1681 deletions
@@ -18,6 +18,7 @@ import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
@@ -108,6 +109,21 @@ public class NewSetting {
return messagesFile;
}
/**
* Return the default messages file within the JAR that should contain all messages.
*
* @return The default messages file, or {@code null} if it could not be retrieved
*/
public File getDefaultMessagesFile() {
String defaultFilePath = "/messages/messages_en.yml";
URL url = NewSetting.class.getResource(defaultFilePath);
if (url == null) {
return null;
}
File file = new File(url.getFile());
return file.exists() ? file : null;
}
public String getEmailMessage() {
return emailMessage;
}
@@ -1,14 +1,18 @@
package fr.xephi.authme.settings;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSourceType;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.DatabaseSettings;
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.settings.properties.SecuritySettings;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -22,8 +26,6 @@ public final class Settings {
public static final File PLUGIN_FOLDER = Wrapper.getInstance().getDataFolder();
public static final File MODULE_FOLDER = new File(PLUGIN_FOLDER, "modules");
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
private static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
public static final File LOG_FILE = new File(PLUGIN_FOLDER, "authme.log");
// This is not an option!
public static boolean antiBotInAction = false;
public static List<String> allowCommands;
@@ -63,7 +65,8 @@ public final class Settings {
purgeLimitedCreative, purgeAntiXray, purgePermissions,
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect,
checkVeryGames, removeJoinMessage, removeLeaveMessage, delayJoinMessage,
noTeleport, applyBlindEffect, hideTablistBeforeLogin, denyTabcompleteBeforeLogin,
kickPlayersBeforeStopping, allowAllCommandsIfRegIsOptional,
customAttributes, generateImage, isRemoveSpeedEnabled, preventOtherCase;
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
@@ -103,7 +106,7 @@ public final class Settings {
}
public static void loadVariables() {
isPermissionCheckEnabled = configFile.getBoolean("permission.EnablePermissionCheck", false);
isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK);
isForcedRegistrationEnabled = configFile.getBoolean("settings.registration.force", true);
isRegistrationEnabled = configFile.getBoolean("settings.registration.enabled", true);
isTeleportToSpawnEnabled = configFile.getBoolean("settings.restrictions.teleportUnAuthedToSpawn", false);
@@ -130,16 +133,16 @@ public final class Settings {
isSaveQuitLocationEnabled = configFile.getBoolean("settings.restrictions.SaveQuitLocation", false);
isForceSurvivalModeEnabled = configFile.getBoolean("settings.GameMode.ForceSurvivalMode", false);
getmaxRegPerIp = configFile.getInt("settings.restrictions.maxRegPerIp", 1);
getPasswordHash = getPasswordHash();
getUnloggedinGroup = configFile.getString("settings.security.unLoggedinGroup", "unLoggedInGroup");
getDataSource = getDataSource();
isCachingEnabled = configFile.getBoolean("DataSource.caching", true);
getMySQLHost = configFile.getString("DataSource.mySQLHost", "127.0.0.1");
getMySQLPort = configFile.getString("DataSource.mySQLPort", "3306");
getMySQLUsername = configFile.getString("DataSource.mySQLUsername", "authme");
getMySQLPassword = configFile.getString("DataSource.mySQLPassword", "12345");
getMySQLDatabase = configFile.getString("DataSource.mySQLDatabase", "authme");
getMySQLTablename = configFile.getString("DataSource.mySQLTablename", "authme");
getPasswordHash = load(SecuritySettings.PASSWORD_HASH);
getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP);
getDataSource = load(DatabaseSettings.BACKEND);
isCachingEnabled = load(DatabaseSettings.USE_CACHING);
getMySQLHost = load(DatabaseSettings.MYSQL_HOST);
getMySQLPort = load(DatabaseSettings.MYSQL_PORT);
getMySQLUsername = load(DatabaseSettings.MYSQL_USERNAME);
getMySQLPassword = load(DatabaseSettings.MYSQL_PASSWORD);
getMySQLDatabase = load(DatabaseSettings.MYSQL_DATABASE);
getMySQLTablename = load(DatabaseSettings.MYSQL_TABLE);
getMySQLColumnEmail = configFile.getString("DataSource.mySQLColumnEmail", "email");
getMySQLColumnName = configFile.getString("DataSource.mySQLColumnName", "username");
getMySQLColumnPassword = configFile.getString("DataSource.mySQLColumnPassword", "password");
@@ -161,12 +164,15 @@ public final class Settings {
}
getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", "");
enablePasswordConfirmation = configFile.getBoolean("settings.restrictions.enablePasswordConfirmation", true);
enablePasswordConfirmation = load(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION);
protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN);
denyTabcompleteBeforeLogin = load(RestrictionSettings.DENY_TABCOMPLETE_BEFORE_LOGIN);
hideTablistBeforeLogin = load(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN);
protectInventoryBeforeLogInEnabled = configFile.getBoolean("settings.restrictions.ProtectInventoryBeforeLogIn", true);
plugin.checkProtocolLib();
passwordMaxLength = configFile.getInt("settings.security.passwordMaxLength", 20);
passwordMaxLength = load(SecuritySettings.MAX_PASSWORD_LENGTH);
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
@@ -240,7 +246,9 @@ public final class Settings {
getMaxLoginPerIp = configFile.getInt("settings.restrictions.maxLoginPerIp", 0);
getMaxJoinPerIp = configFile.getInt("settings.restrictions.maxJoinPerIp", 0);
checkVeryGames = configFile.getBoolean("VeryGames.enableIpCheck", false);
delayJoinLeaveMessages = configFile.getBoolean("settings.delayJoinLeaveMessages", false);
removeJoinMessage = load(RegistrationSettings.REMOVE_JOIN_MESSAGE);
removeLeaveMessage = load(RegistrationSettings.REMOVE_LEAVE_MESSAGE);
delayJoinMessage = load(RegistrationSettings.DELAY_JOIN_MESSAGE);
noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false);
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters", "[\\x21-\\x7E]*");
@@ -257,70 +265,6 @@ public final class Settings {
}
/**
* Method getPasswordHash.
*
* @return HashAlgorithm
*/
private static HashAlgorithm getPasswordHash() {
String key = "settings.security.passwordHash";
try {
return HashAlgorithm.valueOf(configFile.getString(key, "SHA256").toUpperCase());
} catch (IllegalArgumentException ex) {
ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256");
return HashAlgorithm.SHA256;
}
}
/**
* Method getDataSource.
*
* @return DataSourceType
*/
private static DataSourceType getDataSource() {
String key = "DataSource.backend";
try {
return DataSourceType.valueOf(configFile.getString(key, "sqlite").toUpperCase());
} catch (IllegalArgumentException ex) {
ConsoleLogger.showError("Unknown database backend; defaulting to SQLite database");
return DataSourceType.SQLITE;
}
}
/**
* Saves the configuration to disk
*
* @return True if saved successfully
*/
private static boolean save() {
try {
configFile.save(SETTINGS_FILE);
return true;
} catch (IOException ex) {
return false;
}
}
/**
* Method checkLang.
*
* @param lang String
*
* @return String
*/
private static String checkLang(String lang) {
if (new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + lang + ".yml").exists()) {
ConsoleLogger.info("Set Language to: " + lang);
return lang;
}
if (AuthMe.class.getResourceAsStream("/messages/messages_" + lang + ".yml") != null) {
ConsoleLogger.info("Set Language to: " + lang);
return lang;
}
ConsoleLogger.info("Language file not found for " + lang + ", set to default language: en !");
return "en";
}
/**
* Method switchAntiBotMod.
*
@@ -337,20 +281,13 @@ public final class Settings {
}
/**
* Saves current configuration (plus defaults) to disk.
* <p>
* If defaults and configuration are empty, saves blank file.
* Load the value via the new Property setup for temporary support within this old settings manager.
*
* @return True if saved successfully
* @param property The property to load
* @param <T> The property type
* @return The config value of the property
*/
private boolean saveDefaults() {
configFile.options()
.copyDefaults(true)
.copyHeader(true);
boolean success = save();
configFile.options()
.copyDefaults(false)
.copyHeader(false);
return success;
private static <T> T load(Property<T> property) {
return property.getFromFile(configFile);
}
}
@@ -13,6 +13,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import static fr.xephi.authme.settings.properties.RegistrationSettings.DELAY_JOIN_MESSAGE;
import static fr.xephi.authme.settings.properties.RegistrationSettings.REMOVE_JOIN_MESSAGE;
import static fr.xephi.authme.settings.properties.RegistrationSettings.REMOVE_LEAVE_MESSAGE;
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS;
import static java.lang.String.format;
@@ -43,9 +46,12 @@ public final class SettingsMigrationService {
configuration.set(ALLOWED_NICKNAME_CHARACTERS.getPath(), "[a-zA-Z0-9_]*");
changes = true;
}
changes = changes || performMailTextToFileMigration(configuration, pluginFolder);
return changes;
// Note ljacqu 20160211: Concatenating migration methods with | instead of the usual ||
// ensures that all migrations will be performed
return changes
| performMailTextToFileMigration(configuration, pluginFolder)
| migrateJoinLeaveMessages(configuration);
}
@VisibleForTesting
@@ -61,8 +67,7 @@ public final class SettingsMigrationService {
private static boolean hasDeprecatedProperties(FileConfiguration configuration) {
String[] deprecatedProperties = {
"Converter.Rakamak.newPasswordHash", "Hooks.chestshop", "Hooks.legacyChestshop", "Hooks.notifications",
"Passpartu", "Performances", "settings.delayJoinMessage", "settings.restrictions.enablePasswordVerifier",
"Xenoforo.predefinedSalt"};
"Passpartu", "Performances", "settings.restrictions.enablePasswordVerifier", "Xenoforo.predefinedSalt"};
for (String deprecatedPath : deprecatedProperties) {
if (configuration.contains(deprecatedPath)) {
return true;
@@ -104,6 +109,33 @@ public final class SettingsMigrationService {
return true;
}
/**
* Detect deprecated {@code settings.delayJoinLeaveMessages} and inform user of new "remove join messages"
* and "remove leave messages" settings.
*
* @param configuration The file configuration
* @return True if the configuration has changed, false otherwise
*/
private static boolean migrateJoinLeaveMessages(FileConfiguration configuration) {
final String oldDelayJoinPath = "settings.delayJoinLeaveMessages";
if (configuration.contains(oldDelayJoinPath)) {
ConsoleLogger.info("Detected deprecated property " + oldDelayJoinPath);
ConsoleLogger.info(String.format("Note that we now also have the settings %s and %s",
REMOVE_JOIN_MESSAGE.getPath(), REMOVE_LEAVE_MESSAGE.getPath()));
if (!configuration.contains(DELAY_JOIN_MESSAGE.getPath())) {
configuration.set(DELAY_JOIN_MESSAGE.getPath(), true);
ConsoleLogger.info("Renamed " + oldDelayJoinPath + " to " + DELAY_JOIN_MESSAGE.getPath());
}
return true;
}
return false;
}
// -------
// Utilities
// -------
/**
* Copy a resource file (from the JAR) to the given file if it doesn't exist.
*
@@ -80,9 +80,17 @@ public class RegistrationSettings implements SettingsClass {
public static final Property<Boolean> BROADCAST_WELCOME_MESSAGE =
newProperty("settings.broadcastWelcomeMessage", false);
@Comment("Do we need to delay the join/leave message to be displayed only when the player is authenticated?")
public static final Property<Boolean> DELAY_JOIN_LEAVE_MESSAGES =
newProperty("settings.delayJoinLeaveMessages", true);
@Comment("Should we delay the join message and display it once the player has logged in?")
public static final Property<Boolean> DELAY_JOIN_MESSAGE =
newProperty("settings.delayJoinMessage", false);
@Comment("Should we remove join messages altogether?")
public static final Property<Boolean> REMOVE_JOIN_MESSAGE =
newProperty("settings.removeJoinMessage", false);
@Comment("Should we remove leave messages?")
public static final Property<Boolean> REMOVE_LEAVE_MESSAGE =
newProperty("settings.removeLeaveMessage", false);
@Comment("Do we need to add potion effect Blinding before login/reigster?")
public static final Property<Boolean> APPLY_BLIND_EFFECT =
@@ -126,10 +126,18 @@ public class RestrictionSettings implements SettingsClass {
public static final Property<Boolean> ENABLE_PASSWORD_CONFIRMATION =
newProperty("settings.restrictions.enablePasswordConfirmation", true);
@Comment("Should we protect the player inventory before logging in?")
@Comment("Should we protect the player inventory before logging in? Requires ProtocolLib.")
public static final Property<Boolean> PROTECT_INVENTORY_BEFORE_LOGIN =
newProperty("settings.restrictions.ProtectInventoryBeforeLogIn", true);
@Comment("Should we deny the tabcomplete feature before logging in? Requires ProtocolLib.")
public static final Property<Boolean> DENY_TABCOMPLETE_BEFORE_LOGIN =
newProperty("settings.restrictions.DenyTabCompleteBeforeLogin", true);
@Comment("Should we hide the tablist before logging in? Requires ProtocolLib.")
public static final Property<Boolean> HIDE_TABLIST_BEFORE_LOGIN =
newProperty("settings.restrictions.HideTablistBeforeLogin", true);
@Comment({
"Should we display all other accounts from a player when he joins?",
"permission: /authme.admin.accounts"})
@@ -9,7 +9,6 @@ import java.util.List;
import static fr.xephi.authme.settings.domain.Property.newProperty;
import static fr.xephi.authme.settings.domain.PropertyType.STRING_LIST;
import static fr.xephi.authme.settings.domain.Property.newProperty;
public class SecuritySettings implements SettingsClass {