Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into command-perms-refactor
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* Console filter Class
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class ConsoleFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public boolean isLoggable(LogRecord record) {
|
||||
try {
|
||||
if (record == null || record.getMessage() == null)
|
||||
return true;
|
||||
String logM = record.getMessage().toLowerCase();
|
||||
if (!logM.contains("issued server command:"))
|
||||
return true;
|
||||
if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ") && !logM.contains("/authme reg ") && !logM.contains("/authme cp ") && !logM.contains("/register "))
|
||||
return true;
|
||||
String playerName = record.getMessage().split(" ")[0];
|
||||
record.setMessage(playerName + " issued an AuthMe command!");
|
||||
return true;
|
||||
} catch (NullPointerException npe) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.core.Filter;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.Logger;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
|
||||
/**
|
||||
* Implements a filter for Log4j to skip sensitive AuthMe commands.
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class Log4JFilter implements Filter {
|
||||
|
||||
/**
|
||||
* List of commands (lower-case) to skip.
|
||||
*/
|
||||
private static final String[] COMMANDS_TO_SKIP = {"/login ", "/l ", "/reg ", "/changepassword ",
|
||||
"/unregister ", "/authme register ", "/authme changepassword ", "/authme reg ", "/authme cp ",
|
||||
"/register "};
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Log4JFilter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a Message instance and returns the {@link Result} value
|
||||
* depending on whether the message contains sensitive AuthMe data.
|
||||
*
|
||||
* @param message the Message object to verify
|
||||
*
|
||||
* @return the Result value
|
||||
*/
|
||||
private static Result validateMessage(Message message) {
|
||||
if (message == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
return validateMessage(message.getFormattedMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a message and returns the {@link Result} value depending
|
||||
* on whether the message contains sensitive AuthMe data.
|
||||
*
|
||||
* @param message the message to verify
|
||||
*
|
||||
* @return the Result value
|
||||
*/
|
||||
private static Result validateMessage(String message) {
|
||||
if (message == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
String lowerMessage = message.toLowerCase();
|
||||
if (lowerMessage.contains("issued server command:")
|
||||
&& StringUtils.containsAny(lowerMessage, COMMANDS_TO_SKIP)) {
|
||||
return Result.DENY;
|
||||
}
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(LogEvent record) {
|
||||
if (record == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
return validateMessage(record.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger arg0, Level arg1, Marker arg2, String message, Object... arg4) {
|
||||
return validateMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger arg0, Level arg1, Marker arg2, Object message, Throwable arg4) {
|
||||
if (message == null) {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
return validateMessage(message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result filter(Logger arg0, Level arg1, Marker arg2, Message message, Throwable arg4) {
|
||||
return validateMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getOnMatch() {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getOnMismatch() {
|
||||
return Result.NEUTRAL;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
/**
|
||||
* Keys for translatable messages managed by {@link Messages}.
|
||||
*/
|
||||
public enum MessageKey {
|
||||
|
||||
KICK_ANTIBOT("kick_antibot"),
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Class for retrieving and sending translatable messages to players.
|
||||
* This class detects when the language settings have changed and will
|
||||
* automatically update to use a new language file.
|
||||
*/
|
||||
public class Messages {
|
||||
|
||||
private static Messages singleton;
|
||||
private final String language;
|
||||
private MessagesManager manager;
|
||||
|
||||
|
||||
private Messages(String language, MessagesManager manager) {
|
||||
this.language = language;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance of Messages.
|
||||
*
|
||||
* @return The Messages instance
|
||||
*/
|
||||
public static Messages getInstance() {
|
||||
if (singleton == null) {
|
||||
MessagesManager manager = new MessagesManager(Settings.messageFile);
|
||||
singleton = new Messages(Settings.messagesLanguage, manager);
|
||||
}
|
||||
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 = manager.retrieve(key.getKey());
|
||||
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) {
|
||||
if (!Settings.messagesLanguage.equalsIgnoreCase(language)) {
|
||||
reloadManager();
|
||||
}
|
||||
return manager.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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the messages manager.
|
||||
*/
|
||||
public void reloadManager() {
|
||||
manager = new MessagesManager(Settings.messageFile);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.CustomConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Class responsible for reading messages from a file and formatting them for Minecraft.
|
||||
* <p />
|
||||
* This class is used within {@link Messages}, which offers a high-level interface for accessing
|
||||
* or sending messages from a properties file.
|
||||
*/
|
||||
class MessagesManager extends CustomConfiguration {
|
||||
|
||||
/** The section symbol, used in Minecraft for formatting codes. */
|
||||
private static final String SECTION_SIGN = "\u00a7";
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for Messages.
|
||||
*
|
||||
* @param file the configuration file
|
||||
*/
|
||||
MessagesManager(File file) {
|
||||
super(file);
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the message from the configuration file.
|
||||
*
|
||||
* @param key The key to retrieve
|
||||
*
|
||||
* @return The message
|
||||
*/
|
||||
String[] retrieve(String key) {
|
||||
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."};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user