mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Better resyncing of missing players on the proxy.
This commit is contained in:
parent
d1bfb9e162
commit
e285b3f2aa
@ -37,16 +37,14 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.*;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
@ -343,14 +341,23 @@ public final class RedisBungee extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
Pipeline pipeline = tmpRsc.pipelined();
|
||||
|
||||
for (String player : players) {
|
||||
if (redisCollection.contains(player))
|
||||
continue;
|
||||
|
||||
// Player not online according to Redis but not BungeeCord.
|
||||
getLogger().warning("Player " + player + " is on the proxy but not in Redis.");
|
||||
tmpRsc.sadd("proxy:" + configuration.getServerId() + ":usersOnline", player);
|
||||
|
||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(UUID.fromString(player));
|
||||
if (proxiedPlayer == null)
|
||||
continue; // We'll deal with it later.
|
||||
|
||||
RedisUtil.createPlayer(proxiedPlayer.getPendingConnection(), pipeline);
|
||||
}
|
||||
|
||||
pipeline.sync();
|
||||
}
|
||||
}
|
||||
}, 0, 1, TimeUnit.MINUTES);
|
||||
|
@ -108,15 +108,9 @@ public class RedisBungeeListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> playerData = new HashMap<>(4);
|
||||
playerData.put("online", "0");
|
||||
playerData.put("ip", event.getConnection().getAddress().getAddress().getHostAddress());
|
||||
playerData.put("proxy", RedisBungee.getConfiguration().getServerId());
|
||||
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event.getConnection().getUniqueId().toString());
|
||||
plugin.getUuidTranslator().persistInfo(event.getConnection().getName(), event.getConnection().getUniqueId(), pipeline);
|
||||
pipeline.hmset("player:" + event.getConnection().getUniqueId().toString(), playerData);
|
||||
RedisUtil.createPlayer(event.getConnection(), pipeline);
|
||||
// We're not publishing, the API says we only publish at PostLoginEvent time.
|
||||
pipeline.sync();
|
||||
|
||||
|
@ -29,12 +29,26 @@ package com.imaginarycode.minecraft.redisbungee;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@VisibleForTesting
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class RedisUtil {
|
||||
protected static void createPlayer(PendingConnection connection, Pipeline pipeline) {
|
||||
Map<String, String> playerData = new HashMap<>(4);
|
||||
playerData.put("online", "0");
|
||||
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
|
||||
playerData.put("proxy", RedisBungee.getConfiguration().getServerId());
|
||||
|
||||
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", connection.getUniqueId().toString());
|
||||
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
||||
}
|
||||
|
||||
// Compatibility restraints prevent me from using using HDEL with multiple keys.
|
||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
||||
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
||||
|
Loading…
Reference in New Issue
Block a user