diff --git a/src/main/java/fr/xephi/authme/settings/custom/ConverterSettings.java b/src/main/java/fr/xephi/authme/settings/custom/ConverterSettings.java new file mode 100644 index 000000000..7cee6a521 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/ConverterSettings.java @@ -0,0 +1,46 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +public class ConverterSettings extends CustomSetting { + + @Comment("Rakamak file name") + @Type(SettingType.String) + public String rakamakFileName = "users.rak"; + + @Comment("Rakamak use Ip ?") + @Type(SettingType.Boolean) + public boolean rakamakeUseIP = false; + + @Comment("Rakamak IP file name") + @Type(SettingType.String) + public String rakamakIPFileName = "UsersIp.rak"; + + @Comment("CrazyLogin database file name") + @Type(SettingType.String) + public String crazyLoginFileName = "accounts.db"; + + private static File configFile = new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "converter.yml"); + + private ConverterSettings instance; + + public ConverterSettings() + { + super(configFile); + instance = this; + } + + public ConverterSettings getInstance() { + return instance; + } + + public void setInstance(ConverterSettings instance) { + this.instance = instance; + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/CustomSetting.java b/src/main/java/fr/xephi/authme/settings/custom/CustomSetting.java new file mode 100644 index 000000000..27792efd9 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/CustomSetting.java @@ -0,0 +1,156 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.List; + +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.settings.CustomConfiguration; +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; + +public class CustomSetting extends CustomConfiguration { + + private File configFile; + public boolean isFirstLaunch = false; + + public CustomSetting(File file) { + super(file); + this.configFile = file; + try { + if (!configFile.exists()) + { + isFirstLaunch = true; + configFile.createNewFile(); + } + else + { + load(); + loadValues(); + } + save(); + } catch (IOException e) + { + ConsoleLogger.writeStackTrace(e); + } + } + + @Override + public boolean reLoad() + { + boolean out = true; + if (!configFile.exists()) { + try { + configFile.createNewFile(); + save(); + } catch (IOException e) { + out = false; + } + } + if (out) + { + load(); + loadValues(); + } + return out; + } + + public void loadValues() + { + for (Field f : this.getClass().getDeclaredFields()) + { + if (!f.isAnnotationPresent(Type.class)) + continue; + f.setAccessible(true); + try { + switch (f.getAnnotation(Type.class).value()) + { + case Boolean: + f.setBoolean(this, this.getBoolean(f.getName())); + break; + case Double: + f.setDouble(this, this.getDouble(f.getName())); + break; + case Int: + f.setInt(this, this.getInt(f.getName())); + break; + case Long: + f.setLong(this, this.getLong(f.getName())); + break; + case String: + f.set(this, this.getString(f.getName())); + break; + case StringList: + f.set(this, this.getStringList(f.getName())); + break; + default: + break; + } + } catch (Exception e) + { + ConsoleLogger.writeStackTrace(e); + } + } + } + + @Override + public void save() + { + FileWriter writer = null; + try { + writer = new FileWriter(configFile); + writer.write(""); + for (Field f : this.getClass().getDeclaredFields()) + { + if (!f.isAnnotationPresent(Comment.class)) + continue; + if (!f.isAnnotationPresent(Type.class)) + continue; + for (String s : f.getAnnotation(Comment.class).value()) + { + writer.append("# " + s + "\n"); + } + writer.append(f.getName() + ": "); + switch (f.getAnnotation(Type.class).value()) + { + case Boolean: + writer.append(f.getBoolean(this) ? "true" : "false"); + break; + case Double: + writer.append("" + f.getDouble(this)); + break; + case Int: + writer.append("" + f.getInt(this)); + break; + case String: + writer.append("'" + f.get(this).toString() + "'"); + break; + case StringList: + @SuppressWarnings("unchecked") + List list = (List) f.get(this); + writer.append("\n"); + if (list.isEmpty()) + writer.write("[]"); + else + for (String s : list) + writer.append(" - '" + s + "'\n"); + break; + case Long: + writer.append("" + f.getLong(this)); + break; + default: + break; + + } + writer.append("\n"); + writer.flush(); + } + writer.close(); + } catch (Exception e) { + ConsoleLogger.writeStackTrace(e); + } + } + +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java b/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java new file mode 100644 index 000000000..c3c20c6bd --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java @@ -0,0 +1,121 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; + +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +public class DatabaseSettings extends CustomSetting { + + @Comment({"What type of database do you want to use?", + "Valid values: sqlite, mysql"}) + @Type(SettingType.String) + public String backend = "sqlite"; + + @Comment("Enable database caching, should improve database performance") + @Type(SettingType.Boolean) + public boolean caching = true; + + @Comment("Database host address") + @Type(SettingType.String) + public String mySQLHost = "127.0.0.1"; + + @Comment("Database port") + @Type(SettingType.String) + public String mySQLPort = "3306"; + + @Comment("Username about Database Connection Infos") + @Type(SettingType.String) + public String mySQLUsername = "authme"; + + @Comment("Password about Database Connection Infos") + @Type(SettingType.String) + public String mySQLPassword = "12345"; + + @Comment("Database Name, use with converters or as SQLITE database name") + @Type(SettingType.String) + public String mySQLDatabase = "authme"; + + @Comment("Table of the database") + @Type(SettingType.String) + public String mySQLTablename = "authme"; + + @Comment("Column of IDs to sort data") + @Type(SettingType.String) + public String mySQLColumnId = "id"; + + @Comment("Column for storing or checking players nickname") + @Type(SettingType.String) + public String mySQLColumnName = "username"; + + @Comment("Column for storing or checking players RealName ") + @Type(SettingType.String) + public String mySQLColumnRealName = "realname"; + + @Comment("Column for storing players passwords") + @Type(SettingType.String) + public String mySQLColumnPassword = "password"; + + @Comment("Column for storing players passwords salts") + @Type(SettingType.String) + public String mySQLColumnSalt = ""; + + @Comment("Column for storing players emails") + @Type(SettingType.String) + public String mySQLColumnEmail = "email"; + + @Comment("Column for storing if a player is logged in or not") + @Type(SettingType.String) + public String mySQLColumnLogged = "isLogged"; + + @Comment("Column for storing players ips") + @Type(SettingType.String) + public String mySQLColumnIp = "ip"; + + @Comment("Column for storing players lastlogins") + @Type(SettingType.String) + public String mySQLColumnLastLogin = "lastlogin"; + + @Comment("Column for storing player LastLocation - X") + @Type(SettingType.String) + public String mySQLColumnLastLocX = "x"; + + @Comment("Column for storing player LastLocation - Y") + @Type(SettingType.String) + public String mySQLColumnLastLocY = "y"; + + @Comment("Column for storing player LastLocation - Z") + @Type(SettingType.String) + public String mySQLColumnLastLocZ = "z"; + + @Comment("Column for storing player LastLocation - World Name") + @Type(SettingType.String) + public String mySQLColumnLastLocWorld = "world"; + + @Comment("Column for storing players groups") + @Type(SettingType.String) + public String mySQLColumnGroup = ""; + + @Comment("Enable this when you allow registration through a website") + @Type(SettingType.Boolean) + public boolean mySQLWebsite = false; + + private static File configFile = new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "database.yml"); + + private DatabaseSettings instance; + + public DatabaseSettings() + { + super(configFile); + instance = this; + } + + public DatabaseSettings getInstance() { + return instance; + } + + public void setInstance(DatabaseSettings instance) { + this.instance = instance; + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/EmailSettings.java b/src/main/java/fr/xephi/authme/settings/custom/EmailSettings.java new file mode 100644 index 000000000..d6cc36753 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/EmailSettings.java @@ -0,0 +1,83 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +public class EmailSettings extends CustomSetting { + + @Comment("Email SMTP server host") + @Type(SettingType.String) + public String mailSMTP = "smtp.gmail.com"; + + @Comment("Email SMTP server port") + @Type(SettingType.Int) + public int mailPort = 465; + + @Comment("Email account whose send the mail") + @Type(SettingType.String) + public String mailAccount = ""; + + @Comment("Email account password") + @Type(SettingType.String) + public String mailPassword = ""; + + @Comment("Random password length") + @Type(SettingType.Int) + public int recoveryPasswordLength = 8; + + @Comment("Mail Subject") + @Type(SettingType.String) + public String mailSubject = "Your new AuthMe password"; + + @Comment("Like maxRegPerIP but with email") + @Type(SettingType.Int) + public int maxRegPerEmail = 1; + + @Comment("Recall players to add an email ?") + @Type(SettingType.Boolean) + public boolean recallPlayers = false; + + @Comment("Delay in minute for the recall scheduler") + @Type(SettingType.Int) + public int delayRecall = 5; + + @Comment("Blacklist these domains for emails") + @Type(SettingType.StringList) + public List emailBlackListed = new ArrayList(); + + @Comment("Whitelist ONLY these domains for emails") + @Type(SettingType.StringList) + public List emailWhiteListed = new ArrayList(); + + @Comment("Do we need to send new password draw in an image ?") + @Type(SettingType.Boolean) + public boolean generateImage = false; + + private static File configFile = new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "emails.yml"); + + private EmailSettings instance; + + public EmailSettings() + { + super(configFile); + instance = this; + if (this.isFirstLaunch) + { + this.emailBlackListed.add("10minutemail.com"); + save(); + } + } + + public EmailSettings getInstance() { + return instance; + } + + public void setInstance(EmailSettings instance) { + this.instance = instance; + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java b/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java new file mode 100644 index 000000000..307c79062 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java @@ -0,0 +1,54 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +public class HooksSettings extends CustomSetting { + + @Comment("Do we need to hook with multiverse for spawn checking?") + @Type(SettingType.Boolean) + public boolean multiverse = true; + + @Comment("Do we need to hook with BungeeCord ?") + @Type(SettingType.Boolean) + public boolean bungeecord = false; + + @Comment("Send player to this BungeeCord server after register/login") + @Type(SettingType.String) + public String sendPlayerTo = ""; + + @Comment("Do we need to disable Essentials SocialSpy on join?") + @Type(SettingType.Boolean) + public boolean disableSocialSpy = false; + + @Comment("Do we need to force /motd Essentials command on join?") + @Type(SettingType.Boolean) + public boolean useEssentialsMotd = false; + + @Comment("Do we need to cache custom Attributes?") + @Type(SettingType.Boolean) + public boolean customAttributes = false; + + private static File configFile = new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "hooks.yml"); + + private HooksSettings instance; + + public HooksSettings() + { + super(configFile); + instance = this; + } + + public HooksSettings getInstance() { + return instance; + } + + public void setInstance(HooksSettings instance) { + this.instance = instance; + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/ProtectionSettings.java b/src/main/java/fr/xephi/authme/settings/custom/ProtectionSettings.java new file mode 100644 index 000000000..e8e2d059c --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/ProtectionSettings.java @@ -0,0 +1,63 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +public class ProtectionSettings extends CustomSetting { + + @Comment("Enable some servers protection ( country based login, antibot )") + @Type(SettingType.Boolean) + public boolean enableProtection = false; + + @Comment({"Countries allowed to join the server and register, see http://dev.bukkit.org/bukkit-plugins/authme-reloaded/pages/countries-codes/ for countries' codes", + "PLEASE USE QUOTES !"}) + @Type(SettingType.StringList) + public List countriesWhitelist = new ArrayList(); + + @Comment({"Countries not allowed to join the server and register", + "PLEASE USE QUOTES !"}) + @Type(SettingType.StringList) + public List countriesBlacklist = new ArrayList(); + + @Comment("Do we need to enable automatic antibot system?") + @Type(SettingType.Boolean) + public boolean enableAntiBot = false; + + @Comment("Max number of player allowed to login in 5 secs before enable AntiBot system automatically") + @Type(SettingType.Int) + public int antiBotSensibility = 5; + + @Comment("Duration in minutes of the antibot automatic system") + @Type(SettingType.Int) + public int antiBotDuration = 10; + + private static File configFile = new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "protection.yml"); + + private ProtectionSettings instance; + + public ProtectionSettings() + { + super(configFile); + instance = this; + if (this.isFirstLaunch) + { + this.countriesWhitelist.add("US"); + this.countriesWhitelist.add("GB"); + this.countriesBlacklist.add("A1"); + save(); + } + } + + public ProtectionSettings getInstance() { + return instance; + } + + public void setInstance(ProtectionSettings instance) { + this.instance = instance; + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/PurgeSettings.java b/src/main/java/fr/xephi/authme/settings/custom/PurgeSettings.java new file mode 100644 index 000000000..3b85e2fb0 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/PurgeSettings.java @@ -0,0 +1,62 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +public class PurgeSettings extends CustomSetting { + + @Comment("If enabled, AuthMe automatically purges old, unused accounts") + @Type(SettingType.Boolean) + public boolean useAutoPurge = false; + + @Comment("Number of Days an account become Unused") + @Type(SettingType.Int) + public int daysBeforeRemovePlayer = 60; + + @Comment("Do we need to remove the player.dat file during purge process?") + @Type(SettingType.Boolean) + public boolean removePlayerDat = false; + + @Comment("Do we need to remove the Essentials/users/player.yml file during purge process?") + @Type(SettingType.Boolean) + public boolean removeEssentialsFiles = false; + + @Comment("World where are players.dat stores") + @Type(SettingType.String) + public String defaultWorld = "world"; + + @Comment("Do we need to remove LimitedCreative/inventories/player.yml, player_creative.yml files during purge process ?") + @Type(SettingType.Boolean) + public boolean removeLimiteCreativeInventories = false; + + @Comment("Do we need to remove the AntiXRayData/PlayerData/player file during purge process?") + @Type(SettingType.Boolean) + public boolean removeAntiXRayFile = false; + + @Comment("Do we need to remove permissions?") + @Type(SettingType.Boolean) + public boolean removePermissions = false; + + private static File configFile = new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "purge.yml"); + + private PurgeSettings instance; + + public PurgeSettings() + { + super(configFile); + instance = this; + } + + public PurgeSettings getInstance() { + return instance; + } + + public void setInstance(PurgeSettings instance) { + this.instance = instance; + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/SecuritySettings.java b/src/main/java/fr/xephi/authme/settings/custom/SecuritySettings.java new file mode 100644 index 000000000..3166cbe26 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/SecuritySettings.java @@ -0,0 +1,60 @@ +package fr.xephi.authme.settings.custom; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import fr.xephi.authme.settings.custom.annotations.Comment; +import fr.xephi.authme.settings.custom.annotations.Type; +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +public class SecuritySettings extends CustomSetting { + + @Comment({"Stop the server if we can't contact the sql database", + "Take care with this, if you set that to false,", + "AuthMe automatically disable and the server is not protected!"}) + @Type(SettingType.Boolean) + public boolean stopServerOnProblem = true; + + @Comment("/reload support") + @Type(SettingType.Boolean) + public boolean useReloadCommandSupport = true; + + @Comment("Remove Spam from Console ?") + @Type(SettingType.Boolean) + public boolean removeSpamFromConsole = false; + + @Comment("Remove Password from Console ?") + @Type(SettingType.Boolean) + public boolean removePasswordFromConsole = true; + + @Comment("Player need to put a captcha when he fails too lot the password") + @Type(SettingType.Boolean) + public boolean useCaptcha = false; + + @Comment("Max allowed tries before request a captcha") + @Type(SettingType.Int) + public int maxLoginTryBeforeCaptcha = 5; + + @Comment("Captcha length ") + @Type(SettingType.Int) + public int captchaLength = 5; + + private static File configFile = new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "security.yml"); + + private SecuritySettings instance; + + public SecuritySettings() + { + super(configFile); + instance = this; + } + + public SecuritySettings getInstance() { + return instance; + } + + public void setInstance(SecuritySettings instance) { + this.instance = instance; + } +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/annotations/Comment.java b/src/main/java/fr/xephi/authme/settings/custom/annotations/Comment.java new file mode 100644 index 000000000..d711a1943 --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/annotations/Comment.java @@ -0,0 +1,20 @@ +package fr.xephi.authme.settings.custom.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * Add a comment to a field value + * + * @author xephi59 + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Comment { + + public String[] value() default ""; +} diff --git a/src/main/java/fr/xephi/authme/settings/custom/annotations/Type.java b/src/main/java/fr/xephi/authme/settings/custom/annotations/Type.java new file mode 100644 index 000000000..aae0af52b --- /dev/null +++ b/src/main/java/fr/xephi/authme/settings/custom/annotations/Type.java @@ -0,0 +1,43 @@ +package fr.xephi.authme.settings.custom.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import fr.xephi.authme.settings.custom.annotations.Type.SettingType; + +/** +* +* Set the type of a field value +* +* @author xephi59 +* +*/ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Type { + + public enum SettingType { + String(0), + Int(1), + Boolean(2), + Double(3), + StringList(4), + Long(5); + + private int type; + + SettingType(int type) + { + this.type = type; + } + + public int getType() + { + return this.type; + } + } + + public SettingType value() default SettingType.String; +}