2
0
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:
Tux 2014-08-09 15:32:12 -04:00
parent 62cdf7af1b
commit befd4d0d26
4 changed files with 22 additions and 21 deletions

View File

@ -179,7 +179,7 @@ public final class RedisBungee extends Plugin {
if (i.equals(serverId))
continue;
keys.add("server:" + i + ":usersOnline");
keys.add("proxy:" + i + ":usersOnline");
}
if (!keys.isEmpty()) {
Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()]));
@ -245,7 +245,7 @@ public final class RedisBungee extends Plugin {
boolean found = false;
for (String proxyId : getServerIds()) {
if (proxyId.equals(serverId)) continue;
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", uuid.toString())) {
if (tmpRsc.sismember("proxy:" + proxyId + ":usersOnline", uuid.toString())) {
found = true;
break;
}
@ -386,13 +386,13 @@ public final class RedisBungee extends Plugin {
Jedis tmpRsc = pool.getResource();
try {
Collection<String> players = getLocalPlayersAsUuidStrings();
for (String member : tmpRsc.smembers("server:" + serverId + ":usersOnline"))
for (String member : tmpRsc.smembers("proxy:" + serverId + ":usersOnline"))
if (!players.contains(member)) {
// Are they simply on a different proxy?
boolean found = false;
for (String proxyId : getServerIds()) {
if (proxyId.equals(serverId)) continue;
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", member)) {
if (tmpRsc.sismember("proxy:" + proxyId + ":usersOnline", member)) {
// Just clean up the set.
found = true;
break;
@ -402,7 +402,7 @@ public final class RedisBungee extends Plugin {
RedisUtil.cleanUpPlayer(member, tmpRsc);
getLogger().warning("Player found in set that was not found locally and globally: " + member);
} 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);
}
}
@ -426,8 +426,8 @@ public final class RedisBungee extends Plugin {
try {
tmpRsc.hdel("playerCounts", serverId);
tmpRsc.hdel("heartbeats", serverId);
if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) {
Set<String> players = tmpRsc.smembers("server:" + serverId + ":usersOnline");
if (tmpRsc.scard("proxy:" + serverId + ":usersOnline") > 0) {
Set<String> players = tmpRsc.smembers("proxy:" + serverId + ":usersOnline");
Pipeline pipeline = tmpRsc.pipelined();
for (String member : players)
RedisUtil.cleanUpPlayer(member, pipeline);

View File

@ -48,10 +48,11 @@ public class RedisBungeeConsumer implements Runnable {
if (event instanceof PlayerLoggedInConsumerEvent) {
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
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(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
plugin.getUuidTranslator().persistInfo(event1.getPlayer().getName(), event1.getPlayer().getUniqueId(), pipeline);
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "proxy", plugin.getServerId());
pipeline.sync();
} else if (event instanceof PlayerLoggedOffConsumerEvent) {
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;

View File

@ -32,11 +32,10 @@ public class RedisBungeeListener implements Listener {
@EventHandler
public void onPlayerConnect(final PostLoginEvent event) {
if (plugin.getPool() != null) {
Jedis rsc = plugin.getPool().getResource();
try {
for (String server : plugin.getServerIds()) {
if (rsc.sismember("server:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
if (rsc.sismember("proxy:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color(
ChatColor.RED).create());
return;
@ -45,7 +44,6 @@ public class RedisBungeeListener implements Listener {
} finally {
plugin.getPool().returnResource(rsc);
}
}
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
}

View File

@ -11,14 +11,16 @@ import redis.clients.jedis.Pipeline;
class RedisUtil {
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, "ip");
rsc.hdel("player:" + player, "proxy");
}
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, "ip");
rsc.hdel("player:" + player, "proxy");
}
}