Cleanup, take 3
This commit is contained in:
parent
ec3db792ed
commit
4f1d6585cf
@ -71,7 +71,6 @@ import java.io.IOException;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -88,8 +87,9 @@ public class AuthMe extends JavaPlugin {
|
|||||||
// Costants
|
// Costants
|
||||||
private static final String PLUGIN_NAME = "AuthMeReloaded";
|
private static final String PLUGIN_NAME = "AuthMeReloaded";
|
||||||
private static final String LOG_FILENAME = "authme.log";
|
private static final String LOG_FILENAME = "authme.log";
|
||||||
|
private static final String FLATFILE_FILENAME = "auths.db";
|
||||||
private static final int SQLITE_MAX_SIZE = 4000;
|
private static final int SQLITE_MAX_SIZE = 4000;
|
||||||
private final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE;
|
private static final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE;
|
||||||
|
|
||||||
// Default version and build number values;
|
// Default version and build number values;
|
||||||
private static String pluginVersion = "N/D";
|
private static String pluginVersion = "N/D";
|
||||||
@ -210,8 +210,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
instantiateServices(injector);
|
instantiateServices(injector);
|
||||||
|
|
||||||
// Set up Metrics
|
// Reload support hook
|
||||||
MetricsManager.sendMetrics(this, settings);
|
reloadSupportHook();
|
||||||
|
|
||||||
// Do a backup on start
|
// Do a backup on start
|
||||||
// TODO: maybe create a backup manager?
|
// TODO: maybe create a backup manager?
|
||||||
@ -231,6 +231,9 @@ public class AuthMe extends JavaPlugin {
|
|||||||
ConsoleLogger.warning("Warning! This server uses PermissionsBukkit for permissions. Some permissions features may not be supported!");
|
ConsoleLogger.warning("Warning! This server uses PermissionsBukkit for permissions. Some permissions features may not be supported!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up Metrics
|
||||||
|
MetricsManager.sendMetrics(this, settings);
|
||||||
|
|
||||||
// Sponsor messages
|
// Sponsor messages
|
||||||
ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt.");
|
ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt.");
|
||||||
ConsoleLogger.info("Do you want a good game server? Look at our sponsor GameHosting.it leader in Italy as Game Server Provider!");
|
ConsoleLogger.info("Do you want a good game server? Look at our sponsor GameHosting.it leader in Italy as Game Server Provider!");
|
||||||
@ -374,15 +377,17 @@ public class AuthMe extends JavaPlugin {
|
|||||||
* @see AuthMe#database
|
* @see AuthMe#database
|
||||||
*/
|
*/
|
||||||
private void setupDatabase() throws ClassNotFoundException, SQLException, IOException {
|
private void setupDatabase() throws ClassNotFoundException, SQLException, IOException {
|
||||||
if (this.database != null) {
|
if (database != null) {
|
||||||
this.database.close();
|
database.close();
|
||||||
|
database = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
||||||
DataSource dataSource;
|
DataSource dataSource;
|
||||||
switch (dataSourceType) {
|
switch (dataSourceType) {
|
||||||
case FILE:
|
case FILE:
|
||||||
dataSource = new FlatFile(this);
|
File source = new File(getDataFolder(), FLATFILE_FILENAME);
|
||||||
|
dataSource = new FlatFile(source);
|
||||||
break;
|
break;
|
||||||
case MYSQL:
|
case MYSQL:
|
||||||
dataSource = new MySQL(settings);
|
dataSource = new MySQL(settings);
|
||||||
@ -416,6 +421,55 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop/unload the server/plugin as defined in the configuration
|
||||||
|
public void stopOrUnload() {
|
||||||
|
if (settings == null || settings.getProperty(SecuritySettings.STOP_SERVER_ON_PROBLEM)) {
|
||||||
|
ConsoleLogger.warning("THE SERVER IS GOING TO SHUT DOWN AS DEFINED IN THE CONFIGURATION!");
|
||||||
|
setEnabled(false);
|
||||||
|
getServer().shutdown();
|
||||||
|
} else {
|
||||||
|
setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleRecallEmailTask() {
|
||||||
|
if (!settings.getProperty(RECALL_PLAYERS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (PlayerAuth auth : database.getLoggedPlayers()) {
|
||||||
|
String email = auth.getEmail();
|
||||||
|
if (StringUtils.isEmpty(email) || "your@email.com".equalsIgnoreCase(email)) {
|
||||||
|
Player player = bukkitService.getPlayerExact(auth.getRealName());
|
||||||
|
if (player != null) {
|
||||||
|
messages.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1, 1200 * settings.getProperty(EmailSettings.DELAY_RECALL));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: check this, do we really need it? -sgdc3
|
||||||
|
private void reloadSupportHook() {
|
||||||
|
if (database != null) {
|
||||||
|
int playersOnline = bukkitService.getOnlinePlayers().size();
|
||||||
|
if (playersOnline == 0) {
|
||||||
|
database.purgeLogged();
|
||||||
|
} else if (settings.getProperty(SecuritySettings.USE_RELOAD_COMMAND_SUPPORT)) {
|
||||||
|
for (PlayerAuth auth : database.getLoggedPlayers()) {
|
||||||
|
if (auth != null) {
|
||||||
|
//auth.setLastLogin(new Date().getTime());
|
||||||
|
//database.updateSession(auth);
|
||||||
|
playerCache.addPlayer(auth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Save player data
|
// Save player data
|
||||||
@ -489,16 +543,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
ConsoleLogger.close();
|
ConsoleLogger.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop/unload the server/plugin as defined in the configuration
|
|
||||||
public void stopOrUnload() {
|
|
||||||
if (settings == null || settings.getProperty(SecuritySettings.STOP_SERVER_ON_PROBLEM)) {
|
|
||||||
ConsoleLogger.warning("THE SERVER IS GOING TO SHUT DOWN AS DEFINED IN THE CONFIGURATION!");
|
|
||||||
getServer().shutdown();
|
|
||||||
} else {
|
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save Player Data
|
// Save Player Data
|
||||||
private void savePlayer(Player player, LimboCache limboCache, ValidationService validationService) {
|
private void savePlayer(Player player, LimboCache limboCache, ValidationService validationService) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
@ -532,26 +576,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
return pluginHooks != null && pluginHooks.isNpc(player) || player.hasMetadata("NPC");
|
return pluginHooks != null && pluginHooks.isNpc(player) || player.hasMetadata("NPC");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleRecallEmailTask() {
|
|
||||||
if (!settings.getProperty(RECALL_PLAYERS)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (PlayerAuth auth : database.getLoggedPlayers()) {
|
|
||||||
String email = auth.getEmail();
|
|
||||||
if (StringUtils.isEmpty(email) || "your@email.com".equalsIgnoreCase(email)) {
|
|
||||||
Player player = bukkitService.getPlayerExact(auth.getRealName());
|
|
||||||
if (player != null) {
|
|
||||||
messages.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1, 1200 * settings.getProperty(EmailSettings.DELAY_RECALL));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String replaceAllInfo(String message, Player player) {
|
public String replaceAllInfo(String message, Player player) {
|
||||||
String playersOnline = Integer.toString(bukkitService.getOnlinePlayers().size());
|
String playersOnline = Integer.toString(bukkitService.getOnlinePlayers().size());
|
||||||
String ipAddress = Utils.getPlayerIp(player);
|
String ipAddress = Utils.getPlayerIp(player);
|
||||||
@ -566,6 +590,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
.replace("{WORLD}", player.getWorld().getName())
|
.replace("{WORLD}", player.getWorld().getName())
|
||||||
.replace("{SERVER}", server.getServerName())
|
.replace("{SERVER}", server.getServerName())
|
||||||
.replace("{VERSION}", server.getBukkitVersion())
|
.replace("{VERSION}", server.getBukkitVersion())
|
||||||
|
// TODO: We should cache info like this, maybe with a class that extends Player?
|
||||||
.replace("{COUNTRY}", geoLiteApi.getCountryName(ipAddress));
|
.replace("{COUNTRY}", geoLiteApi.getCountryName(ipAddress));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
@ -41,19 +39,13 @@ public class FlatFile implements DataSource {
|
|||||||
*/
|
*/
|
||||||
private final File source;
|
private final File source;
|
||||||
|
|
||||||
public FlatFile(AuthMe authMe) throws IOException {
|
public FlatFile(File source) throws IOException {
|
||||||
source = new File(authMe.getDataFolder(), "auths.db");
|
this.source = source;
|
||||||
boolean createResult = source.createNewFile();
|
if (!source.exists() && !source.createNewFile()) {
|
||||||
if (!createResult) {
|
|
||||||
throw new IOException("Could not create file '" + source.getPath() + "'");
|
throw new IOException("Could not create file '" + source.getPath() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public FlatFile(File source) {
|
|
||||||
this.source = source;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
throw new UnsupportedOperationException("Flatfile no longer supported");
|
throw new UnsupportedOperationException("Flatfile no longer supported");
|
||||||
|
|||||||
@ -66,6 +66,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private PlayerDataTaskManager playerDataTaskManager;
|
private PlayerDataTaskManager playerDataTaskManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Management management;
|
||||||
|
|
||||||
AsynchronousJoin() {
|
AsynchronousJoin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.process.register;
|
package fr.xephi.authme.process.register;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
@ -8,6 +7,7 @@ import fr.xephi.authme.mail.SendMailSSL;
|
|||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.process.ProcessService;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
@ -32,9 +32,6 @@ import static fr.xephi.authme.permission.PlayerStatePermission.ALLOW_MULTIPLE_AC
|
|||||||
|
|
||||||
public class AsyncRegister implements AsynchronousProcess {
|
public class AsyncRegister implements AsynchronousProcess {
|
||||||
|
|
||||||
@Inject
|
|
||||||
private AuthMe plugin;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private DataSource database;
|
private DataSource database;
|
||||||
|
|
||||||
@ -59,6 +56,9 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private SendMailSSL sendMailSsl;
|
private SendMailSSL sendMailSsl;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Management management;
|
||||||
|
|
||||||
AsyncRegister() { }
|
AsyncRegister() { }
|
||||||
|
|
||||||
private boolean preRegisterCheck(Player player, String password) {
|
private boolean preRegisterCheck(Player player, String password) {
|
||||||
@ -163,7 +163,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!service.getProperty(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER) && autoLogin) {
|
if (!service.getProperty(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER) && autoLogin) {
|
||||||
plugin.getManagement().performLogin(player, "dontneed", true);
|
management.performLogin(player, "dontneed", true);
|
||||||
}
|
}
|
||||||
syncProcessManager.processSyncPasswordRegister(player);
|
syncProcessManager.processSyncPasswordRegister(player);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user