mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
Store user's proxy in their hash and rename the server: keys to proxy: to make their purpose more clear.
This commit is contained in:
parent
62cdf7af1b
commit
befd4d0d26
@ -179,7 +179,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
if (i.equals(serverId))
|
if (i.equals(serverId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
keys.add("server:" + i + ":usersOnline");
|
keys.add("proxy:" + i + ":usersOnline");
|
||||||
}
|
}
|
||||||
if (!keys.isEmpty()) {
|
if (!keys.isEmpty()) {
|
||||||
Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()]));
|
Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()]));
|
||||||
@ -245,7 +245,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getServerIds()) {
|
||||||
if (proxyId.equals(serverId)) continue;
|
if (proxyId.equals(serverId)) continue;
|
||||||
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", uuid.toString())) {
|
if (tmpRsc.sismember("proxy:" + proxyId + ":usersOnline", uuid.toString())) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -386,13 +386,13 @@ public final class RedisBungee extends Plugin {
|
|||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
Collection<String> players = getLocalPlayersAsUuidStrings();
|
Collection<String> players = getLocalPlayersAsUuidStrings();
|
||||||
for (String member : tmpRsc.smembers("server:" + serverId + ":usersOnline"))
|
for (String member : tmpRsc.smembers("proxy:" + serverId + ":usersOnline"))
|
||||||
if (!players.contains(member)) {
|
if (!players.contains(member)) {
|
||||||
// Are they simply on a different proxy?
|
// Are they simply on a different proxy?
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getServerIds()) {
|
||||||
if (proxyId.equals(serverId)) continue;
|
if (proxyId.equals(serverId)) continue;
|
||||||
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", member)) {
|
if (tmpRsc.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
||||||
// Just clean up the set.
|
// Just clean up the set.
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@ -402,7 +402,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||||
getLogger().warning("Player found in set that was not found locally and globally: " + member);
|
getLogger().warning("Player found in set that was not found locally and globally: " + member);
|
||||||
} else {
|
} else {
|
||||||
tmpRsc.srem("server:" + serverId + ":usersOnline", member);
|
tmpRsc.srem("proxy:" + serverId + ":usersOnline", member);
|
||||||
getLogger().warning("Player found in set that was not found locally, but is on another proxy: " + member);
|
getLogger().warning("Player found in set that was not found locally, but is on another proxy: " + member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -426,8 +426,8 @@ public final class RedisBungee extends Plugin {
|
|||||||
try {
|
try {
|
||||||
tmpRsc.hdel("playerCounts", serverId);
|
tmpRsc.hdel("playerCounts", serverId);
|
||||||
tmpRsc.hdel("heartbeats", serverId);
|
tmpRsc.hdel("heartbeats", serverId);
|
||||||
if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) {
|
if (tmpRsc.scard("proxy:" + serverId + ":usersOnline") > 0) {
|
||||||
Set<String> players = tmpRsc.smembers("server:" + serverId + ":usersOnline");
|
Set<String> players = tmpRsc.smembers("proxy:" + serverId + ":usersOnline");
|
||||||
Pipeline pipeline = tmpRsc.pipelined();
|
Pipeline pipeline = tmpRsc.pipelined();
|
||||||
for (String member : players)
|
for (String member : players)
|
||||||
RedisUtil.cleanUpPlayer(member, pipeline);
|
RedisUtil.cleanUpPlayer(member, pipeline);
|
||||||
|
@ -48,10 +48,11 @@ public class RedisBungeeConsumer implements Runnable {
|
|||||||
if (event instanceof PlayerLoggedInConsumerEvent) {
|
if (event instanceof PlayerLoggedInConsumerEvent) {
|
||||||
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
|
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
|
||||||
Pipeline pipeline = jedis.pipelined();
|
Pipeline pipeline = jedis.pipelined();
|
||||||
pipeline.sadd("server:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
|
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
|
||||||
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
|
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
|
||||||
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
|
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
|
||||||
plugin.getUuidTranslator().persistInfo(event1.getPlayer().getName(), event1.getPlayer().getUniqueId(), pipeline);
|
plugin.getUuidTranslator().persistInfo(event1.getPlayer().getName(), event1.getPlayer().getUniqueId(), pipeline);
|
||||||
|
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "proxy", plugin.getServerId());
|
||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
} else if (event instanceof PlayerLoggedOffConsumerEvent) {
|
} else if (event instanceof PlayerLoggedOffConsumerEvent) {
|
||||||
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
|
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
|
||||||
|
@ -32,19 +32,17 @@ public class RedisBungeeListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerConnect(final PostLoginEvent event) {
|
public void onPlayerConnect(final PostLoginEvent event) {
|
||||||
if (plugin.getPool() != null) {
|
Jedis rsc = plugin.getPool().getResource();
|
||||||
Jedis rsc = plugin.getPool().getResource();
|
try {
|
||||||
try {
|
for (String server : plugin.getServerIds()) {
|
||||||
for (String server : plugin.getServerIds()) {
|
if (rsc.sismember("proxy:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
|
||||||
if (rsc.sismember("server:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
|
event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color(
|
||||||
event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color(
|
ChatColor.RED).create());
|
||||||
ChatColor.RED).create());
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
plugin.getPool().returnResource(rsc);
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
plugin.getPool().returnResource(rsc);
|
||||||
}
|
}
|
||||||
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
|
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,16 @@ import redis.clients.jedis.Pipeline;
|
|||||||
|
|
||||||
class RedisUtil {
|
class RedisUtil {
|
||||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
public static void cleanUpPlayer(String player, Jedis rsc) {
|
||||||
rsc.srem("server:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
||||||
rsc.hdel("player:" + player, "server");
|
rsc.hdel("player:" + player, "server");
|
||||||
rsc.hdel("player:" + player, "ip");
|
rsc.hdel("player:" + player, "ip");
|
||||||
|
rsc.hdel("player:" + player, "proxy");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
||||||
rsc.srem("server:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
||||||
rsc.hdel("player:" + player, "server");
|
rsc.hdel("player:" + player, "server");
|
||||||
rsc.hdel("player:" + player, "ip");
|
rsc.hdel("player:" + player, "ip");
|
||||||
|
rsc.hdel("player:" + player, "proxy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user