mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 04:08:02 +00:00
Better firing of network events when we need to resync.
This commit is contained in:
parent
4e09efe801
commit
cd3f5f1b7e
@ -357,7 +357,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
if (proxiedPlayer == null)
|
if (proxiedPlayer == null)
|
||||||
continue; // We'll deal with it later.
|
continue; // We'll deal with it later.
|
||||||
|
|
||||||
RedisUtil.createPlayer(proxiedPlayer, pipeline);
|
RedisUtil.createPlayer(proxiedPlayer, pipeline, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
|
@ -110,7 +110,7 @@ public class RedisBungeeListener implements Listener {
|
|||||||
|
|
||||||
Pipeline pipeline = jedis.pipelined();
|
Pipeline pipeline = jedis.pipelined();
|
||||||
plugin.getUuidTranslator().persistInfo(event.getConnection().getName(), event.getConnection().getUniqueId(), pipeline);
|
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.
|
// We're not publishing, the API says we only publish at PostLoginEvent time.
|
||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
|
|
||||||
@ -139,11 +139,7 @@ public class RedisBungeeListener implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
protected Void call(Jedis jedis) {
|
protected Void call(Jedis jedis) {
|
||||||
Pipeline pipeline = jedis.pipelined();
|
Pipeline pipeline = jedis.pipelined();
|
||||||
long timestamp = System.currentTimeMillis();
|
|
||||||
RedisUtil.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
|
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();
|
pipeline.sync();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -36,17 +36,18 @@ import redis.clients.jedis.Pipeline;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class RedisUtil {
|
public class RedisUtil {
|
||||||
protected static void createPlayer(ProxiedPlayer player, Pipeline pipeline) {
|
protected static void createPlayer(ProxiedPlayer player, Pipeline pipeline, boolean fireEvent) {
|
||||||
createPlayer(player.getPendingConnection(), pipeline);
|
createPlayer(player.getPendingConnection(), pipeline, fireEvent);
|
||||||
if (player.getServer() != null)
|
if (player.getServer() != null)
|
||||||
pipeline.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
|
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);
|
Map<String, String> playerData = new HashMap<>(4);
|
||||||
playerData.put("online", "0");
|
playerData.put("online", "0");
|
||||||
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
|
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.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", connection.getUniqueId().toString());
|
||||||
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
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.
|
// Compatibility restraints prevent me from using using HDEL with multiple keys.
|
||||||
@ -64,6 +71,9 @@ public class RedisUtil {
|
|||||||
rsc.hdel("player:" + player, "proxy");
|
rsc.hdel("player:" + player, "proxy");
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
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) {
|
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
||||||
@ -73,6 +83,9 @@ public class RedisUtil {
|
|||||||
rsc.hdel("player:" + player, "proxy");
|
rsc.hdel("player:" + player, "proxy");
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
|
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) {
|
public static boolean canUseLua(String redisVersion) {
|
||||||
|
Loading…
Reference in New Issue
Block a user