2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-22 20:28:00 +00:00

Always kick the new player in online mode.

Allowing the new player on is more seamless, but does not synchronize well, so I've forced a kick instead, which is a cleaner solution at the expense of minor inconvenience.
This commit is contained in:
Tux 2015-06-22 04:54:15 -04:00
parent ff602bc5e6
commit 8c05655330

View File

@ -60,6 +60,11 @@ public class RedisBungeeListener implements Listener {
.append("\n\nIf you were disconnected forcefully, please wait up to one minute.\nIf this does not resolve your issue, please contact staff.") .append("\n\nIf you were disconnected forcefully, please wait up to one minute.\nIf this does not resolve your issue, please contact staff.")
.color(ChatColor.GRAY) .color(ChatColor.GRAY)
.create(); .create();
private static final BaseComponent[] ONLINE_MODE_RECONNECT =
new ComponentBuilder("Whoops! You need to reconnect.").color(ChatColor.RED)
.append("\n\nWe found someone online using your username. They were kicked and you may reconnect.\nIf this does not work, please contact staff.")
.color(ChatColor.GRAY)
.create();
private final RedisBungee plugin; private final RedisBungee plugin;
private final List<InetAddress> exemptAddresses; private final List<InetAddress> exemptAddresses;
@ -74,22 +79,30 @@ public class RedisBungeeListener implements Listener {
return null; return null;
} }
// If a player with this name isn't on this proxy, we make sure they aren't trying to use an existing // We make sure they aren't trying to use an existing player's name.
// player's name. This is BungeeCord behavior I disapprove of but I don't really care at this point. // This is problematic for online-mode servers as they always disconnect old clients.
ProxiedPlayer player = plugin.getProxy().getPlayer(event.getConnection().getName()); if (plugin.getProxy().getConfig().isOnlineMode()) {
ProxiedPlayer player = plugin.getProxy().getPlayer(event.getConnection().getName());
if (player == null) { if (player != null) {
String online = jedis.hget("player:" + event.getConnection().getUniqueId().toString(), "online");
if (online != null && online.equals("0")) {
event.setCancelled(true); event.setCancelled(true);
// TODO: Make it accept a BaseComponent[] like everything else. // TODO: Make it accept a BaseComponent[] like everything else.
event.setCancelReason(TextComponent.toLegacyText(ALREADY_LOGGED_IN)); event.setCancelReason(TextComponent.toLegacyText(ONLINE_MODE_RECONNECT));
event.completeIntent(plugin); event.completeIntent(plugin);
return null; return null;
} }
} }
String online = jedis.hget("player:" + event.getConnection().getUniqueId().toString(), "online");
if (online != null && online.equals("0")) {
event.setCancelled(true);
// TODO: Make it accept a BaseComponent[] like everything else.
event.setCancelReason(TextComponent.toLegacyText(ALREADY_LOGGED_IN));
event.completeIntent(plugin);
return null;
}
Map<String, String> playerData = new HashMap<>(4); Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0"); playerData.put("online", "0");
playerData.put("ip", event.getConnection().getAddress().getAddress().getHostAddress()); playerData.put("ip", event.getConnection().getAddress().getAddress().getHostAddress());