2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-25 13:38:02 +00:00

Better firing of network events when we need to resync.

This commit is contained in:
Tux 2015-10-03 23:45:34 -04:00
parent 4e09efe801
commit cd3f5f1b7e
3 changed files with 18 additions and 9 deletions

View File

@ -357,7 +357,7 @@ public final class RedisBungee extends Plugin {
if (proxiedPlayer == null)
continue; // We'll deal with it later.
RedisUtil.createPlayer(proxiedPlayer, pipeline);
RedisUtil.createPlayer(proxiedPlayer, pipeline, true);
}
pipeline.sync();

View File

@ -110,7 +110,7 @@ public class RedisBungeeListener implements Listener {
Pipeline pipeline = jedis.pipelined();
plugin.getUuidTranslator().persistInfo(event.getConnection().getName(), event.getConnection().getUniqueId(), pipeline);
RedisUtil.createPlayer(event.getConnection(), pipeline);
RedisUtil.createPlayer(event.getConnection(), pipeline, false);
// We're not publishing, the API says we only publish at PostLoginEvent time.
pipeline.sync();
@ -139,11 +139,7 @@ public class RedisBungeeListener implements Listener {
@Override
protected Void call(Jedis jedis) {
Pipeline pipeline = jedis.pipelined();
long timestamp = System.currentTimeMillis();
RedisUtil.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp))));
pipeline.sync();
return null;
}

View File

@ -36,17 +36,18 @@ import redis.clients.jedis.Pipeline;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@VisibleForTesting
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RedisUtil {
protected static void createPlayer(ProxiedPlayer player, Pipeline pipeline) {
createPlayer(player.getPendingConnection(), pipeline);
protected static void createPlayer(ProxiedPlayer player, Pipeline pipeline, boolean fireEvent) {
createPlayer(player.getPendingConnection(), pipeline, fireEvent);
if (player.getServer() != null)
pipeline.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
}
protected static void createPlayer(PendingConnection connection, Pipeline pipeline) {
protected static void createPlayer(PendingConnection connection, Pipeline pipeline, boolean fireEvent) {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
@ -54,6 +55,12 @@ public class RedisUtil {
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", connection.getUniqueId().toString());
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
if (fireEvent) {
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
connection.getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(connection.getAddress().getAddress()))));
}
}
// Compatibility restraints prevent me from using using HDEL with multiple keys.
@ -64,6 +71,9 @@ public class RedisUtil {
rsc.hdel("player:" + player, "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
UUID.fromString(player), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp))));
}
public static void cleanUpPlayer(String player, Pipeline rsc) {
@ -73,6 +83,9 @@ public class RedisUtil {
rsc.hdel("player:" + player, "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
UUID.fromString(player), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp))));
}
public static boolean canUseLua(String redisVersion) {