Merge remote-tracking branch 'origin/master' into authme-process

Conflicts:
	src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java
	src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java
	src/main/java/fr/xephi/authme/process/register/AsyncRegister.java
	src/main/java/fr/xephi/authme/settings/Settings.java
This commit is contained in:
DNx5
2015-12-05 03:23:50 +07:00
71 changed files with 1488 additions and 1274 deletions
@@ -1,132 +0,0 @@
package fr.xephi.authme.settings;
/**
* Keys for translatable messages managed by {@link Messages}.
*/
public enum MessageKey {
UNKNOWN_USER("unknown_user"),
UNSAFE_QUIT_LOCATION("unsafe_spawn"),
NOT_LOGGED_IN("not_logged_in"),
REGISTER_VOLUNTARILY("reg_voluntarily"),
USAGE_LOGIN("usage_log"),
WRONG_PASSWORD("wrong_pwd"),
UNREGISTERED_SUCCESS("unregistered"),
REGISTRATION_DISABLED("reg_disabled"),
SESSION_RECONNECTION("valid_session"),
LOGIN_SUCCESS("login"),
ACCOUNT_NOT_ACTIVATED("vb_nonActiv"),
NAME_ALREADY_REGISTERED("user_regged"),
NO_PERMISSION("no_perm"),
ERROR("error"),
LOGIN_MESSAGE("login_msg"),
REGISTER_MESSAGE("reg_msg"),
REGISTER_EMAIL_MESSAGE("reg_email_msg"),
MAX_REGISTER_EXCEEDED("max_reg"),
USAGE_REGISTER("usage_reg"),
USAGE_UNREGISTER("usage_unreg"),
PASSWORD_CHANGED_SUCCESS("pwd_changed"),
USER_NOT_REGISTERED("user_unknown"),
PASSWORD_MATCH_ERROR("password_error"),
PASSWORD_IS_USERNAME_ERROR("password_error_nick"),
PASSWORD_UNSAFE_ERROR("password_error_unsafe"),
SESSION_EXPIRED("invalid_session"),
MUST_REGISTER_MESSAGE("reg_only"),
ALREADY_LOGGED_IN_ERROR("logged_in"),
LOGOUT_SUCCESS("logout"),
USERNAME_ALREADY_ONLINE_ERROR("same_nick"),
REGISTER_SUCCESS("registered"),
INVALID_PASSWORD_LENGTH("pass_len"),
CONFIG_RELOAD_SUCCESS("reload"),
LOGIN_TIMEOUT_ERROR("timeout"),
USAGE_CHANGE_PASSWORD("usage_changepassword"),
INVALID_NAME_LENGTH("name_len"),
INVALID_NAME_CHARACTERS("regex"),
ADD_EMAIL_MESSAGE("add_email"),
FORGOT_PASSWORD_MESSAGE("recovery_email"),
USAGE_CAPTCHA("usage_captcha"),
CAPTCHA_WRONG_ERROR("wrong_captcha"),
CAPTCHA_SUCCESS("valid_captcha"),
KICK_FOR_VIP("kick_forvip"),
KICK_FULL_SERVER("kick_fullserver"),
USAGE_ADD_EMAIL("usage_email_add"),
USAGE_RECOVER_EMAIL("usage_email_recovery"),
INVALID_NEW_EMAIL("new_email_invalid"),
INVALID_OLD_EMAIL("old_email_invalid"),
INVALID_EMAIL("email_invalid"),
EMAIL_ADDED_SUCCESS("email_added"),
CONFIRM_EMAIL_MESSAGE("email_confirm"),
EMAIL_CHANGED_SUCCESS("email_changed"),
RECOVERY_EMAIL_SENT_MESSAGE("email_send"),
RECOVERY_EMAIL_ALREADY_SENT_MESSAGE("email_exists"),
COUNTRY_BANNED_ERROR("country_banned"),
ANTIBOT_AUTO_ENABLED_MESSAGE("antibot_auto_enabled"),
ANTIBOT_AUTO_DISABLED_MESSAGE("antibot_auto_disabled");
private String key;
MessageKey(String key) {
this.key = key;
}
public String getKey() {
return key;
}
}
@@ -1,115 +0,0 @@
package fr.xephi.authme.settings;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.command.CommandSender;
import java.io.File;
/**
* Class for retrieving and sending translatable messages to players.
*/
// TODO ljacqu 20151124: This class is a weird mix between singleton and POJO
// TODO: change it into POJO
public class Messages extends CustomConfiguration {
/** The section symbol, used in Minecraft for formatting codes. */
private static final String SECTION_SIGN = "\u00a7";
private static Messages singleton;
private String language;
/**
* Constructor for Messages.
*
* @param file the configuration file
* @param lang the code of the language to use
*/
public Messages(File file, String lang) {
super(file);
load();
this.language = lang;
}
public static Messages getInstance() {
if (singleton == null) {
singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
}
return singleton;
}
/**
* Send the given message code to the player.
*
* @param sender The entity to send the message to
* @param key The key of the message to send
*/
public void send(CommandSender sender, MessageKey key) {
String[] lines = retrieve(key);
for (String line : lines) {
sender.sendMessage(line);
}
}
/**
* Retrieve the message from the text file and return it split by new line as an array.
*
* @param key The message key to retrieve
*
* @return The message split by new lines
*/
public String[] retrieve(MessageKey key) {
return retrieve(key.getKey());
}
/**
* Retrieve the message from the text file.
*
* @param key The message key to retrieve
*
* @return The message from the file
*/
public String retrieveSingle(MessageKey key) {
return StringUtils.join("\n", retrieve(key.getKey()));
}
/**
* Retrieve the message from the configuration file.
*
* @param key The key to retrieve
*
* @return The message
*/
private String[] retrieve(String key) {
if (!Settings.messagesLanguage.equalsIgnoreCase(language)) {
reloadMessages();
}
String message = (String) get(key);
if (message != null) {
return formatMessage(message);
}
// Message is null: log key not being found and send error back as message
String retrievalError = "Error getting message with key '" + key + "'. ";
ConsoleLogger.showError(retrievalError + "Please verify your config file at '"
+ getConfigFile().getName() + "'");
return new String[]{
retrievalError + "Please contact the admin to verify or update the AuthMe messages file."};
}
private static String[] formatMessage(String message) {
// TODO: Check that the codes actually exist, i.e. replace &c but not &y
// TODO: Allow '&' to be retained with the code '&&'
String[] lines = message.split("&n");
for (int i = 0; i < lines.length; ++i) {
// We don't initialize a StringBuilder here because mostly we will only have one entry
lines[i] = lines[i].replace("&", SECTION_SIGN);
}
return lines;
}
public void reloadMessages() {
singleton = new Messages(Settings.messageFile, Settings.messagesLanguage);
}
}
@@ -8,7 +8,11 @@ import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.configuration.file.YamlConfiguration;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -17,12 +21,13 @@ import java.util.regex.Pattern;
/**
*/
public final class Settings extends YamlConfiguration {
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");
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
public static final File EMAIL_FILE = new File(PLUGIN_FOLDER, "email.html");
public 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!
@@ -68,7 +73,7 @@ public final class Settings extends YamlConfiguration {
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect,
customAttributes, generateImage, isRemoveSpeedEnabled, isMySQLWebsite;
customAttributes, generateImage, isRemoveSpeedEnabled;
public static String helpHeader, getNickRegex, getUnloggedinGroup, getMySQLHost,
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
getMySQLTablename, getMySQLColumnName, getMySQLColumnPassword,
@@ -116,7 +121,7 @@ public final class Settings extends YamlConfiguration {
if (!exist) {
plugin.saveDefaultConfig();
}
instance.load(SETTINGS_FILE);
configFile.load(SETTINGS_FILE);
if (exist) {
instance.mergeConfig();
}
@@ -231,7 +236,7 @@ public final class Settings extends YamlConfiguration {
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
getMailSubject = configFile.getString("Email.mailSubject", "Your new AuthMe Password");
getMailText = configFile.getString("Email.mailText", "Dear <playername>, <br /><br /> This is your new AuthMe password for the server <br /><br /> <servername> : <br /><br /> <generatedpass><br /><br />Do not forget to change password after login! <br /> /changepassword <generatedpass> newPassword");
getMailText = loadEmailText();
emailRegistration = configFile.getBoolean("settings.registration.enableEmailRegistrationSystem", false);
saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8);
getmaxRegPerEmail = configFile.getInt("Email.maxRegPerEmail", 1);
@@ -289,20 +294,46 @@ public final class Settings extends YamlConfiguration {
forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole");
customAttributes = configFile.getBoolean("Hooks.customAttributes");
generateImage = configFile.getBoolean("Email.generateImage", false);
isMySQLWebsite = configFile.getBoolean("DataSource.mySQLWebsite", false);
// Load the welcome message
getWelcomeMessage();
}
/**
* Method setValue.
*
* @param key String
* @param value Object
*/
public static void setValue(String key, Object value) {
private static String loadEmailText() {
if (!EMAIL_FILE.exists())
saveDefaultEmailText();
StringBuilder str = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new FileReader(EMAIL_FILE));
String s;
while ((s = in.readLine()) != null)
str.append(s);
in.close();
} catch(IOException e)
{
}
return str.toString();
}
private static void saveDefaultEmailText() {
InputStream file = plugin.getResource("email.html");
StringBuilder str = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(file, Charset.forName("utf-8")));
String s;
while ((s = in.readLine()) != null)
str.append(s);
in.close();
Files.touch(EMAIL_FILE);
Files.write(str.toString(), EMAIL_FILE, Charsets.UTF_8);
}
catch(Exception e)
{
}
}
public static void setValue(String key, Object value) {
instance.set(key, value);
save();
}
@@ -373,9 +404,9 @@ public final class Settings extends YamlConfiguration {
*/
public static boolean save() {
try {
instance.save(SETTINGS_FILE);
configFile.save(SETTINGS_FILE);
return true;
} catch (Exception ex) {
} catch (IOException ex) {
return false;
}
}
@@ -593,7 +624,7 @@ public final class Settings extends YamlConfiguration {
set("VeryGames.enableIpCheck", false);
changes = true;
}
if (getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) {
if (configFile.getString("settings.restrictions.allowedNicknameCharacters").equals("[a-zA-Z0-9_?]*")) {
set("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_]*");
changes = true;
}
@@ -681,9 +712,11 @@ public final class Settings extends YamlConfiguration {
set("DataSource.mySQLRealName", "realname");
changes = true;
}
if (!contains("DataSource.mySQLWebsite")) {
set("DataSource.mySQLWebsite", false);
changes = true;
if (contains("Email.mailText"))
{
set("Email.mailText", null);
ConsoleLogger.showError("Remove Email.mailText from config, we now use the email.html file");
}
if (changes) {
@@ -692,6 +725,15 @@ public final class Settings extends YamlConfiguration {
}
}
private static boolean contains(String path) {
return configFile.contains(path);
}
// public because it's used in AuthMe at one place
public void set(String path, Object value) {
configFile.set(path, value);
}
/**
* Saves current configuration (plus defaults) to disk.
* <p>
@@ -700,11 +742,13 @@ public final class Settings extends YamlConfiguration {
* @return True if saved successfully
*/
public final boolean saveDefaults() {
options().copyDefaults(true);
options().copyHeader(true);
configFile.options()
.copyDefaults(true)
.copyHeader(true);
boolean success = save();
options().copyDefaults(false);
options().copyHeader(false);
configFile.options()
.copyDefaults(false)
.copyHeader(false);
return success;
}
}