2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-22 20:28:00 +00:00

last bug was caused by confusion due Proxy Called server in some cases Which resulted in new API methods and some refactor

This commit is contained in:
mohammed jasem alaajel 2022-07-17 15:38:00 +04:00
parent 482dfc5141
commit aff185a85b
14 changed files with 179 additions and 150 deletions

View File

@ -21,7 +21,6 @@ import java.util.*;
*
* @author tuxed
* @since 0.2.3 | updated 0.7.0
*
*/
@SuppressWarnings("unused")
public class RedisBungeeAPI {
@ -34,7 +33,7 @@ public class RedisBungeeAPI {
redisBungeeApi = this;
this.reservedChannels = ImmutableList.of(
"redisbungee-allservers",
"redisbungee-" + plugin.getConfiguration().getServerId(),
"redisbungee-" + plugin.getConfiguration().getProxyId(),
"redisbungee-data"
);
new RedisBungee(this);
@ -175,8 +174,8 @@ public class RedisBungeeAPI {
*
* @param proxyId a proxy ID
* @param command the command to send and execute
* @see #getServerId()
* @see #getAllServers()
* @see #getProxyId()
* @see #getAllProxies()
* @since 0.2.5
*/
public final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
@ -196,14 +195,38 @@ public class RedisBungeeAPI {
}
/**
* Get the current BungeeCord server ID for this server.
* Get the current BungeeCord / Velocity proxy ID for this server.
*
* @return the current server ID
* @see #getAllProxies()
* @since 0.8.0
*/
public final String getProxyId() {
return plugin.getConfiguration().getProxyId();
}
/**
* Get the current BungeeCord / Velocity proxy ID for this server.
*
* @return the current server ID
* @see #getAllServers()
* @since 0.2.5
* @deprecated to avoid confusion between A server and A proxy see #getProxyId()
*/
@Deprecated
public final String getServerId() {
return plugin.getConfiguration().getServerId();
return getProxyId();
}
/**
* Get all the linked proxies in this network.
*
* @return the list of all proxies
* @see #getProxyId()
* @since 0.8.0
*/
public final List<String> getAllProxies() {
return plugin.getProxiesIds();
}
/**
@ -212,9 +235,11 @@ public class RedisBungeeAPI {
* @return the list of all proxies
* @see #getServerId()
* @since 0.2.5
* @deprecated to avoid confusion between A server and A proxy see see {@link #getAllProxies()}
*/
@Deprecated
public final List<String> getAllServers() {
return plugin.getServerIds();
return getAllProxies();
}
/**
@ -238,7 +263,7 @@ public class RedisBungeeAPI {
Preconditions.checkArgument(!reservedChannels.contains(channel), "attempting to unregister internal channel");
}
plugin.getPubSubListener().removeChannel(channels);
plugin.getPubSubListener().removeChannel(channels);
}
/**
@ -310,6 +335,7 @@ public class RedisBungeeAPI {
/**
* This gives you instance of Jedis
*
* @return {@link Jedis}
* @since 0.7.0
*/
@ -320,10 +346,12 @@ public class RedisBungeeAPI {
throw new RuntimeException("RedisBungee is on Cluster MODE!");
}
}
/**
* This gets Redis Bungee {@link JedisPool}
*
* @return {@link JedisPool}
* @since 0.6.5
* @since 0.6.5
*/
public JedisPool getJedisPool() {
if (getMode() == RedisBungeeMode.SINGLE) {
@ -345,6 +373,7 @@ public class RedisBungeeAPI {
/**
* This gives you instance of Jedis Cluster
*
* @return {@link redis.clients.jedis.JedisCluster}
* @since 0.8.0
*/
@ -358,6 +387,7 @@ public class RedisBungeeAPI {
/**
* shows what mode is RedisBungee is on
*
* @return {@link RedisBungeeMode}
* @since 0.8.0
*/
@ -368,6 +398,7 @@ public class RedisBungeeAPI {
/**
* Api instance
*
* @return the API instance.
* @since 0.6.5
*/

View File

@ -79,7 +79,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
P player = plugin.getPlayer(uuid);
if (player != null)
return plugin.getConfiguration().getServerId();
return plugin.getConfiguration().getProxyId();
try {
return proxyCache.get(uuid, new RedisTask<String>(plugin.getApi()) {
@ -183,7 +183,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
String source = jsonObject.get("source").getAsString();
if (source.equals(plugin.getConfiguration().getServerId()))
if (source.equals(plugin.getConfiguration().getProxyId()))
return;
DataManagerMessage.Action action = DataManagerMessage.Action.valueOf(jsonObject.get("action").getAsString());

View File

@ -27,7 +27,7 @@ public class PubSubListener implements Runnable {
public Void jedisTask(Jedis jedis) {
try {
jpsh = new JedisPubSubHandler(plugin);
addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId());
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
addedChannels.add("redisbungee-allservers");
addedChannels.add("redisbungee-data");
jedis.subscribe(jpsh, addedChannels.toArray(new String[0]));
@ -51,7 +51,7 @@ public class PubSubListener implements Runnable {
public Void clusterJedisTask(JedisCluster jedisCluster) {
try {
jpsh = new JedisPubSubHandler(plugin);
addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId());
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
addedChannels.add("redisbungee-allservers");
addedChannels.add("redisbungee-data");
jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0]));

View File

@ -7,13 +7,13 @@ import java.net.InetAddress;
import java.util.List;
public class RedisBungeeConfiguration {
private final String serverId;
private final String proxyId;
private final List<InetAddress> exemptAddresses;
private final boolean overrideBungeeCommands;
private static RedisBungeeConfiguration config;
public RedisBungeeConfiguration(String serverId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
this.serverId = serverId;
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
this.proxyId = proxyId;
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
for (String s : exemptAddresses) {
@ -24,8 +24,8 @@ public class RedisBungeeConfiguration {
this.overrideBungeeCommands = overrideBungeeCommands;
}
public String getServerId() {
return serverId;
public String getProxyId() {
return proxyId;
}
public List<InetAddress> getExemptAddresses() {

View File

@ -52,9 +52,9 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
void sendProxyCommand(String serverId, String command);
List<String> getServerIds();
List<String> getProxiesIds();
List<String> getCurrentServerIds(boolean nag, boolean lagged);
List<String> getCurrentProxiesIds(boolean nag, boolean lagged);
PubSubListener getPubSubListener();

View File

@ -15,31 +15,31 @@ public class RedisUtil {
private static final Gson gson = new Gson();
public static void cleanUpPlayer(String player, Jedis rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player);
rsc.hdel("player:" + player, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}
public static void cleanUpPlayer(String player, Pipeline rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player);
rsc.hdel("player:" + player, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}
public static void cleanUpPlayer(String player, JedisCluster rsc) {
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player);
rsc.srem("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player);
rsc.hdel("player:" + player, "server", "ip", "proxy");
long timestamp = System.currentTimeMillis();
rsc.hset("player:" + player, "online", String.valueOf(timestamp));
rsc.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
UUID.fromString(player), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.LEAVE,
new AbstractDataManager.LogoutPayload(timestamp))));
}

View File

@ -24,14 +24,14 @@ public class PlayerUtils {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getServerId());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getProxyId());
pipeline.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", connection.getUniqueId().toString());
pipeline.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", connection.getUniqueId().toString());
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
if (fireEvent) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
}
}
@ -46,14 +46,14 @@ public class PlayerUtils {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getServerId());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getProxyId());
jedisCluster.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", connection.getUniqueId().toString());
jedisCluster.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", connection.getUniqueId().toString());
jedisCluster.hmset("player:" + connection.getUniqueId().toString(), playerData);
if (fireEvent) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
connection.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
}
}

View File

@ -59,7 +59,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
}
}
for (String s : plugin.getServerIds()) {
for (String s : plugin.getProxiesIds()) {
if (jedis.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
event.setCancelled(true);
// TODO: Make it accept a BaseComponent[] like everything else.
@ -93,7 +93,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
}
}
for (String s : plugin.getServerIds()) {
for (String s : plugin.getProxiesIds()) {
if (jedisCluster.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
event.setCancelled(true);
// TODO: Make it accept a BaseComponent[] like everything else.
@ -125,7 +125,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
// the end of moved code.
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
return null;
}
@ -142,7 +142,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
// the end of moved code.
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
return null;
}
@ -182,7 +182,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
public Void jedisTask(Jedis jedis) {
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
return null;
}
@ -191,7 +191,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
public Void clusterJedisTask(JedisCluster jedisCluster) {
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
return null;
}
@ -299,7 +299,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
break;
case "Proxy":
out.writeUTF("Proxy");
out.writeUTF(plugin.getConfiguration().getServerId());
out.writeUTF(plugin.getConfiguration().getProxyId());
break;
case "PlayerProxy":
String username = in.readUTF();
@ -319,7 +319,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
@Override
@EventHandler
public void onPubSubMessage(PubSubMessageEvent event) {
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getApi().getServerId())) {
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getApi().getProxyId())) {
String message = event.getMessage();
if (message.startsWith("/"))
message = message.substring(1);

View File

@ -58,7 +58,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
private RedisBungeeConfiguration configuration;
private BungeeDataManager dataManager;
private OkHttpClient httpClient;
private volatile List<String> serverIds;
private volatile List<String> proxiesIds;
private final AtomicInteger nagAboutServers = new AtomicInteger();
private final AtomicInteger globalPlayerCount = new AtomicInteger();
private Future<?> integrityCheck;
@ -142,7 +142,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
try {
List<String> keys = new ArrayList<>();
for (String i : getServerIds()) {
for (String i : getProxiesIds()) {
keys.add("proxy:" + i + ":usersOnline");
}
if (!keys.isEmpty()) {
@ -169,7 +169,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
try {
List<String> keys = new ArrayList<>();
for (String i : getServerIds()) {
for (String i : getProxiesIds()) {
keys.add("proxy:" + i + ":usersOnline");
}
if (!keys.isEmpty()) {
@ -210,8 +210,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override
public Multimap<String, UUID> jedisTask(Jedis jedis) {
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
for (String serverId : getServerIds()) {
Set<String> players = jedis.smembers("proxy:" + serverId + ":usersOnline");
for (String proxyId : getProxiesIds()) {
Set<String> players = jedis.smembers("proxy:" + proxyId + ":usersOnline");
for (String player : players) {
builder.put(jedis.hget("player:" + player, "server"), UUID.fromString(player));
@ -223,8 +223,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override
public Multimap<String, UUID> clusterJedisTask(JedisCluster jedisCluster) {
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
for (String serverId : getServerIds()) {
Set<String> players = jedisCluster.smembers("proxy:" + serverId + ":usersOnline");
for (String proxyId : getProxiesIds()) {
Set<String> players = jedisCluster.smembers("proxy:" + proxyId + ":usersOnline");
for (String player : players) {
builder.put(jedisCluster.hget("player:" + player, "server"), UUID.fromString(player));
}
@ -239,7 +239,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override
public Set<UUID> getPlayersOnProxy(String proxyId) {
checkArgument(getServerIds().contains(proxyId), proxyId + " is not a valid proxy ID");
checkArgument(getProxiesIds().contains(proxyId), proxyId + " is not a valid proxy ID");
return new RedisTask<Set<UUID>>(api) {
@Override
public Set<UUID> jedisTask(Jedis jedis) {
@ -264,18 +264,18 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
}
@Override
public void sendProxyCommand(String serverId, String command) {
checkArgument(getServerIds().contains(serverId) || serverId.equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + serverId, command);
public void sendProxyCommand(String proxyId, String command) {
checkArgument(getProxiesIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + proxyId, command);
}
@Override
public List<String> getServerIds() {
return serverIds;
public List<String> getProxiesIds() {
return proxiesIds;
}
@Override
public List<String> getCurrentServerIds(boolean nag, boolean lagged) {
public List<String> getCurrentProxiesIds(boolean nag, boolean lagged) {
return new RedisTask<List<String>>(api) {
@Override
public List<String> jedisTask(Jedis jedis) {
@ -305,7 +305,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
return servers.build();
} catch (JedisConnectionException e) {
getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
return Collections.singletonList(configuration.getServerId());
return Collections.singletonList(configuration.getProxyId());
}
}
@ -337,7 +337,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
return servers.build();
} catch (JedisConnectionException e) {
getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
return Collections.singletonList(configuration.getServerId());
return Collections.singletonList(configuration.getProxyId());
}
}
}.execute();
@ -449,8 +449,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override
public void sendProxyCommand(String cmd) {
checkArgument(getServerIds().contains(this.configuration.getServerId()) || this.configuration.getServerId().equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + this.configuration.getServerId(), cmd);
checkArgument(getProxiesIds().contains(this.configuration.getProxyId()) || this.configuration.getProxyId().equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + this.configuration.getProxyId(), cmd);
}
@Override
@ -546,9 +546,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
if (crashFile.exists() && crashFile.delete()) {
getLogger().info("crash file was deleted");
} else if (jedis.hexists("heartbeats", configuration.getServerId())) {
} else if (jedis.hexists("heartbeats", configuration.getProxyId())) {
try {
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getServerId()));
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getProxyId()));
long redisTime = getRedisTime(jedis.time());
if (redisTime < value + 20) {
getLogger().severe("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running.");
@ -559,7 +559,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
} catch (NumberFormatException ignored) {
}
} else {
jedis.hset("heartbeats", configuration.getServerId(), jedis.time().get(0));
jedis.hset("heartbeats", configuration.getProxyId(), jedis.time().get(0));
}
return null;
@ -570,9 +570,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
if (crashFile.exists() && crashFile.delete()) {
getLogger().info("crash file was deleted");
} else if (jedisCluster.hexists("heartbeats", configuration.getServerId())) {
} else if (jedisCluster.hexists("heartbeats", configuration.getProxyId())) {
try {
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getServerId()));
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getProxyId()));
long redisTime = getRedisClusterTime();
if (redisTime < value + 20) {
@ -584,13 +584,13 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
} catch (NumberFormatException ignored) {
}
} else {
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(getRedisClusterTime()));
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(getRedisClusterTime()));
}
return null;
}
}.execute();
serverIds = getCurrentServerIds(true, false);
proxiesIds = getCurrentProxiesIds(true, false);
uuidTranslator = new UUIDTranslator(this);
@ -599,14 +599,14 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
public Void jedisTask(Jedis jedis) {
try {
long redisTime = getRedisTime(jedis.time());
jedis.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
jedis.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
return null;
}
try {
serverIds = getCurrentServerIds(true, false);
proxiesIds = getCurrentProxiesIds(true, false);
globalPlayerCount.set(getCurrentCount());
} catch (Throwable e) {
getLogger().log(Level.SEVERE, "Unable to update data - did your Redis server go away?", e);
@ -618,14 +618,14 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
public Void clusterJedisTask(JedisCluster jedisCluster) {
try {
long redisTime = getRedisClusterTime();
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
return null;
}
try {
serverIds = getCurrentServerIds(true, false);
proxiesIds = getCurrentProxiesIds(true, false);
globalPlayerCount.set(getCurrentCount());
} catch (Throwable e) {
getLogger().log(Level.SEVERE, "Unable to update data - did your Redis server go away?", e);
@ -647,8 +647,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
public Void jedisTask(Jedis jedis) {
try {
Set<String> players = getLocalPlayersAsUuidStrings();
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
List<String> lagged = getCurrentServerIds(false, true);
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
List<String> lagged = getCurrentProxiesIds(false, true);
// Clean up lagged players.
for (String s : lagged) {
@ -669,8 +669,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
for (String member : absentLocally) {
boolean found = false;
for (String proxyId : getServerIds()) {
if (proxyId.equals(configuration.getServerId())) continue;
for (String proxyId : getProxiesIds()) {
if (proxyId.equals(configuration.getProxyId())) continue;
if (jedis.sismember("proxy:" + proxyId + ":usersOnline", member)) {
// Just clean up the set.
found = true;
@ -681,7 +681,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
RedisUtil.cleanUpPlayer(member, jedis);
getLogger().warning("Player found in set that was not found locally and globally: " + member);
} else {
jedis.srem("proxy:" + configuration.getServerId() + ":usersOnline", member);
jedis.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
getLogger().warning("Player found in set that was not found locally, but is on another proxy: " + member);
}
}
@ -710,8 +710,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
public Void clusterJedisTask(JedisCluster jedisCluster) {
try {
Set<String> players = getLocalPlayersAsUuidStrings();
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
List<String> lagged = getCurrentServerIds(false, true);
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
List<String> lagged = getCurrentProxiesIds(false, true);
// Clean up lagged players.
for (String s : lagged) {
@ -732,8 +732,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
for (String member : absentLocally) {
boolean found = false;
for (String proxyId : getServerIds()) {
if (proxyId.equals(configuration.getServerId())) continue;
for (String proxyId : getProxiesIds()) {
if (proxyId.equals(configuration.getProxyId())) continue;
if (jedisCluster.sismember("proxy:" + proxyId + ":usersOnline", member)) {
// Just clean up the set.
found = true;
@ -744,7 +744,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
RedisUtil.cleanUpPlayer(member, jedisCluster);
getLogger().warning("Player found in set that was not found locally and globally: " + member);
} else {
jedisCluster.srem("proxy:" + configuration.getServerId() + ":usersOnline", member);
jedisCluster.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
getLogger().warning("Player found in set that was not found locally, but is on another proxy: " + member);
}
}
@ -806,9 +806,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
new RedisTask<Void>(api) {
@Override
public Void jedisTask(Jedis jedis) {
jedis.hdel("heartbeats", configuration.getServerId());
if (jedis.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
Set<String> players = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
jedis.hdel("heartbeats", configuration.getProxyId());
if (jedis.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
RedisUtil.cleanUpPlayer(member, jedis);
}
@ -817,9 +817,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
jedisCluster.hdel("heartbeats", configuration.getServerId());
if (jedisCluster.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
jedisCluster.hdel("heartbeats", configuration.getProxyId());
if (jedisCluster.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
RedisUtil.cleanUpPlayer(member, jedisCluster);
}

View File

@ -266,7 +266,7 @@ public class RedisBungeeCommands {
@Override
public void execute(CommandSender sender, String[] args) {
TextComponent textComponent = new TextComponent();
textComponent.setText("You are on " + plugin.getApi().getServerId() + ".");
textComponent.setText("You are on " + plugin.getApi().getProxyId() + ".");
textComponent.setColor(ChatColor.YELLOW);
sender.sendMessage(textComponent);
}
@ -282,7 +282,7 @@ public class RedisBungeeCommands {
@Override
public void execute(CommandSender sender, String[] strings) {
TextComponent textComponent = new TextComponent();
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getApi().getAllServers()));
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getApi().getAllProxies()));
textComponent.setColor(ChatColor.YELLOW);
sender.sendMessage(textComponent);
}
@ -301,8 +301,8 @@ public class RedisBungeeCommands {
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
@Override
public void run() {
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getServerId();
if (!plugin.getServerIds().contains(proxy)) {
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getProxyId();
if (!plugin.getProxiesIds().contains(proxy)) {
sender.sendMessage(new ComponentBuilder(proxy + " is not a valid proxy. See /serverids for valid proxies.").color(ChatColor.RED).create());
return;
}

View File

@ -21,14 +21,14 @@ public class PlayerUtils {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", player.getRemoteAddress().getHostName());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getServerId());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getProxyId());
pipeline.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player.getUniqueId().toString());
pipeline.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player.getUniqueId().toString());
pipeline.hmset("player:" + player.getUniqueId().toString(), playerData);
if (fireEvent) {
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
}
}
@ -40,14 +40,14 @@ public class PlayerUtils {
Map<String, String> playerData = new HashMap<>(4);
playerData.put("online", "0");
playerData.put("ip", player.getRemoteAddress().getHostName());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getServerId());
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getProxyId());
jedisCluster.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getServerId() + ":usersOnline", player.getUniqueId().toString());
jedisCluster.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", player.getUniqueId().toString());
jedisCluster.hmset("player:" + player.getUniqueId().toString(), playerData);
if (fireEvent) {
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
player.getUniqueId(), RedisBungeeAPI.getRedisBungeeApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
}
}

View File

@ -64,7 +64,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
}
}
for (String s : plugin.getServerIds()) {
for (String s : plugin.getProxiesIds()) {
if (jedis.sismember("proxy:" + s + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ALREADY_LOGGED_IN)));
return null;
@ -94,7 +94,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
}
}
for (String s : plugin.getServerIds()) {
for (String s : plugin.getProxiesIds()) {
if (jedisCluster.sismember("proxy:" + s + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ALREADY_LOGGED_IN)));
return null;
@ -122,7 +122,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
// the end of moved code.
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
return null;
}
@ -134,7 +134,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
// the end of moved code.
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.JOIN,
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
return null;
}
@ -174,7 +174,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
public Void jedisTask(Jedis jedis) {
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
return null;
}
@ -183,7 +183,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
public Void clusterJedisTask(JedisCluster jedisCluster) {
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
event.getPlayer().getUniqueId(), plugin.getApi().getServerId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
event.getPlayer().getUniqueId(), plugin.getApi().getProxyId(), AbstractDataManager.DataManagerMessage.Action.SERVER_CHANGE,
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
return null;
}
@ -290,7 +290,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
break;
case "Proxy":
out.writeUTF("Proxy");
out.writeUTF(plugin.getConfiguration().getServerId());
out.writeUTF(plugin.getConfiguration().getProxyId());
break;
case "PlayerProxy":
String username = in.readUTF();
@ -311,7 +311,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
@Override
@Subscribe
public void onPubSubMessage(PubSubMessageEvent event) {
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getApi().getServerId())) {
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + plugin.getApi().getProxyId())) {
String message = event.getMessage();
if (message.startsWith("/"))
message = message.substring(1);

View File

@ -55,7 +55,6 @@ import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
@Plugin(id = "redisbungee", name = "RedisBungee", version = PomData.VERSION, url = "https://github.com/ProxioDev/RedisBungee", authors = "ProxioDev")
public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@ -70,7 +69,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
private RedisBungeeConfiguration configuration;
private final VelocityDataManager dataManager;
private final OkHttpClient httpClient;
private volatile List<String> serverIds;
private volatile List<String> proxiesIds;
private final AtomicInteger nagAboutServers = new AtomicInteger();
private final AtomicInteger globalPlayerCount = new AtomicInteger();
private ScheduledTask integrityCheck;
@ -165,9 +164,9 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
throw new RuntimeException(e);
}
getLogger().info("crash file was deleted");
} else if (jedis.hexists("heartbeats", configuration.getServerId())) {
} else if (jedis.hexists("heartbeats", configuration.getProxyId())) {
try {
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getServerId()));
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getProxyId()));
long redisTime = getRedisTime(jedis.time());
if (redisTime < value + 20) {
getLogger().error("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running.");
@ -178,7 +177,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
} catch (NumberFormatException ignored) {
}
} else {
jedis.hset("heartbeats", configuration.getServerId(), jedis.time().get(0));
jedis.hset("heartbeats", configuration.getProxyId(), jedis.time().get(0));
}
return null;
@ -194,9 +193,9 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
throw new RuntimeException(e);
}
getLogger().info("crash file was deleted");
} else if (jedisCluster.hexists("heartbeats", configuration.getServerId())) {
} else if (jedisCluster.hexists("heartbeats", configuration.getProxyId())) {
try {
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getServerId()));
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getProxyId()));
long redisTime = getRedisClusterTime();
if (redisTime < value + 20) {
@ -208,7 +207,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
} catch (NumberFormatException ignored) {
}
} else {
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(getRedisClusterTime()));
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(getRedisClusterTime()));
}
return null;
}
@ -300,7 +299,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
try {
List<String> keys = new ArrayList<>();
for (String i : getServerIds()) {
for (String i : getProxiesIds()) {
keys.add("proxy:" + i + ":usersOnline");
}
if (!keys.isEmpty()) {
@ -327,7 +326,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
try {
List<String> keys = new ArrayList<>();
for (String i : getServerIds()) {
for (String i : getProxiesIds()) {
keys.add("proxy:" + i + ":usersOnline");
}
if (!keys.isEmpty()) {
@ -374,7 +373,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public Multimap<String, UUID> jedisTask(Jedis jedis) {
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
for (String serverId : getServerIds()) {
for (String serverId : getProxiesIds()) {
Set<String> players = jedis.smembers("proxy:" + serverId + ":usersOnline");
for (String player : players) {
builder.put(jedis.hget("player:" + player, "server"), UUID.fromString(player));
@ -386,7 +385,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public Multimap<String, UUID> clusterJedisTask(JedisCluster jedisCluster) {
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
for (String serverId : getServerIds()) {
for (String serverId : getProxiesIds()) {
Set<String> players = jedisCluster.smembers("proxy:" + serverId + ":usersOnline");
for (String player : players) {
builder.put(jedisCluster.hget("player:" + player, "server"), UUID.fromString(player));
@ -402,7 +401,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public Set<UUID> getPlayersOnProxy(String proxyId) {
checkArgument(getServerIds().contains(proxyId), proxyId + " is not a valid proxy ID");
checkArgument(getProxiesIds().contains(proxyId), proxyId + " is not a valid proxy ID");
return new RedisTask<Set<UUID>>(api) {
@Override
public Set<UUID> jedisTask(Jedis jedis) {
@ -428,18 +427,18 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public void sendProxyCommand(String serverId, String command) {
checkArgument(getServerIds().contains(serverId) || serverId.equals("allservers"), "proxyId is invalid");
checkArgument(getProxiesIds().contains(serverId) || serverId.equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + serverId, command);
}
@Override
public List<String> getServerIds() {
return serverIds;
public List<String> getProxiesIds() {
return proxiesIds;
}
@Override
public List<String> getCurrentServerIds(boolean nag, boolean lagged) {
public List<String> getCurrentProxiesIds(boolean nag, boolean lagged) {
return new RedisTask<List<String>>(api) {
@Override
public List<String> jedisTask(Jedis jedis) {
@ -469,7 +468,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
return servers.build();
} catch (JedisConnectionException e) {
getLogger().error("Unable to fetch server IDs", e);
return Collections.singletonList(configuration.getServerId());
return Collections.singletonList(configuration.getProxyId());
}
}
@ -501,7 +500,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
return servers.build();
} catch (JedisConnectionException e) {
getLogger().error("Unable to fetch server IDs", e);
return Collections.singletonList(configuration.getServerId());
return Collections.singletonList(configuration.getProxyId());
}
}
}.execute();
@ -613,8 +612,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public void sendProxyCommand(String cmd) {
checkArgument(getServerIds().contains(this.configuration.getServerId()) || this.configuration.getServerId().equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + this.configuration.getServerId(), cmd);
checkArgument(getProxiesIds().contains(this.configuration.getProxyId()) || this.configuration.getProxyId().equals("allservers"), "proxyId is invalid");
sendChannelMessage("redisbungee-" + this.configuration.getProxyId(), cmd);
}
@Override
@ -625,21 +624,21 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public void initialize() {
serverIds = getCurrentServerIds(true, false);
proxiesIds = getCurrentProxiesIds(true, false);
// start heartbeat task
RedisTask<Void> heartBeatRedisTask = new RedisTask<Void>(api) {
@Override
public Void jedisTask(Jedis jedis) {
try {
long redisTime = getRedisTime(jedis.time());
jedis.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
jedis.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().error("Unable to update heartbeat - did your Redis server go away?", e);
return null;
}
try {
serverIds = getCurrentServerIds(true, false);
proxiesIds = getCurrentProxiesIds(true, false);
globalPlayerCount.set(getCurrentCount());
} catch (Throwable e) {
getLogger().error("Unable to update data - did your Redis server go away?", e);
@ -651,14 +650,14 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
public Void clusterJedisTask(JedisCluster jedisCluster) {
try {
long redisTime = getRedisClusterTime();
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().error("Unable to update heartbeat - did your Redis server go away?", e);
return null;
}
try {
serverIds = getCurrentServerIds(true, false);
proxiesIds = getCurrentProxiesIds(true, false);
globalPlayerCount.set(getCurrentCount());
} catch (Throwable e) {
getLogger().error("Unable to update data - did your Redis server go away?", e);
@ -676,8 +675,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
public Void jedisTask(Jedis jedis) {
try {
Set<String> players = getLocalPlayersAsUuidStrings();
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
List<String> lagged = getCurrentServerIds(false, true);
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
List<String> lagged = getCurrentProxiesIds(false, true);
// Clean up lagged players.
for (String s : lagged) {
@ -698,8 +697,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
for (String member : absentLocally) {
boolean found = false;
for (String proxyId : getServerIds()) {
if (proxyId.equals(configuration.getServerId())) continue;
for (String proxyId : getProxiesIds()) {
if (proxyId.equals(configuration.getProxyId())) continue;
if (jedis.sismember("proxy:" + proxyId + ":usersOnline", member)) {
// Just clean up the set.
found = true;
@ -710,7 +709,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
RedisUtil.cleanUpPlayer(member, jedis);
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
} else {
jedis.srem("proxy:" + configuration.getServerId() + ":usersOnline", member);
jedis.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
getLogger().warn("Player found in set that was not found locally, but is on another proxy: {}", member);
}
}
@ -739,8 +738,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
public Void clusterJedisTask(JedisCluster jedisCluster) {
try {
Set<String> players = getLocalPlayersAsUuidStrings();
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
List<String> lagged = getCurrentServerIds(false, true);
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
List<String> lagged = getCurrentProxiesIds(false, true);
// Clean up lagged players.
for (String s : lagged) {
@ -761,8 +760,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
for (String member : absentLocally) {
boolean found = false;
for (String proxyId : getServerIds()) {
if (proxyId.equals(configuration.getServerId())) continue;
for (String proxyId : getProxiesIds()) {
if (proxyId.equals(configuration.getProxyId())) continue;
if (jedisCluster.sismember("proxy:" + proxyId + ":usersOnline", member)) {
// Just clean up the set.
found = true;
@ -773,7 +772,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
RedisUtil.cleanUpPlayer(member, jedisCluster);
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
} else {
jedisCluster.srem("proxy:" + configuration.getServerId() + ":usersOnline", member);
jedisCluster.srem("proxy:" + configuration.getProxyId() + ":usersOnline", member);
getLogger().warn("Player found in set that was not found locally, but is on another proxy: {}", member);
}
}
@ -830,9 +829,9 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
new RedisTask<Void>(api) {
@Override
public Void jedisTask(Jedis jedis) {
jedis.hdel("heartbeats", configuration.getServerId());
if (jedis.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
Set<String> players = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
jedis.hdel("heartbeats", configuration.getProxyId());
if (jedis.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
RedisUtil.cleanUpPlayer(member, jedis);
}
@ -841,9 +840,9 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
@Override
public Void clusterJedisTask(JedisCluster jedisCluster) {
jedisCluster.hdel("heartbeats", configuration.getServerId());
if (jedisCluster.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
jedisCluster.hdel("heartbeats", configuration.getProxyId());
if (jedisCluster.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
for (String member : players)
RedisUtil.cleanUpPlayer(member, jedisCluster);
}

View File

@ -2,7 +2,6 @@ package com.imaginarycode.minecraft.redisbungee.commands;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
@ -271,7 +270,7 @@ public class RedisBungeeCommands {
@Override
public void execute(Invocation invocation) {
invocation.source().sendMessage(Component.text("You are on " + plugin.getApi().getServerId() + ".", NamedTextColor.YELLOW));
invocation.source().sendMessage(Component.text("You are on " + plugin.getApi().getProxyId() + ".", NamedTextColor.YELLOW));
}
@Override
@ -289,7 +288,7 @@ public class RedisBungeeCommands {
@Override
public void execute(Invocation invocation) {
invocation.source().sendMessage(
Component.text("All server IDs: " + Joiner.on(", ").join(plugin.getApi().getAllServers()), NamedTextColor.YELLOW));
Component.text("All server IDs: " + Joiner.on(", ").join(plugin.getApi().getAllProxies()), NamedTextColor.YELLOW));
}
@Override
@ -310,8 +309,8 @@ public class RedisBungeeCommands {
CommandSource sender= invocation.source();
String[] args = invocation.arguments();
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getServerId();
if (!plugin.getServerIds().contains(proxy)) {
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getProxyId();
if (!plugin.getProxiesIds().contains(proxy)) {
sender.sendMessage(Component.text(proxy + " is not a valid proxy. See /serverids for valid proxies.", NamedTextColor.RED));
return;
}