mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-26 04:05:28 +01:00
Remove cache-update bungee messages, always use the player in the context to send bungee messages, minor codestyle changes
This commit is contained in:
parent
fd0a0a1155
commit
7c8bbe6294
@ -5,8 +5,6 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -23,18 +21,15 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
|
|||||||
@Inject
|
@Inject
|
||||||
private CommonService commonService;
|
private CommonService commonService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||||
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||||
|
|
||||||
if ("*".equals(playerName)) {
|
if ("*".equals(playerName)) {
|
||||||
for (PlayerAuth auth : dataSource.getAllAuths()) {
|
for (PlayerAuth auth : dataSource.getAllAuths()) {
|
||||||
resetLastPosition(auth);
|
resetLastPosition(auth);
|
||||||
dataSource.updateQuitLoc(auth);
|
dataSource.updateQuitLoc(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName);
|
// TODO: send an update when a messaging service will be implemented (QUITLOC)
|
||||||
}
|
}
|
||||||
sender.sendMessage("All players last position locations are now reset");
|
sender.sendMessage("All players last position locations are now reset");
|
||||||
} else {
|
} else {
|
||||||
@ -47,7 +42,7 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
|
|||||||
|
|
||||||
resetLastPosition(auth);
|
resetLastPosition(auth);
|
||||||
dataSource.updateQuitLoc(auth);
|
dataSource.updateQuitLoc(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName);
|
// TODO: send an update when a messaging service will be implemented (QUITLOC)
|
||||||
sender.sendMessage(playerName + "'s last position location is now reset");
|
sender.sendMessage(playerName + "'s last position location is now reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ import fr.xephi.authme.data.limbo.LimboService;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
@ -36,8 +34,6 @@ public class OnShutdownPlayerSaver {
|
|||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
@Inject
|
@Inject
|
||||||
private LimboService limboService;
|
private LimboService limboService;
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
OnShutdownPlayerSaver() {
|
OnShutdownPlayerSaver() {
|
||||||
}
|
}
|
||||||
@ -52,7 +48,7 @@ public class OnShutdownPlayerSaver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void savePlayer(Player player) {
|
private void savePlayer(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
if (PlayerUtils.isNpc(player) || validationService.isUnrestricted(name)) {
|
if (PlayerUtils.isNpc(player) || validationService.isUnrestricted(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -67,12 +63,12 @@ public class OnShutdownPlayerSaver {
|
|||||||
private void saveLoggedinPlayer(Player player) {
|
private void saveLoggedinPlayer(Player player) {
|
||||||
if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
||||||
Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
|
Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
|
||||||
final PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(player.getName().toLowerCase())
|
.name(player.getName().toLowerCase())
|
||||||
.realName(player.getName())
|
.realName(player.getName())
|
||||||
.location(loc).build();
|
.location(loc).build();
|
||||||
dataSource.updateQuitLoc(auth);
|
dataSource.updateQuitLoc(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, player.getName());
|
// TODO: send an update when a messaging service will be implemented (QUITLOC)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ import fr.xephi.authme.process.AsynchronousProcess;
|
|||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -33,9 +31,6 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
AsyncChangePassword() {
|
AsyncChangePassword() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,8 +41,8 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
* @param oldPassword the old password used by the player
|
* @param oldPassword the old password used by the player
|
||||||
* @param newPassword the new password chosen by the player
|
* @param newPassword the new password chosen by the player
|
||||||
*/
|
*/
|
||||||
public void changePassword(final Player player, String oldPassword, String newPassword) {
|
public void changePassword(Player player, String oldPassword, String newPassword) {
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
PlayerAuth auth = playerCache.getAuth(name);
|
PlayerAuth auth = playerCache.getAuth(name);
|
||||||
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
|
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
|
||||||
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
|
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
|
||||||
@ -57,7 +52,8 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
commonService.send(player, MessageKey.ERROR);
|
commonService.send(player, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, name);
|
|
||||||
|
// TODO: send an update when a messaging service will be implemented (PASSWORD_CHANGED)
|
||||||
|
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||||
@ -74,8 +70,8 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
* @param playerName the player name
|
* @param playerName the player name
|
||||||
* @param newPassword the new password chosen for the player
|
* @param newPassword the new password chosen for the player
|
||||||
*/
|
*/
|
||||||
public void changePasswordAsAdmin(CommandSender sender, final String playerName, String newPassword) {
|
public void changePasswordAsAdmin(CommandSender sender, String playerName, String newPassword) {
|
||||||
final String lowerCaseName = playerName.toLowerCase();
|
String lowerCaseName = playerName.toLowerCase();
|
||||||
if (!(playerCache.isAuthenticated(lowerCaseName) || dataSource.isAuthAvailable(lowerCaseName))) {
|
if (!(playerCache.isAuthenticated(lowerCaseName) || dataSource.isAuthAvailable(lowerCaseName))) {
|
||||||
if (sender == null) {
|
if (sender == null) {
|
||||||
logger.warning("Tried to change password for user " + lowerCaseName + " but it doesn't exist!");
|
logger.warning("Tried to change password for user " + lowerCaseName + " but it doesn't exist!");
|
||||||
@ -87,7 +83,8 @@ public class AsyncChangePassword implements AsynchronousProcess {
|
|||||||
|
|
||||||
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, lowerCaseName);
|
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, lowerCaseName);
|
||||||
if (dataSource.updatePassword(lowerCaseName, hashedPassword)) {
|
if (dataSource.updatePassword(lowerCaseName, hashedPassword)) {
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_PASSWORD, lowerCaseName);
|
// TODO: send an update when a messaging service will be implemented (PASSWORD_CHANGED)
|
||||||
|
|
||||||
if (sender != null) {
|
if (sender != null) {
|
||||||
commonService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
commonService.send(sender, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||||
logger.info(sender.getName() + " changed password of " + lowerCaseName);
|
logger.info(sender.getName() + " changed password of " + lowerCaseName);
|
||||||
|
@ -11,8 +11,6 @@ import fr.xephi.authme.process.AsynchronousProcess;
|
|||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -37,9 +35,6 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
@ -57,7 +52,7 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
|||||||
|
|
||||||
if (playerCache.isAuthenticated(playerName)) {
|
if (playerCache.isAuthenticated(playerName)) {
|
||||||
PlayerAuth auth = playerCache.getAuth(playerName);
|
PlayerAuth auth = playerCache.getAuth(playerName);
|
||||||
final String currentEmail = auth.getEmail();
|
String currentEmail = auth.getEmail();
|
||||||
|
|
||||||
if (!Utils.isEmailEmpty(currentEmail)) {
|
if (!Utils.isEmailEmpty(currentEmail)) {
|
||||||
service.send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
service.send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
||||||
@ -76,7 +71,7 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
|||||||
auth.setEmail(email);
|
auth.setEmail(email);
|
||||||
if (dataSource.updateEmail(auth)) {
|
if (dataSource.updateEmail(auth)) {
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, playerName);
|
// TODO: send an update when a messaging service will be implemented (ADD_MAIL)
|
||||||
service.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
service.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
logger.warning("Could not save email for player '" + player + "'");
|
logger.warning("Could not save email for player '" + player + "'");
|
||||||
|
@ -11,8 +11,6 @@ import fr.xephi.authme.process.AsynchronousProcess;
|
|||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -36,9 +34,6 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private ValidationService validationService;
|
private ValidationService validationService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
@ -56,7 +51,7 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
|||||||
String playerName = player.getName().toLowerCase();
|
String playerName = player.getName().toLowerCase();
|
||||||
if (playerCache.isAuthenticated(playerName)) {
|
if (playerCache.isAuthenticated(playerName)) {
|
||||||
PlayerAuth auth = playerCache.getAuth(playerName);
|
PlayerAuth auth = playerCache.getAuth(playerName);
|
||||||
final String currentEmail = auth.getEmail();
|
String currentEmail = auth.getEmail();
|
||||||
|
|
||||||
if (currentEmail == null) {
|
if (currentEmail == null) {
|
||||||
service.send(player, MessageKey.USAGE_ADD_EMAIL);
|
service.send(player, MessageKey.USAGE_ADD_EMAIL);
|
||||||
@ -94,7 +89,7 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
|||||||
auth.setEmail(newEmail);
|
auth.setEmail(newEmail);
|
||||||
if (dataSource.updateEmail(auth)) {
|
if (dataSource.updateEmail(auth)) {
|
||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_EMAIL, player.getName());
|
// TODO: send an update when a messaging service will be implemented (CHANGE_MAIL)
|
||||||
service.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
|
service.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
service.send(player, MessageKey.ERROR);
|
service.send(player, MessageKey.ERROR);
|
||||||
|
@ -89,9 +89,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
*
|
*
|
||||||
* @param player the player to process
|
* @param player the player to process
|
||||||
*/
|
*/
|
||||||
public void processJoin(final Player player) {
|
public void processJoin(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
final String ip = PlayerUtils.getPlayerIp(player);
|
String ip = PlayerUtils.getPlayerIp(player);
|
||||||
|
|
||||||
if (!validationService.fulfillsNameRestrictions(player)) {
|
if (!validationService.fulfillsNameRestrictions(player)) {
|
||||||
handlePlayerWithUnmetNameRestriction(player, ip);
|
handlePlayerWithUnmetNameRestriction(player, ip);
|
||||||
@ -116,7 +116,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
boolean isAuthAvailable = database.isAuthAvailable(name);
|
||||||
|
|
||||||
if (isAuthAvailable) {
|
if (isAuthAvailable) {
|
||||||
// Protect inventory
|
// Protect inventory
|
||||||
@ -153,7 +153,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Skip if registration is optional
|
// Skip if registration is optional
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.LOGIN, name);
|
bungeeSender.sendAuthMeBungeecordMessage(player, MessageType.LOGIN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
* @param isAuthAvailable true if the player is registered, false otherwise
|
* @param isAuthAvailable true if the player is registered, false otherwise
|
||||||
*/
|
*/
|
||||||
private void processJoinSync(Player player, boolean isAuthAvailable) {
|
private void processJoinSync(Player player, boolean isAuthAvailable) {
|
||||||
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
|
|
||||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
||||||
limboService.createLimboPlayer(player, isAuthAvailable);
|
limboService.createLimboPlayer(player, isAuthAvailable);
|
||||||
@ -204,7 +204,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
*
|
*
|
||||||
* @return true if the verification is OK (no infraction), false if player has been kicked
|
* @return true if the verification is OK (no infraction), false if player has been kicked
|
||||||
*/
|
*/
|
||||||
private boolean validatePlayerCountForIp(final Player player, String ip) {
|
private boolean validatePlayerCountForIp(Player player, String ip) {
|
||||||
if (service.getProperty(RestrictionSettings.MAX_JOIN_PER_IP) > 0
|
if (service.getProperty(RestrictionSettings.MAX_JOIN_PER_IP) > 0
|
||||||
&& !service.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
&& !service.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||||
&& !InternetProtocolUtils.isLoopbackAddress(ip)
|
&& !InternetProtocolUtils.isLoopbackAddress(ip)
|
||||||
|
@ -153,7 +153,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
* (e.g. because he is already logged in)
|
* (e.g. because he is already logged in)
|
||||||
*/
|
*/
|
||||||
private PlayerAuth getPlayerAuth(Player player, boolean quiet) {
|
private PlayerAuth getPlayerAuth(Player player, boolean quiet) {
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
if (playerCache.isAuthenticated(name)) {
|
if (playerCache.isAuthenticated(name)) {
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
@ -179,7 +179,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = PlayerUtils.getPlayerIp(player);
|
String ip = PlayerUtils.getPlayerIp(player);
|
||||||
if (hasReachedMaxLoggedInPlayersForIp(player, ip)) {
|
if (hasReachedMaxLoggedInPlayersForIp(player, ip)) {
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
@ -206,7 +206,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
* false otherwise
|
* false otherwise
|
||||||
*/
|
*/
|
||||||
private boolean checkPlayerInfo(Player player, PlayerAuth auth, String password) {
|
private boolean checkPlayerInfo(Player player, PlayerAuth auth, String password) {
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
|
|
||||||
// If captcha is required send a message to the player and deny to log in
|
// If captcha is required send a message to the player and deny to log in
|
||||||
if (loginCaptchaManager.isCaptchaRequired(name)) {
|
if (loginCaptchaManager.isCaptchaRequired(name)) {
|
||||||
@ -214,7 +214,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = PlayerUtils.getPlayerIp(player);
|
String ip = PlayerUtils.getPlayerIp(player);
|
||||||
|
|
||||||
// Increase the counts here before knowing the result of the login.
|
// Increase the counts here before knowing the result of the login.
|
||||||
loginCaptchaManager.increaseLoginFailureCount(name);
|
loginCaptchaManager.increaseLoginFailureCount(name);
|
||||||
@ -266,18 +266,19 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
*/
|
*/
|
||||||
public void performLogin(Player player, PlayerAuth auth) {
|
public void performLogin(Player player, PlayerAuth auth) {
|
||||||
if (player.isOnline()) {
|
if (player.isOnline()) {
|
||||||
final boolean isFirstLogin = (auth.getLastLogin() == null);
|
boolean isFirstLogin = (auth.getLastLogin() == null);
|
||||||
|
|
||||||
// Update auth to reflect this new login
|
// Update auth to reflect this new login
|
||||||
final String ip = PlayerUtils.getPlayerIp(player);
|
String ip = PlayerUtils.getPlayerIp(player);
|
||||||
auth.setRealName(player.getName());
|
auth.setRealName(player.getName());
|
||||||
auth.setLastLogin(System.currentTimeMillis());
|
auth.setLastLogin(System.currentTimeMillis());
|
||||||
auth.setLastIp(ip);
|
auth.setLastIp(ip);
|
||||||
dataSource.updateSession(auth);
|
dataSource.updateSession(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, player.getName());
|
|
||||||
|
// TODO: send an update when a messaging service will be implemented (SESSION)
|
||||||
|
|
||||||
// Successful login, so reset the captcha & temp ban count
|
// Successful login, so reset the captcha & temp ban count
|
||||||
final String name = player.getName();
|
String name = player.getName();
|
||||||
loginCaptchaManager.resetLoginFailureCount(name);
|
loginCaptchaManager.resetLoginFailureCount(name);
|
||||||
tempbanManager.resetCount(ip, name);
|
tempbanManager.resetCount(ip, name);
|
||||||
player.setNoDamageTicks(0);
|
player.setNoDamageTicks(0);
|
||||||
@ -288,7 +289,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
List<String> auths = dataSource.getAllAuthsByIp(auth.getLastIp());
|
List<String> auths = dataSource.getAllAuthsByIp(auth.getLastIp());
|
||||||
displayOtherAccounts(auths, player);
|
displayOtherAccounts(auths, player);
|
||||||
|
|
||||||
final String email = auth.getEmail();
|
String email = auth.getEmail();
|
||||||
if (service.getProperty(EmailSettings.RECALL_PLAYERS) && Utils.isEmailEmpty(email)) {
|
if (service.getProperty(EmailSettings.RECALL_PLAYERS) && Utils.isEmailEmpty(email)) {
|
||||||
service.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
service.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||||
}
|
}
|
||||||
@ -299,7 +300,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
playerCache.updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
dataSource.setLogged(name);
|
dataSource.setLogged(name);
|
||||||
sessionService.grantSession(name);
|
sessionService.grantSession(name);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.LOGIN, name);
|
bungeeSender.sendAuthMeBungeecordMessage(player, MessageType.LOGIN);
|
||||||
|
|
||||||
// As the scheduling executes the Task most likely after the current
|
// As the scheduling executes the Task most likely after the current
|
||||||
// task, we schedule it in the end
|
// task, we schedule it in the end
|
||||||
@ -368,7 +369,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count logged in players with same IP address
|
// Count logged in players with same IP address
|
||||||
final String name = player.getName();
|
String name = player.getName();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
|
for (Player onlinePlayer : bukkitService.getOnlinePlayers()) {
|
||||||
if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(onlinePlayer))
|
if (ip.equalsIgnoreCase(PlayerUtils.getPlayerIp(onlinePlayer))
|
||||||
|
@ -51,7 +51,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
|||||||
* @param player the player wanting to log out
|
* @param player the player wanting to log out
|
||||||
*/
|
*/
|
||||||
public void logout(Player player) {
|
public void logout(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
if (!playerCache.isAuthenticated(name)) {
|
if (!playerCache.isAuthenticated(name)) {
|
||||||
service.send(player, MessageKey.NOT_LOGGED_IN);
|
service.send(player, MessageKey.NOT_LOGGED_IN);
|
||||||
return;
|
return;
|
||||||
@ -59,18 +59,18 @@ public class AsynchronousLogout implements AsynchronousProcess {
|
|||||||
|
|
||||||
PlayerAuth auth = playerCache.getAuth(name);
|
PlayerAuth auth = playerCache.getAuth(name);
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_SESSION, name);
|
// TODO: send an update when a messaging service will be implemented (SESSION)
|
||||||
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
||||||
auth.setQuitLocation(player.getLocation());
|
auth.setQuitLocation(player.getLocation());
|
||||||
database.updateQuitLoc(auth);
|
database.updateQuitLoc(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
// TODO: send an update when a messaging service will be implemented (QUITLOC)
|
||||||
}
|
}
|
||||||
|
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
codeManager.unverify(name);
|
codeManager.unverify(name);
|
||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
sessionService.revokeSession(name);
|
sessionService.revokeSession(name);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.LOGOUT, name);
|
bungeeSender.sendAuthMeBungeecordMessage(player, MessageType.LOGOUT);
|
||||||
syncProcessManager.processSyncPlayerLogout(player);
|
syncProcessManager.processSyncPlayerLogout(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ import fr.xephi.authme.process.SyncProcessManager;
|
|||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.SessionService;
|
import fr.xephi.authme.service.SessionService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
@ -53,9 +51,6 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private SessionService sessionService;
|
private SessionService sessionService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
AsynchronousQuit() {
|
AsynchronousQuit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,8 +63,8 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
if (player == null || validationService.isUnrestricted(player.getName())) {
|
if (player == null || validationService.isUnrestricted(player.getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
final boolean wasLoggedIn = playerCache.isAuthenticated(name);
|
boolean wasLoggedIn = playerCache.isAuthenticated(name);
|
||||||
|
|
||||||
if (wasLoggedIn) {
|
if (wasLoggedIn) {
|
||||||
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
|
||||||
@ -80,7 +75,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
database.updateQuitLoc(auth);
|
database.updateQuitLoc(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = PlayerUtils.getPlayerIp(player);
|
String ip = PlayerUtils.getPlayerIp(player);
|
||||||
PlayerAuth auth = PlayerAuth.builder()
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
.name(name)
|
.name(name)
|
||||||
.realName(player.getName())
|
.realName(player.getName())
|
||||||
@ -88,7 +83,8 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
|||||||
.lastLogin(System.currentTimeMillis())
|
.lastLogin(System.currentTimeMillis())
|
||||||
.build();
|
.build();
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, name);
|
|
||||||
|
// TODO: send an update when a messaging service will be implemented (QUITLOC)
|
||||||
}
|
}
|
||||||
|
|
||||||
//always unauthenticate the player - use session only for auto logins on the same ip
|
//always unauthenticate the player - use session only for auto logins on the same ip
|
||||||
|
@ -12,8 +12,6 @@ import fr.xephi.authme.process.register.executors.RegistrationMethod;
|
|||||||
import fr.xephi.authme.process.register.executors.RegistrationParameters;
|
import fr.xephi.authme.process.register.executors.RegistrationParameters;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.util.InternetProtocolUtils;
|
import fr.xephi.authme.util.InternetProtocolUtils;
|
||||||
@ -40,8 +38,6 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
private CommonService service;
|
private CommonService service;
|
||||||
@Inject
|
@Inject
|
||||||
private SingletonStore<RegistrationExecutor> registrationExecutorFactory;
|
private SingletonStore<RegistrationExecutor> registrationExecutorFactory;
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
AsyncRegister() {
|
AsyncRegister() {
|
||||||
}
|
}
|
||||||
@ -71,7 +67,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
* @return true if the checks are successful and the event hasn't marked the action as denied, false otherwise.
|
* @return true if the checks are successful and the event hasn't marked the action as denied, false otherwise.
|
||||||
*/
|
*/
|
||||||
private boolean preRegisterCheck(RegistrationMethod<?> variant, Player player) {
|
private boolean preRegisterCheck(RegistrationMethod<?> variant, Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
String name = player.getName().toLowerCase();
|
||||||
if (playerCache.isAuthenticated(name)) {
|
if (playerCache.isAuthenticated(name)) {
|
||||||
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
return false;
|
return false;
|
||||||
@ -104,7 +100,6 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
PlayerAuth auth = executor.buildPlayerAuth(parameters);
|
PlayerAuth auth = executor.buildPlayerAuth(parameters);
|
||||||
if (database.saveAuth(auth)) {
|
if (database.saveAuth(auth)) {
|
||||||
executor.executePostPersistAction(parameters);
|
executor.executePostPersistAction(parameters);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.REGISTER, parameters.getPlayerName());
|
|
||||||
} else {
|
} else {
|
||||||
service.send(parameters.getPlayer(), MessageKey.ERROR);
|
service.send(parameters.getPlayer(), MessageKey.ERROR);
|
||||||
}
|
}
|
||||||
@ -118,8 +113,8 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
* @return true if registration may take place, false otherwise (IP check failed)
|
* @return true if registration may take place, false otherwise (IP check failed)
|
||||||
*/
|
*/
|
||||||
private boolean isPlayerIpAllowedToRegister(Player player) {
|
private boolean isPlayerIpAllowedToRegister(Player player) {
|
||||||
final int maxRegPerIp = service.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP);
|
int maxRegPerIp = service.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP);
|
||||||
final String ip = PlayerUtils.getPlayerIp(player);
|
String ip = PlayerUtils.getPlayerIp(player);
|
||||||
if (maxRegPerIp > 0
|
if (maxRegPerIp > 0
|
||||||
&& !InternetProtocolUtils.isLoopbackAddress(ip)
|
&& !InternetProtocolUtils.isLoopbackAddress(ip)
|
||||||
&& !service.hasPermission(player, ALLOW_MULTIPLE_ACCOUNTS)) {
|
&& !service.hasPermission(player, ALLOW_MULTIPLE_ACCOUNTS)) {
|
||||||
|
@ -14,8 +14,6 @@ import fr.xephi.authme.security.PasswordSecurity;
|
|||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
@ -56,9 +54,6 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private BungeeSender bungeeSender;
|
|
||||||
|
|
||||||
AsynchronousUnregister() {
|
AsynchronousUnregister() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +65,8 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
* @param password the input password to check before unregister
|
* @param password the input password to check before unregister
|
||||||
*/
|
*/
|
||||||
public void unregister(Player player, String password) {
|
public void unregister(Player player, String password) {
|
||||||
final String name = player.getName();
|
String name = player.getName();
|
||||||
final PlayerAuth cachedAuth = playerCache.getAuth(name);
|
PlayerAuth cachedAuth = playerCache.getAuth(name);
|
||||||
if (passwordSecurity.comparePassword(password, cachedAuth.getPassword(), name)) {
|
if (passwordSecurity.comparePassword(password, cachedAuth.getPassword(), name)) {
|
||||||
if (dataSource.removeAuth(name)) {
|
if (dataSource.removeAuth(name)) {
|
||||||
performPostUnregisterActions(name, player);
|
performPostUnregisterActions(name, player);
|
||||||
@ -118,7 +113,8 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
*/
|
*/
|
||||||
private void performPostUnregisterActions(String name, Player player) {
|
private void performPostUnregisterActions(String name, Player player) {
|
||||||
playerCache.removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
bungeeSender.sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
|
||||||
|
// TODO: send an update when a messaging service will be implemented (UNREGISTER)
|
||||||
|
|
||||||
if (player == null || !player.isOnline()) {
|
if (player == null || !player.isOnline()) {
|
||||||
return;
|
return;
|
||||||
@ -137,7 +133,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyBlindEffect(final Player player) {
|
private void applyBlindEffect(Player player) {
|
||||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||||
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.service;
|
package fr.xephi.authme.service;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
@ -299,15 +298,13 @@ public class BukkitService implements SettingsDependent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the specified message to bungeecord using the first available player connection.
|
* Send the specified bytes to bungeecord using the specified player connection.
|
||||||
*
|
*
|
||||||
|
* @param player the player
|
||||||
* @param bytes the message
|
* @param bytes the message
|
||||||
*/
|
*/
|
||||||
public void sendBungeeMessage(byte[] bytes) {
|
public void sendBungeeMessage(Player player, byte[] bytes) {
|
||||||
Player player = Iterables.getFirst(getOnlinePlayers(), null);
|
player.sendPluginMessage(authMe, "BungeeCord", bytes);
|
||||||
if (player != null) {
|
|
||||||
player.sendPluginMessage(authMe, "BungeeCord", bytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,6 @@ import com.google.common.io.ByteStreams;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.ProxySessionManager;
|
import fr.xephi.authme.data.ProxySessionManager;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
|
||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
@ -27,29 +26,27 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
|
|||||||
private final BukkitService bukkitService;
|
private final BukkitService bukkitService;
|
||||||
private final ProxySessionManager proxySessionManager;
|
private final ProxySessionManager proxySessionManager;
|
||||||
private final Management management;
|
private final Management management;
|
||||||
private final DataSource dataSource;
|
|
||||||
|
|
||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BungeeReceiver(AuthMe plugin, BukkitService bukkitService, ProxySessionManager proxySessionManager,
|
BungeeReceiver(AuthMe plugin, BukkitService bukkitService, ProxySessionManager proxySessionManager,
|
||||||
Management management, DataSource dataSource, Settings settings) {
|
Management management, Settings settings) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.bukkitService = bukkitService;
|
this.bukkitService = bukkitService;
|
||||||
this.proxySessionManager = proxySessionManager;
|
this.proxySessionManager = proxySessionManager;
|
||||||
this.management = management;
|
this.management = management;
|
||||||
this.dataSource = dataSource;
|
|
||||||
reload(settings);
|
reload(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload(final Settings settings) {
|
public void reload(Settings settings) {
|
||||||
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
|
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
|
||||||
if (this.isEnabled) {
|
if (this.isEnabled) {
|
||||||
this.isEnabled = bukkitService.isBungeeCordConfiguredForSpigot().orElse(false);
|
this.isEnabled = bukkitService.isBungeeCordConfiguredForSpigot().orElse(false);
|
||||||
}
|
}
|
||||||
if (this.isEnabled) {
|
if (this.isEnabled) {
|
||||||
final Messenger messenger = plugin.getServer().getMessenger();
|
Messenger messenger = plugin.getServer().getMessenger();
|
||||||
if (!messenger.isIncomingChannelRegistered(plugin, "BungeeCord")) {
|
if (!messenger.isIncomingChannelRegistered(plugin, "BungeeCord")) {
|
||||||
messenger.registerIncomingPluginChannel(plugin, "BungeeCord", this);
|
messenger.registerIncomingPluginChannel(plugin, "BungeeCord", this);
|
||||||
}
|
}
|
||||||
@ -61,23 +58,23 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
|
|||||||
*
|
*
|
||||||
* @param in the input to handle
|
* @param in the input to handle
|
||||||
*/
|
*/
|
||||||
private void handleBroadcast(final ByteArrayDataInput in) {
|
private void handleBroadcast(ByteArrayDataInput in) {
|
||||||
// Read data byte array
|
// Read data byte array
|
||||||
final short dataLength = in.readShort();
|
short dataLength = in.readShort();
|
||||||
final byte[] dataBytes = new byte[dataLength];
|
byte[] dataBytes = new byte[dataLength];
|
||||||
in.readFully(dataBytes);
|
in.readFully(dataBytes);
|
||||||
final ByteArrayDataInput dataIn = ByteStreams.newDataInput(dataBytes);
|
ByteArrayDataInput dataIn = ByteStreams.newDataInput(dataBytes);
|
||||||
|
|
||||||
// Parse type
|
// Parse type
|
||||||
final String typeId = dataIn.readUTF();
|
String typeId = dataIn.readUTF();
|
||||||
final Optional<MessageType> type = MessageType.fromId(typeId);
|
Optional<MessageType> type = MessageType.fromId(typeId);
|
||||||
if (!type.isPresent()) {
|
if (!type.isPresent()) {
|
||||||
logger.debug("Received unsupported forwarded bungeecord message type! ({0})", typeId);
|
logger.debug("Received unsupported forwarded bungeecord message type! ({0})", typeId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse argument
|
// Parse argument
|
||||||
final String argument;
|
String argument;
|
||||||
try {
|
try {
|
||||||
argument = dataIn.readUTF();
|
argument = dataIn.readUTF();
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
@ -88,14 +85,9 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
|
|||||||
|
|
||||||
// Handle type
|
// Handle type
|
||||||
switch (type.get()) {
|
switch (type.get()) {
|
||||||
case UNREGISTER:
|
case LOGIN:
|
||||||
dataSource.invalidateCache(argument);
|
case LOGOUT:
|
||||||
break;
|
// TODO: unused
|
||||||
case REFRESH_PASSWORD:
|
|
||||||
case REFRESH_QUITLOC:
|
|
||||||
case REFRESH_EMAIL:
|
|
||||||
case REFRESH:
|
|
||||||
dataSource.refreshCache(argument);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
@ -108,15 +100,15 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
|
|||||||
*/
|
*/
|
||||||
private void handle(ByteArrayDataInput in) {
|
private void handle(ByteArrayDataInput in) {
|
||||||
// Parse type
|
// Parse type
|
||||||
final String typeId = in.readUTF();
|
String typeId = in.readUTF();
|
||||||
final Optional<MessageType> type = MessageType.fromId(typeId);
|
Optional<MessageType> type = MessageType.fromId(typeId);
|
||||||
if (!type.isPresent()) {
|
if (!type.isPresent()) {
|
||||||
logger.debug("Received unsupported bungeecord message type! ({0})", typeId);
|
logger.debug("Received unsupported bungeecord message type! ({0})", typeId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse argument
|
// Parse argument
|
||||||
final String argument;
|
String argument;
|
||||||
try {
|
try {
|
||||||
argument = in.readUTF();
|
argument = in.readUTF();
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
@ -135,15 +127,15 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(final String channel, final Player player, final byte[] data) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] data) {
|
||||||
if (!isEnabled) {
|
if (!isEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ByteArrayDataInput in = ByteStreams.newDataInput(data);
|
ByteArrayDataInput in = ByteStreams.newDataInput(data);
|
||||||
|
|
||||||
// Check subchannel
|
// Check subchannel
|
||||||
final String subChannel = in.readUTF();
|
String subChannel = in.readUTF();
|
||||||
if ("AuthMe.v2.Broadcast".equals(subChannel)) {
|
if ("AuthMe.v2.Broadcast".equals(subChannel)) {
|
||||||
handleBroadcast(in);
|
handleBroadcast(in);
|
||||||
} else if ("AuthMe.v2".equals(subChannel)) {
|
} else if ("AuthMe.v2".equals(subChannel)) {
|
||||||
@ -151,7 +143,7 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performLogin(final String name) {
|
private void performLogin(String name) {
|
||||||
Player player = bukkitService.getPlayerExact(name);
|
Player player = bukkitService.getPlayerExact(name);
|
||||||
if (player != null && player.isOnline()) {
|
if (player != null && player.isOnline()) {
|
||||||
management.forceLogin(player, true);
|
management.forceLogin(player, true);
|
||||||
|
@ -4,7 +4,6 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
|
||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
@ -20,7 +19,6 @@ public class BungeeSender implements SettingsDependent {
|
|||||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(BungeeSender.class);
|
private final ConsoleLogger logger = ConsoleLoggerFactory.get(BungeeSender.class);
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final BukkitService bukkitService;
|
private final BukkitService bukkitService;
|
||||||
private final DataSource dataSource;
|
|
||||||
|
|
||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
private String destinationServerOnLogin;
|
private String destinationServerOnLogin;
|
||||||
@ -29,21 +27,19 @@ public class BungeeSender implements SettingsDependent {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
BungeeSender(final AuthMe plugin, final BukkitService bukkitService, final DataSource dataSource,
|
BungeeSender(AuthMe plugin, BukkitService bukkitService, Settings settings) {
|
||||||
final Settings settings) {
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.bukkitService = bukkitService;
|
this.bukkitService = bukkitService;
|
||||||
this.dataSource = dataSource;
|
|
||||||
reload(settings);
|
reload(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload(final Settings settings) {
|
public void reload(Settings settings) {
|
||||||
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
|
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
|
||||||
this.destinationServerOnLogin = settings.getProperty(HooksSettings.BUNGEECORD_SERVER);
|
this.destinationServerOnLogin = settings.getProperty(HooksSettings.BUNGEECORD_SERVER);
|
||||||
|
|
||||||
if (this.isEnabled) {
|
if (this.isEnabled) {
|
||||||
final Messenger messenger = plugin.getServer().getMessenger();
|
Messenger messenger = plugin.getServer().getMessenger();
|
||||||
if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) {
|
if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) {
|
||||||
messenger.registerOutgoingPluginChannel(plugin, "BungeeCord");
|
messenger.registerOutgoingPluginChannel(plugin, "BungeeCord");
|
||||||
}
|
}
|
||||||
@ -54,27 +50,27 @@ public class BungeeSender implements SettingsDependent {
|
|||||||
return isEnabled;
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendBungeecordMessage(final String... data) {
|
private void sendBungeecordMessage(Player player, String... data) {
|
||||||
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
for (final String element : data) {
|
for (String element : data) {
|
||||||
out.writeUTF(element);
|
out.writeUTF(element);
|
||||||
}
|
}
|
||||||
bukkitService.sendBungeeMessage(out.toByteArray());
|
bukkitService.sendBungeeMessage(player, out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendForwardedBungeecordMessage(final String subChannel, final String... data) {
|
private void sendForwardedBungeecordMessage(Player player, String subChannel, String... data) {
|
||||||
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF("Forward");
|
out.writeUTF("Forward");
|
||||||
out.writeUTF("ONLINE");
|
out.writeUTF("ONLINE");
|
||||||
out.writeUTF(subChannel);
|
out.writeUTF(subChannel);
|
||||||
final ByteArrayDataOutput dataOut = ByteStreams.newDataOutput();
|
ByteArrayDataOutput dataOut = ByteStreams.newDataOutput();
|
||||||
for (final String element : data) {
|
for (String element : data) {
|
||||||
dataOut.writeUTF(element);
|
dataOut.writeUTF(element);
|
||||||
}
|
}
|
||||||
final byte[] dataBytes = dataOut.toByteArray();
|
byte[] dataBytes = dataOut.toByteArray();
|
||||||
out.writeShort(dataBytes.length);
|
out.writeShort(dataBytes.length);
|
||||||
out.write(dataBytes);
|
out.write(dataBytes);
|
||||||
bukkitService.sendBungeeMessage(out.toByteArray());
|
bukkitService.sendBungeeMessage(player, out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,33 +79,32 @@ public class BungeeSender implements SettingsDependent {
|
|||||||
*
|
*
|
||||||
* @param player The player to send.
|
* @param player The player to send.
|
||||||
*/
|
*/
|
||||||
public void connectPlayerOnLogin(final Player player) {
|
public void connectPlayerOnLogin(Player player) {
|
||||||
if (isEnabled && !destinationServerOnLogin.isEmpty()) {
|
if (!isEnabled || destinationServerOnLogin.isEmpty()) {
|
||||||
bukkitService.scheduleSyncDelayedTask(() ->
|
return;
|
||||||
sendBungeecordMessage("ConnectOther", player.getName(), destinationServerOnLogin), 5L);
|
|
||||||
}
|
}
|
||||||
|
bukkitService.scheduleSyncDelayedTask(() ->
|
||||||
|
sendBungeecordMessage(player, "Connect", destinationServerOnLogin), 5L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to the AuthMe plugin messaging channel, if enabled.
|
* Sends a message to the AuthMe plugin messaging channel, if enabled.
|
||||||
*
|
*
|
||||||
|
* @param player The player related to the message
|
||||||
* @param type The message type, See {@link MessageType}
|
* @param type The message type, See {@link MessageType}
|
||||||
* @param playerName the player related to the message
|
|
||||||
*/
|
*/
|
||||||
public void sendAuthMeBungeecordMessage(final MessageType type, final String playerName) {
|
public void sendAuthMeBungeecordMessage(Player player, MessageType type) {
|
||||||
if (isEnabled) {
|
if (!isEnabled) {
|
||||||
if (!plugin.isEnabled()) {
|
return;
|
||||||
logger.debug("Tried to send a " + type + " bungeecord message but the plugin was disabled!");
|
}
|
||||||
return;
|
if (!plugin.isEnabled()) {
|
||||||
}
|
logger.debug("Tried to send a " + type + " bungeecord message but the plugin was disabled!");
|
||||||
if (type.isRequiresCaching() && !dataSource.isCached()) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (type.isBroadcast()) {
|
||||||
if (type.isBroadcast()) {
|
sendForwardedBungeecordMessage(player, "AuthMe.v2.Broadcast", type.getId(), player.getName().toLowerCase());
|
||||||
sendForwardedBungeecordMessage("AuthMe.v2.Broadcast", type.getId(), playerName.toLowerCase());
|
} else {
|
||||||
} else {
|
sendBungeecordMessage(player, "AuthMe.v2", type.getId(), player.getName().toLowerCase());
|
||||||
sendBungeecordMessage("AuthMe.v2", type.getId(), playerName.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,29 +3,16 @@ package fr.xephi.authme.service.bungeecord;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public enum MessageType {
|
public enum MessageType {
|
||||||
REFRESH_PASSWORD("refresh.password", true, true),
|
|
||||||
REFRESH_SESSION("refresh.session", true, true),
|
|
||||||
REFRESH_QUITLOC("refresh.quitloc", true, true),
|
|
||||||
REFRESH_EMAIL("refresh.email", true, true),
|
|
||||||
REFRESH("refresh", true, true),
|
|
||||||
REGISTER("register", true),
|
|
||||||
UNREGISTER("unregister", true),
|
|
||||||
LOGIN("login", true),
|
LOGIN("login", true),
|
||||||
LOGOUT("logout", true),
|
LOGOUT("logout", true),
|
||||||
PERFORM_LOGIN("perform.login", false);
|
PERFORM_LOGIN("perform.login", false);
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final boolean broadcast;
|
private final boolean broadcast;
|
||||||
private final boolean requiresCaching;
|
|
||||||
|
|
||||||
MessageType(final String id, final boolean broadcast, final boolean requiresCaching) {
|
MessageType(String id, boolean broadcast) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.broadcast = broadcast;
|
this.broadcast = broadcast;
|
||||||
this.requiresCaching = requiresCaching;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageType(final String id, final boolean broadcast) {
|
|
||||||
this(id, broadcast, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@ -36,10 +23,6 @@ public enum MessageType {
|
|||||||
return broadcast;
|
return broadcast;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRequiresCaching() {
|
|
||||||
return requiresCaching;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the MessageType with the given ID.
|
* Returns the MessageType with the given ID.
|
||||||
*
|
*
|
||||||
@ -47,8 +30,8 @@ public enum MessageType {
|
|||||||
*
|
*
|
||||||
* @return the MessageType with the given id, empty if invalid.
|
* @return the MessageType with the given id, empty if invalid.
|
||||||
*/
|
*/
|
||||||
public static Optional<MessageType> fromId(final String id) {
|
public static Optional<MessageType> fromId(String id) {
|
||||||
for (final MessageType current : values()) {
|
for (MessageType current : values()) {
|
||||||
if (current.getId().equals(id)) {
|
if (current.getId().equals(id)) {
|
||||||
return Optional.of(current);
|
return Optional.of(current);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import fr.xephi.authme.service.BukkitService;
|
|||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.TeleportationService;
|
import fr.xephi.authme.service.TeleportationService;
|
||||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
@ -128,7 +127,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(teleportationService).teleportOnJoin(player);
|
verify(teleportationService).teleportOnJoin(player);
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(commandManager).runCommandsOnUnregister(player);
|
verify(commandManager).runCommandsOnUnregister(player);
|
||||||
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
|
||||||
verify(player).addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 21 * 20, 2));
|
verify(player).addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 21 * 20, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +159,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(teleportationService).teleportOnJoin(player);
|
verify(teleportationService).teleportOnJoin(player);
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(commandManager).runCommandsOnUnregister(player);
|
verify(commandManager).runCommandsOnUnregister(player);
|
||||||
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
|
||||||
verify(player, never()).addPotionEffect(any(PotionEffect.class));
|
verify(player, never()).addPotionEffect(any(PotionEffect.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +188,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verifyNoInteractions(teleportationService, limboService);
|
verifyNoInteractions(teleportationService, limboService);
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
|
||||||
verify(commandManager).runCommandsOnUnregister(player);
|
verify(commandManager).runCommandsOnUnregister(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +239,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verifyNoInteractions(teleportationService);
|
verifyNoInteractions(teleportationService);
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initiator known and Player object available
|
// Initiator known and Player object available
|
||||||
@ -270,7 +265,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(teleportationService).teleportOnJoin(player);
|
verify(teleportationService).teleportOnJoin(player);
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(commandManager).runCommandsOnUnregister(player);
|
verify(commandManager).runCommandsOnUnregister(player);
|
||||||
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -287,7 +281,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verifyNoInteractions(teleportationService);
|
verifyNoInteractions(teleportationService);
|
||||||
verifyCalledUnregisterEventFor(null);
|
verifyCalledUnregisterEventFor(null);
|
||||||
verify(bungeeSender).sendAuthMeBungeecordMessage(MessageType.UNREGISTER, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user