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:
parent
482dfc5141
commit
aff185a85b
@ -21,7 +21,6 @@ import java.util.*;
|
|||||||
*
|
*
|
||||||
* @author tuxed
|
* @author tuxed
|
||||||
* @since 0.2.3 | updated 0.7.0
|
* @since 0.2.3 | updated 0.7.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class RedisBungeeAPI {
|
public class RedisBungeeAPI {
|
||||||
@ -34,7 +33,7 @@ public class RedisBungeeAPI {
|
|||||||
redisBungeeApi = this;
|
redisBungeeApi = this;
|
||||||
this.reservedChannels = ImmutableList.of(
|
this.reservedChannels = ImmutableList.of(
|
||||||
"redisbungee-allservers",
|
"redisbungee-allservers",
|
||||||
"redisbungee-" + plugin.getConfiguration().getServerId(),
|
"redisbungee-" + plugin.getConfiguration().getProxyId(),
|
||||||
"redisbungee-data"
|
"redisbungee-data"
|
||||||
);
|
);
|
||||||
new RedisBungee(this);
|
new RedisBungee(this);
|
||||||
@ -175,8 +174,8 @@ public class RedisBungeeAPI {
|
|||||||
*
|
*
|
||||||
* @param proxyId a proxy ID
|
* @param proxyId a proxy ID
|
||||||
* @param command the command to send and execute
|
* @param command the command to send and execute
|
||||||
* @see #getServerId()
|
* @see #getProxyId()
|
||||||
* @see #getAllServers()
|
* @see #getAllProxies()
|
||||||
* @since 0.2.5
|
* @since 0.2.5
|
||||||
*/
|
*/
|
||||||
public final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
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
|
* @return the current server ID
|
||||||
* @see #getAllServers()
|
* @see #getAllServers()
|
||||||
* @since 0.2.5
|
* @since 0.2.5
|
||||||
|
* @deprecated to avoid confusion between A server and A proxy see #getProxyId()
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final String getServerId() {
|
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
|
* @return the list of all proxies
|
||||||
* @see #getServerId()
|
* @see #getServerId()
|
||||||
* @since 0.2.5
|
* @since 0.2.5
|
||||||
|
* @deprecated to avoid confusion between A server and A proxy see see {@link #getAllProxies()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final List<String> getAllServers() {
|
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");
|
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
|
* This gives you instance of Jedis
|
||||||
|
*
|
||||||
* @return {@link Jedis}
|
* @return {@link Jedis}
|
||||||
* @since 0.7.0
|
* @since 0.7.0
|
||||||
*/
|
*/
|
||||||
@ -320,10 +346,12 @@ public class RedisBungeeAPI {
|
|||||||
throw new RuntimeException("RedisBungee is on Cluster MODE!");
|
throw new RuntimeException("RedisBungee is on Cluster MODE!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This gets Redis Bungee {@link JedisPool}
|
* This gets Redis Bungee {@link JedisPool}
|
||||||
|
*
|
||||||
* @return {@link JedisPool}
|
* @return {@link JedisPool}
|
||||||
* @since 0.6.5
|
* @since 0.6.5
|
||||||
*/
|
*/
|
||||||
public JedisPool getJedisPool() {
|
public JedisPool getJedisPool() {
|
||||||
if (getMode() == RedisBungeeMode.SINGLE) {
|
if (getMode() == RedisBungeeMode.SINGLE) {
|
||||||
@ -345,6 +373,7 @@ public class RedisBungeeAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This gives you instance of Jedis Cluster
|
* This gives you instance of Jedis Cluster
|
||||||
|
*
|
||||||
* @return {@link redis.clients.jedis.JedisCluster}
|
* @return {@link redis.clients.jedis.JedisCluster}
|
||||||
* @since 0.8.0
|
* @since 0.8.0
|
||||||
*/
|
*/
|
||||||
@ -358,6 +387,7 @@ public class RedisBungeeAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* shows what mode is RedisBungee is on
|
* shows what mode is RedisBungee is on
|
||||||
|
*
|
||||||
* @return {@link RedisBungeeMode}
|
* @return {@link RedisBungeeMode}
|
||||||
* @since 0.8.0
|
* @since 0.8.0
|
||||||
*/
|
*/
|
||||||
@ -368,6 +398,7 @@ public class RedisBungeeAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Api instance
|
* Api instance
|
||||||
|
*
|
||||||
* @return the API instance.
|
* @return the API instance.
|
||||||
* @since 0.6.5
|
* @since 0.6.5
|
||||||
*/
|
*/
|
||||||
|
@ -79,7 +79,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
|||||||
P player = plugin.getPlayer(uuid);
|
P player = plugin.getPlayer(uuid);
|
||||||
|
|
||||||
if (player != null)
|
if (player != null)
|
||||||
return plugin.getConfiguration().getServerId();
|
return plugin.getConfiguration().getProxyId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return proxyCache.get(uuid, new RedisTask<String>(plugin.getApi()) {
|
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();
|
String source = jsonObject.get("source").getAsString();
|
||||||
|
|
||||||
if (source.equals(plugin.getConfiguration().getServerId()))
|
if (source.equals(plugin.getConfiguration().getProxyId()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DataManagerMessage.Action action = DataManagerMessage.Action.valueOf(jsonObject.get("action").getAsString());
|
DataManagerMessage.Action action = DataManagerMessage.Action.valueOf(jsonObject.get("action").getAsString());
|
||||||
|
@ -27,7 +27,7 @@ public class PubSubListener implements Runnable {
|
|||||||
public Void jedisTask(Jedis jedis) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
try {
|
try {
|
||||||
jpsh = new JedisPubSubHandler(plugin);
|
jpsh = new JedisPubSubHandler(plugin);
|
||||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId());
|
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
|
||||||
addedChannels.add("redisbungee-allservers");
|
addedChannels.add("redisbungee-allservers");
|
||||||
addedChannels.add("redisbungee-data");
|
addedChannels.add("redisbungee-data");
|
||||||
jedis.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
jedis.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
||||||
@ -51,7 +51,7 @@ public class PubSubListener implements Runnable {
|
|||||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
try {
|
try {
|
||||||
jpsh = new JedisPubSubHandler(plugin);
|
jpsh = new JedisPubSubHandler(plugin);
|
||||||
addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId());
|
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
|
||||||
addedChannels.add("redisbungee-allservers");
|
addedChannels.add("redisbungee-allservers");
|
||||||
addedChannels.add("redisbungee-data");
|
addedChannels.add("redisbungee-data");
|
||||||
jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0]));
|
||||||
|
@ -7,13 +7,13 @@ import java.net.InetAddress;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RedisBungeeConfiguration {
|
public class RedisBungeeConfiguration {
|
||||||
private final String serverId;
|
private final String proxyId;
|
||||||
private final List<InetAddress> exemptAddresses;
|
private final List<InetAddress> exemptAddresses;
|
||||||
private final boolean overrideBungeeCommands;
|
private final boolean overrideBungeeCommands;
|
||||||
private static RedisBungeeConfiguration config;
|
private static RedisBungeeConfiguration config;
|
||||||
|
|
||||||
public RedisBungeeConfiguration(String serverId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
|
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
|
||||||
this.serverId = serverId;
|
this.proxyId = proxyId;
|
||||||
|
|
||||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||||
for (String s : exemptAddresses) {
|
for (String s : exemptAddresses) {
|
||||||
@ -24,8 +24,8 @@ public class RedisBungeeConfiguration {
|
|||||||
this.overrideBungeeCommands = overrideBungeeCommands;
|
this.overrideBungeeCommands = overrideBungeeCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerId() {
|
public String getProxyId() {
|
||||||
return serverId;
|
return proxyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<InetAddress> getExemptAddresses() {
|
public List<InetAddress> getExemptAddresses() {
|
||||||
|
@ -52,9 +52,9 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
|
|||||||
|
|
||||||
void sendProxyCommand(String serverId, String command);
|
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();
|
PubSubListener getPubSubListener();
|
||||||
|
|
||||||
|
@ -15,31 +15,31 @@ public class RedisUtil {
|
|||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
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");
|
rsc.hdel("player:" + player, "server", "ip", "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", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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))));
|
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
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");
|
rsc.hdel("player:" + player, "server", "ip", "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", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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))));
|
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||||
}
|
}
|
||||||
public static void cleanUpPlayer(String player, JedisCluster rsc) {
|
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");
|
rsc.hdel("player:" + player, "server", "ip", "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", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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))));
|
new AbstractDataManager.LogoutPayload(timestamp))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ public class PlayerUtils {
|
|||||||
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());
|
||||||
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);
|
pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
||||||
|
|
||||||
if (fireEvent) {
|
if (fireEvent) {
|
||||||
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,14 +46,14 @@ public class PlayerUtils {
|
|||||||
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());
|
||||||
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);
|
jedisCluster.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
||||||
|
|
||||||
if (fireEvent) {
|
if (fireEvent) {
|
||||||
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(connection.getAddress().getAddress()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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())) {
|
if (jedis.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
// TODO: Make it accept a BaseComponent[] like everything else.
|
// 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())) {
|
if (jedisCluster.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
// TODO: Make it accept a BaseComponent[] like everything else.
|
// TODO: Make it accept a BaseComponent[] like everything else.
|
||||||
@ -125,7 +125,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
|||||||
// the end of moved code.
|
// the end of moved code.
|
||||||
|
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
|||||||
// the end of moved code.
|
// the end of moved code.
|
||||||
|
|
||||||
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
|||||||
public Void jedisTask(Jedis jedis) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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))));
|
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
|||||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
||||||
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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))));
|
new AbstractDataManager.ServerChangePayload(event.getServer().getInfo().getName(), currentServer))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -299,7 +299,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
|||||||
break;
|
break;
|
||||||
case "Proxy":
|
case "Proxy":
|
||||||
out.writeUTF("Proxy");
|
out.writeUTF("Proxy");
|
||||||
out.writeUTF(plugin.getConfiguration().getServerId());
|
out.writeUTF(plugin.getConfiguration().getProxyId());
|
||||||
break;
|
break;
|
||||||
case "PlayerProxy":
|
case "PlayerProxy":
|
||||||
String username = in.readUTF();
|
String username = in.readUTF();
|
||||||
@ -319,7 +319,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
|||||||
@Override
|
@Override
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
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();
|
String message = event.getMessage();
|
||||||
if (message.startsWith("/"))
|
if (message.startsWith("/"))
|
||||||
message = message.substring(1);
|
message = message.substring(1);
|
||||||
|
@ -58,7 +58,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
private RedisBungeeConfiguration configuration;
|
private RedisBungeeConfiguration configuration;
|
||||||
private BungeeDataManager dataManager;
|
private BungeeDataManager dataManager;
|
||||||
private OkHttpClient httpClient;
|
private OkHttpClient httpClient;
|
||||||
private volatile List<String> serverIds;
|
private volatile List<String> proxiesIds;
|
||||||
private final AtomicInteger nagAboutServers = new AtomicInteger();
|
private final AtomicInteger nagAboutServers = new AtomicInteger();
|
||||||
private final AtomicInteger globalPlayerCount = new AtomicInteger();
|
private final AtomicInteger globalPlayerCount = new AtomicInteger();
|
||||||
private Future<?> integrityCheck;
|
private Future<?> integrityCheck;
|
||||||
@ -142,7 +142,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
||||||
try {
|
try {
|
||||||
List<String> keys = new ArrayList<>();
|
List<String> keys = new ArrayList<>();
|
||||||
for (String i : getServerIds()) {
|
for (String i : getProxiesIds()) {
|
||||||
keys.add("proxy:" + i + ":usersOnline");
|
keys.add("proxy:" + i + ":usersOnline");
|
||||||
}
|
}
|
||||||
if (!keys.isEmpty()) {
|
if (!keys.isEmpty()) {
|
||||||
@ -169,7 +169,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
||||||
try {
|
try {
|
||||||
List<String> keys = new ArrayList<>();
|
List<String> keys = new ArrayList<>();
|
||||||
for (String i : getServerIds()) {
|
for (String i : getProxiesIds()) {
|
||||||
keys.add("proxy:" + i + ":usersOnline");
|
keys.add("proxy:" + i + ":usersOnline");
|
||||||
}
|
}
|
||||||
if (!keys.isEmpty()) {
|
if (!keys.isEmpty()) {
|
||||||
@ -210,8 +210,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
@Override
|
@Override
|
||||||
public Multimap<String, UUID> jedisTask(Jedis jedis) {
|
public Multimap<String, UUID> jedisTask(Jedis jedis) {
|
||||||
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
||||||
for (String serverId : getServerIds()) {
|
for (String proxyId : getProxiesIds()) {
|
||||||
Set<String> players = jedis.smembers("proxy:" + serverId + ":usersOnline");
|
Set<String> players = jedis.smembers("proxy:" + proxyId + ":usersOnline");
|
||||||
for (String player : players) {
|
for (String player : players) {
|
||||||
|
|
||||||
builder.put(jedis.hget("player:" + player, "server"), UUID.fromString(player));
|
builder.put(jedis.hget("player:" + player, "server"), UUID.fromString(player));
|
||||||
@ -223,8 +223,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
@Override
|
@Override
|
||||||
public Multimap<String, UUID> clusterJedisTask(JedisCluster jedisCluster) {
|
public Multimap<String, UUID> clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
||||||
for (String serverId : getServerIds()) {
|
for (String proxyId : getProxiesIds()) {
|
||||||
Set<String> players = jedisCluster.smembers("proxy:" + serverId + ":usersOnline");
|
Set<String> players = jedisCluster.smembers("proxy:" + proxyId + ":usersOnline");
|
||||||
for (String player : players) {
|
for (String player : players) {
|
||||||
builder.put(jedisCluster.hget("player:" + player, "server"), UUID.fromString(player));
|
builder.put(jedisCluster.hget("player:" + player, "server"), UUID.fromString(player));
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> getPlayersOnProxy(String proxyId) {
|
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) {
|
return new RedisTask<Set<UUID>>(api) {
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> jedisTask(Jedis jedis) {
|
public Set<UUID> jedisTask(Jedis jedis) {
|
||||||
@ -264,18 +264,18 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendProxyCommand(String serverId, String command) {
|
public void sendProxyCommand(String proxyId, String command) {
|
||||||
checkArgument(getServerIds().contains(serverId) || serverId.equals("allservers"), "proxyId is invalid");
|
checkArgument(getProxiesIds().contains(proxyId) || proxyId.equals("allservers"), "proxyId is invalid");
|
||||||
sendChannelMessage("redisbungee-" + serverId, command);
|
sendChannelMessage("redisbungee-" + proxyId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getServerIds() {
|
public List<String> getProxiesIds() {
|
||||||
return serverIds;
|
return proxiesIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getCurrentServerIds(boolean nag, boolean lagged) {
|
public List<String> getCurrentProxiesIds(boolean nag, boolean lagged) {
|
||||||
return new RedisTask<List<String>>(api) {
|
return new RedisTask<List<String>>(api) {
|
||||||
@Override
|
@Override
|
||||||
public List<String> jedisTask(Jedis jedis) {
|
public List<String> jedisTask(Jedis jedis) {
|
||||||
@ -305,7 +305,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
return servers.build();
|
return servers.build();
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
getLogger().log(Level.SEVERE, "Unable to fetch server IDs", 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();
|
return servers.build();
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
|
getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
|
||||||
return Collections.singletonList(configuration.getServerId());
|
return Collections.singletonList(configuration.getProxyId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
@ -449,8 +449,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendProxyCommand(String cmd) {
|
public void sendProxyCommand(String cmd) {
|
||||||
checkArgument(getServerIds().contains(this.configuration.getServerId()) || this.configuration.getServerId().equals("allservers"), "proxyId is invalid");
|
checkArgument(getProxiesIds().contains(this.configuration.getProxyId()) || this.configuration.getProxyId().equals("allservers"), "proxyId is invalid");
|
||||||
sendChannelMessage("redisbungee-" + this.configuration.getServerId(), cmd);
|
sendChannelMessage("redisbungee-" + this.configuration.getProxyId(), cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -546,9 +546,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
||||||
if (crashFile.exists() && crashFile.delete()) {
|
if (crashFile.exists() && crashFile.delete()) {
|
||||||
getLogger().info("crash file was deleted");
|
getLogger().info("crash file was deleted");
|
||||||
} else if (jedis.hexists("heartbeats", configuration.getServerId())) {
|
} else if (jedis.hexists("heartbeats", configuration.getProxyId())) {
|
||||||
try {
|
try {
|
||||||
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getServerId()));
|
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getProxyId()));
|
||||||
long redisTime = getRedisTime(jedis.time());
|
long redisTime = getRedisTime(jedis.time());
|
||||||
if (redisTime < value + 20) {
|
if (redisTime < value + 20) {
|
||||||
getLogger().severe("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running.");
|
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) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jedis.hset("heartbeats", configuration.getServerId(), jedis.time().get(0));
|
jedis.hset("heartbeats", configuration.getProxyId(), jedis.time().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -570,9 +570,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
||||||
if (crashFile.exists() && crashFile.delete()) {
|
if (crashFile.exists() && crashFile.delete()) {
|
||||||
getLogger().info("crash file was deleted");
|
getLogger().info("crash file was deleted");
|
||||||
} else if (jedisCluster.hexists("heartbeats", configuration.getServerId())) {
|
} else if (jedisCluster.hexists("heartbeats", configuration.getProxyId())) {
|
||||||
try {
|
try {
|
||||||
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getServerId()));
|
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getProxyId()));
|
||||||
long redisTime = getRedisClusterTime();
|
long redisTime = getRedisClusterTime();
|
||||||
|
|
||||||
if (redisTime < value + 20) {
|
if (redisTime < value + 20) {
|
||||||
@ -584,13 +584,13 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(getRedisClusterTime()));
|
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(getRedisClusterTime()));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
serverIds = getCurrentServerIds(true, false);
|
proxiesIds = getCurrentProxiesIds(true, false);
|
||||||
|
|
||||||
uuidTranslator = new UUIDTranslator(this);
|
uuidTranslator = new UUIDTranslator(this);
|
||||||
|
|
||||||
@ -599,14 +599,14 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
public Void jedisTask(Jedis jedis) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
try {
|
try {
|
||||||
long redisTime = getRedisTime(jedis.time());
|
long redisTime = getRedisTime(jedis.time());
|
||||||
jedis.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
|
jedis.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
serverIds = getCurrentServerIds(true, false);
|
proxiesIds = getCurrentProxiesIds(true, false);
|
||||||
globalPlayerCount.set(getCurrentCount());
|
globalPlayerCount.set(getCurrentCount());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
getLogger().log(Level.SEVERE, "Unable to update data - did your Redis server go away?", 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) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
try {
|
try {
|
||||||
long redisTime = getRedisClusterTime();
|
long redisTime = getRedisClusterTime();
|
||||||
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
|
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to update heartbeat - did your Redis server go away?", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
serverIds = getCurrentServerIds(true, false);
|
proxiesIds = getCurrentProxiesIds(true, false);
|
||||||
globalPlayerCount.set(getCurrentCount());
|
globalPlayerCount.set(getCurrentCount());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
getLogger().log(Level.SEVERE, "Unable to update data - did your Redis server go away?", 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) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
try {
|
try {
|
||||||
Set<String> players = getLocalPlayersAsUuidStrings();
|
Set<String> players = getLocalPlayersAsUuidStrings();
|
||||||
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
List<String> lagged = getCurrentServerIds(false, true);
|
List<String> lagged = getCurrentProxiesIds(false, true);
|
||||||
|
|
||||||
// Clean up lagged players.
|
// Clean up lagged players.
|
||||||
for (String s : lagged) {
|
for (String s : lagged) {
|
||||||
@ -669,8 +669,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
|
|
||||||
for (String member : absentLocally) {
|
for (String member : absentLocally) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getProxiesIds()) {
|
||||||
if (proxyId.equals(configuration.getServerId())) continue;
|
if (proxyId.equals(configuration.getProxyId())) continue;
|
||||||
if (jedis.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
if (jedis.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
||||||
// Just clean up the set.
|
// Just clean up the set.
|
||||||
found = true;
|
found = true;
|
||||||
@ -681,7 +681,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
RedisUtil.cleanUpPlayer(member, jedis);
|
RedisUtil.cleanUpPlayer(member, jedis);
|
||||||
getLogger().warning("Player found in set that was not found locally and globally: " + member);
|
getLogger().warning("Player found in set that was not found locally and globally: " + member);
|
||||||
} else {
|
} 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);
|
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) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
try {
|
try {
|
||||||
Set<String> players = getLocalPlayersAsUuidStrings();
|
Set<String> players = getLocalPlayersAsUuidStrings();
|
||||||
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
List<String> lagged = getCurrentServerIds(false, true);
|
List<String> lagged = getCurrentProxiesIds(false, true);
|
||||||
|
|
||||||
// Clean up lagged players.
|
// Clean up lagged players.
|
||||||
for (String s : lagged) {
|
for (String s : lagged) {
|
||||||
@ -732,8 +732,8 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
|
|
||||||
for (String member : absentLocally) {
|
for (String member : absentLocally) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getProxiesIds()) {
|
||||||
if (proxyId.equals(configuration.getServerId())) continue;
|
if (proxyId.equals(configuration.getProxyId())) continue;
|
||||||
if (jedisCluster.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
if (jedisCluster.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
||||||
// Just clean up the set.
|
// Just clean up the set.
|
||||||
found = true;
|
found = true;
|
||||||
@ -744,7 +744,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
||||||
getLogger().warning("Player found in set that was not found locally and globally: " + member);
|
getLogger().warning("Player found in set that was not found locally and globally: " + member);
|
||||||
} else {
|
} 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);
|
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) {
|
new RedisTask<Void>(api) {
|
||||||
@Override
|
@Override
|
||||||
public Void jedisTask(Jedis jedis) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
jedis.hdel("heartbeats", configuration.getServerId());
|
jedis.hdel("heartbeats", configuration.getProxyId());
|
||||||
if (jedis.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
|
if (jedis.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
|
||||||
Set<String> players = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> players = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
for (String member : players)
|
for (String member : players)
|
||||||
RedisUtil.cleanUpPlayer(member, jedis);
|
RedisUtil.cleanUpPlayer(member, jedis);
|
||||||
}
|
}
|
||||||
@ -817,9 +817,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
jedisCluster.hdel("heartbeats", configuration.getServerId());
|
jedisCluster.hdel("heartbeats", configuration.getProxyId());
|
||||||
if (jedisCluster.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
|
if (jedisCluster.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
|
||||||
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
for (String member : players)
|
for (String member : players)
|
||||||
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ public class RedisBungeeCommands {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
TextComponent textComponent = new TextComponent();
|
TextComponent textComponent = new TextComponent();
|
||||||
textComponent.setText("You are on " + plugin.getApi().getServerId() + ".");
|
textComponent.setText("You are on " + plugin.getApi().getProxyId() + ".");
|
||||||
textComponent.setColor(ChatColor.YELLOW);
|
textComponent.setColor(ChatColor.YELLOW);
|
||||||
sender.sendMessage(textComponent);
|
sender.sendMessage(textComponent);
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ public class RedisBungeeCommands {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] strings) {
|
public void execute(CommandSender sender, String[] strings) {
|
||||||
TextComponent textComponent = new TextComponent();
|
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);
|
textComponent.setColor(ChatColor.YELLOW);
|
||||||
sender.sendMessage(textComponent);
|
sender.sendMessage(textComponent);
|
||||||
}
|
}
|
||||||
@ -301,8 +301,8 @@ public class RedisBungeeCommands {
|
|||||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getServerId();
|
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getProxyId();
|
||||||
if (!plugin.getServerIds().contains(proxy)) {
|
if (!plugin.getProxiesIds().contains(proxy)) {
|
||||||
sender.sendMessage(new ComponentBuilder(proxy + " is not a valid proxy. See /serverids for valid proxies.").color(ChatColor.RED).create());
|
sender.sendMessage(new ComponentBuilder(proxy + " is not a valid proxy. See /serverids for valid proxies.").color(ChatColor.RED).create());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,14 @@ public class PlayerUtils {
|
|||||||
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", player.getRemoteAddress().getHostName());
|
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);
|
pipeline.hmset("player:" + player.getUniqueId().toString(), playerData);
|
||||||
|
|
||||||
if (fireEvent) {
|
if (fireEvent) {
|
||||||
pipeline.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,14 +40,14 @@ public class PlayerUtils {
|
|||||||
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", player.getRemoteAddress().getHostName());
|
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);
|
jedisCluster.hmset("player:" + player.getUniqueId().toString(), playerData);
|
||||||
|
|
||||||
if (fireEvent) {
|
if (fireEvent) {
|
||||||
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(player.getRemoteAddress().getAddress()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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())) {
|
if (jedis.sismember("proxy:" + s + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
|
||||||
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ALREADY_LOGGED_IN)));
|
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ALREADY_LOGGED_IN)));
|
||||||
return null;
|
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())) {
|
if (jedisCluster.sismember("proxy:" + s + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
|
||||||
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ALREADY_LOGGED_IN)));
|
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ALREADY_LOGGED_IN)));
|
||||||
return null;
|
return null;
|
||||||
@ -122,7 +122,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
|||||||
// the end of moved code.
|
// the end of moved code.
|
||||||
|
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
|||||||
// the end of moved code.
|
// the end of moved code.
|
||||||
|
|
||||||
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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()))));
|
new AbstractDataManager.LoginPayload(event.getPlayer().getRemoteAddress().getAddress()))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
|||||||
public Void jedisTask(Jedis jedis) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
|
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
|
||||||
jedis.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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))));
|
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
|||||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
|
jedisCluster.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getServerInfo().getName());
|
||||||
jedisCluster.publish("redisbungee-data", gson.toJson(new AbstractDataManager.DataManagerMessage<>(
|
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))));
|
new AbstractDataManager.ServerChangePayload(event.getServer().getServerInfo().getName(), currentServer))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
|||||||
break;
|
break;
|
||||||
case "Proxy":
|
case "Proxy":
|
||||||
out.writeUTF("Proxy");
|
out.writeUTF("Proxy");
|
||||||
out.writeUTF(plugin.getConfiguration().getServerId());
|
out.writeUTF(plugin.getConfiguration().getProxyId());
|
||||||
break;
|
break;
|
||||||
case "PlayerProxy":
|
case "PlayerProxy":
|
||||||
String username = in.readUTF();
|
String username = in.readUTF();
|
||||||
@ -311,7 +311,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
|||||||
@Override
|
@Override
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
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();
|
String message = event.getMessage();
|
||||||
if (message.startsWith("/"))
|
if (message.startsWith("/"))
|
||||||
message = message.substring(1);
|
message = message.substring(1);
|
||||||
|
@ -55,7 +55,6 @@ import java.nio.file.StandardCopyOption;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
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")
|
@Plugin(id = "redisbungee", name = "RedisBungee", version = PomData.VERSION, url = "https://github.com/ProxioDev/RedisBungee", authors = "ProxioDev")
|
||||||
public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||||
@ -70,7 +69,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
private RedisBungeeConfiguration configuration;
|
private RedisBungeeConfiguration configuration;
|
||||||
private final VelocityDataManager dataManager;
|
private final VelocityDataManager dataManager;
|
||||||
private final OkHttpClient httpClient;
|
private final OkHttpClient httpClient;
|
||||||
private volatile List<String> serverIds;
|
private volatile List<String> proxiesIds;
|
||||||
private final AtomicInteger nagAboutServers = new AtomicInteger();
|
private final AtomicInteger nagAboutServers = new AtomicInteger();
|
||||||
private final AtomicInteger globalPlayerCount = new AtomicInteger();
|
private final AtomicInteger globalPlayerCount = new AtomicInteger();
|
||||||
private ScheduledTask integrityCheck;
|
private ScheduledTask integrityCheck;
|
||||||
@ -165,9 +164,9 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
getLogger().info("crash file was deleted");
|
getLogger().info("crash file was deleted");
|
||||||
} else if (jedis.hexists("heartbeats", configuration.getServerId())) {
|
} else if (jedis.hexists("heartbeats", configuration.getProxyId())) {
|
||||||
try {
|
try {
|
||||||
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getServerId()));
|
long value = Long.parseLong(jedis.hget("heartbeats", configuration.getProxyId()));
|
||||||
long redisTime = getRedisTime(jedis.time());
|
long redisTime = getRedisTime(jedis.time());
|
||||||
if (redisTime < value + 20) {
|
if (redisTime < value + 20) {
|
||||||
getLogger().error("You have launched a possible impostor Velocity / Bungeecord instance. Another instance is already running.");
|
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) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jedis.hset("heartbeats", configuration.getServerId(), jedis.time().get(0));
|
jedis.hset("heartbeats", configuration.getProxyId(), jedis.time().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -194,9 +193,9 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
getLogger().info("crash file was deleted");
|
getLogger().info("crash file was deleted");
|
||||||
} else if (jedisCluster.hexists("heartbeats", configuration.getServerId())) {
|
} else if (jedisCluster.hexists("heartbeats", configuration.getProxyId())) {
|
||||||
try {
|
try {
|
||||||
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getServerId()));
|
long value = Long.parseLong(jedisCluster.hget("heartbeats", configuration.getProxyId()));
|
||||||
long redisTime = getRedisClusterTime();
|
long redisTime = getRedisClusterTime();
|
||||||
|
|
||||||
if (redisTime < value + 20) {
|
if (redisTime < value + 20) {
|
||||||
@ -208,7 +207,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(getRedisClusterTime()));
|
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(getRedisClusterTime()));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -300,7 +299,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
||||||
try {
|
try {
|
||||||
List<String> keys = new ArrayList<>();
|
List<String> keys = new ArrayList<>();
|
||||||
for (String i : getServerIds()) {
|
for (String i : getProxiesIds()) {
|
||||||
keys.add("proxy:" + i + ":usersOnline");
|
keys.add("proxy:" + i + ":usersOnline");
|
||||||
}
|
}
|
||||||
if (!keys.isEmpty()) {
|
if (!keys.isEmpty()) {
|
||||||
@ -327,7 +326,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
||||||
try {
|
try {
|
||||||
List<String> keys = new ArrayList<>();
|
List<String> keys = new ArrayList<>();
|
||||||
for (String i : getServerIds()) {
|
for (String i : getProxiesIds()) {
|
||||||
keys.add("proxy:" + i + ":usersOnline");
|
keys.add("proxy:" + i + ":usersOnline");
|
||||||
}
|
}
|
||||||
if (!keys.isEmpty()) {
|
if (!keys.isEmpty()) {
|
||||||
@ -374,7 +373,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public Multimap<String, UUID> jedisTask(Jedis jedis) {
|
public Multimap<String, UUID> jedisTask(Jedis jedis) {
|
||||||
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
||||||
for (String serverId : getServerIds()) {
|
for (String serverId : getProxiesIds()) {
|
||||||
Set<String> players = jedis.smembers("proxy:" + serverId + ":usersOnline");
|
Set<String> players = jedis.smembers("proxy:" + serverId + ":usersOnline");
|
||||||
for (String player : players) {
|
for (String player : players) {
|
||||||
builder.put(jedis.hget("player:" + player, "server"), UUID.fromString(player));
|
builder.put(jedis.hget("player:" + player, "server"), UUID.fromString(player));
|
||||||
@ -386,7 +385,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public Multimap<String, UUID> clusterJedisTask(JedisCluster jedisCluster) {
|
public Multimap<String, UUID> clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
ImmutableMultimap.Builder<String, UUID> builder = ImmutableMultimap.builder();
|
||||||
for (String serverId : getServerIds()) {
|
for (String serverId : getProxiesIds()) {
|
||||||
Set<String> players = jedisCluster.smembers("proxy:" + serverId + ":usersOnline");
|
Set<String> players = jedisCluster.smembers("proxy:" + serverId + ":usersOnline");
|
||||||
for (String player : players) {
|
for (String player : players) {
|
||||||
builder.put(jedisCluster.hget("player:" + player, "server"), UUID.fromString(player));
|
builder.put(jedisCluster.hget("player:" + player, "server"), UUID.fromString(player));
|
||||||
@ -402,7 +401,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> getPlayersOnProxy(String proxyId) {
|
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) {
|
return new RedisTask<Set<UUID>>(api) {
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> jedisTask(Jedis jedis) {
|
public Set<UUID> jedisTask(Jedis jedis) {
|
||||||
@ -428,18 +427,18 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendProxyCommand(String serverId, String command) {
|
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);
|
sendChannelMessage("redisbungee-" + serverId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getServerIds() {
|
public List<String> getProxiesIds() {
|
||||||
return serverIds;
|
return proxiesIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getCurrentServerIds(boolean nag, boolean lagged) {
|
public List<String> getCurrentProxiesIds(boolean nag, boolean lagged) {
|
||||||
return new RedisTask<List<String>>(api) {
|
return new RedisTask<List<String>>(api) {
|
||||||
@Override
|
@Override
|
||||||
public List<String> jedisTask(Jedis jedis) {
|
public List<String> jedisTask(Jedis jedis) {
|
||||||
@ -469,7 +468,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
return servers.build();
|
return servers.build();
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
getLogger().error("Unable to fetch server IDs", 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();
|
return servers.build();
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
getLogger().error("Unable to fetch server IDs", e);
|
getLogger().error("Unable to fetch server IDs", e);
|
||||||
return Collections.singletonList(configuration.getServerId());
|
return Collections.singletonList(configuration.getProxyId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
@ -613,8 +612,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendProxyCommand(String cmd) {
|
public void sendProxyCommand(String cmd) {
|
||||||
checkArgument(getServerIds().contains(this.configuration.getServerId()) || this.configuration.getServerId().equals("allservers"), "proxyId is invalid");
|
checkArgument(getProxiesIds().contains(this.configuration.getProxyId()) || this.configuration.getProxyId().equals("allservers"), "proxyId is invalid");
|
||||||
sendChannelMessage("redisbungee-" + this.configuration.getServerId(), cmd);
|
sendChannelMessage("redisbungee-" + this.configuration.getProxyId(), cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -625,21 +624,21 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
serverIds = getCurrentServerIds(true, false);
|
proxiesIds = getCurrentProxiesIds(true, false);
|
||||||
// start heartbeat task
|
// start heartbeat task
|
||||||
RedisTask<Void> heartBeatRedisTask = new RedisTask<Void>(api) {
|
RedisTask<Void> heartBeatRedisTask = new RedisTask<Void>(api) {
|
||||||
@Override
|
@Override
|
||||||
public Void jedisTask(Jedis jedis) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
try {
|
try {
|
||||||
long redisTime = getRedisTime(jedis.time());
|
long redisTime = getRedisTime(jedis.time());
|
||||||
jedis.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
|
jedis.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().error("Unable to update heartbeat - did your Redis server go away?", e);
|
getLogger().error("Unable to update heartbeat - did your Redis server go away?", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
serverIds = getCurrentServerIds(true, false);
|
proxiesIds = getCurrentProxiesIds(true, false);
|
||||||
globalPlayerCount.set(getCurrentCount());
|
globalPlayerCount.set(getCurrentCount());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
getLogger().error("Unable to update data - did your Redis server go away?", 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) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
try {
|
try {
|
||||||
long redisTime = getRedisClusterTime();
|
long redisTime = getRedisClusterTime();
|
||||||
jedisCluster.hset("heartbeats", configuration.getServerId(), String.valueOf(redisTime));
|
jedisCluster.hset("heartbeats", configuration.getProxyId(), String.valueOf(redisTime));
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().error("Unable to update heartbeat - did your Redis server go away?", e);
|
getLogger().error("Unable to update heartbeat - did your Redis server go away?", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
serverIds = getCurrentServerIds(true, false);
|
proxiesIds = getCurrentProxiesIds(true, false);
|
||||||
globalPlayerCount.set(getCurrentCount());
|
globalPlayerCount.set(getCurrentCount());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
getLogger().error("Unable to update data - did your Redis server go away?", 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) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
try {
|
try {
|
||||||
Set<String> players = getLocalPlayersAsUuidStrings();
|
Set<String> players = getLocalPlayersAsUuidStrings();
|
||||||
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> playersInRedis = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
List<String> lagged = getCurrentServerIds(false, true);
|
List<String> lagged = getCurrentProxiesIds(false, true);
|
||||||
|
|
||||||
// Clean up lagged players.
|
// Clean up lagged players.
|
||||||
for (String s : lagged) {
|
for (String s : lagged) {
|
||||||
@ -698,8 +697,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
for (String member : absentLocally) {
|
for (String member : absentLocally) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getProxiesIds()) {
|
||||||
if (proxyId.equals(configuration.getServerId())) continue;
|
if (proxyId.equals(configuration.getProxyId())) continue;
|
||||||
if (jedis.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
if (jedis.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
||||||
// Just clean up the set.
|
// Just clean up the set.
|
||||||
found = true;
|
found = true;
|
||||||
@ -710,7 +709,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
RedisUtil.cleanUpPlayer(member, jedis);
|
RedisUtil.cleanUpPlayer(member, jedis);
|
||||||
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
|
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
|
||||||
} else {
|
} 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);
|
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) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
try {
|
try {
|
||||||
Set<String> players = getLocalPlayersAsUuidStrings();
|
Set<String> players = getLocalPlayersAsUuidStrings();
|
||||||
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> playersInRedis = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
List<String> lagged = getCurrentServerIds(false, true);
|
List<String> lagged = getCurrentProxiesIds(false, true);
|
||||||
|
|
||||||
// Clean up lagged players.
|
// Clean up lagged players.
|
||||||
for (String s : lagged) {
|
for (String s : lagged) {
|
||||||
@ -761,8 +760,8 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
for (String member : absentLocally) {
|
for (String member : absentLocally) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getProxiesIds()) {
|
||||||
if (proxyId.equals(configuration.getServerId())) continue;
|
if (proxyId.equals(configuration.getProxyId())) continue;
|
||||||
if (jedisCluster.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
if (jedisCluster.sismember("proxy:" + proxyId + ":usersOnline", member)) {
|
||||||
// Just clean up the set.
|
// Just clean up the set.
|
||||||
found = true;
|
found = true;
|
||||||
@ -773,7 +772,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
||||||
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
|
getLogger().warn("Player found in set that was not found locally and globally: {}", member);
|
||||||
} else {
|
} 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);
|
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) {
|
new RedisTask<Void>(api) {
|
||||||
@Override
|
@Override
|
||||||
public Void jedisTask(Jedis jedis) {
|
public Void jedisTask(Jedis jedis) {
|
||||||
jedis.hdel("heartbeats", configuration.getServerId());
|
jedis.hdel("heartbeats", configuration.getProxyId());
|
||||||
if (jedis.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
|
if (jedis.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
|
||||||
Set<String> players = jedis.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> players = jedis.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
for (String member : players)
|
for (String member : players)
|
||||||
RedisUtil.cleanUpPlayer(member, jedis);
|
RedisUtil.cleanUpPlayer(member, jedis);
|
||||||
}
|
}
|
||||||
@ -841,9 +840,9 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
public Void clusterJedisTask(JedisCluster jedisCluster) {
|
||||||
jedisCluster.hdel("heartbeats", configuration.getServerId());
|
jedisCluster.hdel("heartbeats", configuration.getProxyId());
|
||||||
if (jedisCluster.scard("proxy:" + configuration.getServerId() + ":usersOnline") > 0) {
|
if (jedisCluster.scard("proxy:" + configuration.getProxyId() + ":usersOnline") > 0) {
|
||||||
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getServerId() + ":usersOnline");
|
Set<String> players = jedisCluster.smembers("proxy:" + configuration.getProxyId() + ":usersOnline");
|
||||||
for (String member : players)
|
for (String member : players)
|
||||||
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
RedisUtil.cleanUpPlayer(member, jedisCluster);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.imaginarycode.minecraft.redisbungee.commands;
|
|||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -271,7 +270,7 @@ public class RedisBungeeCommands {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Invocation invocation) {
|
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
|
@Override
|
||||||
@ -289,7 +288,7 @@ public class RedisBungeeCommands {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(Invocation invocation) {
|
public void execute(Invocation invocation) {
|
||||||
invocation.source().sendMessage(
|
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
|
@Override
|
||||||
@ -310,8 +309,8 @@ public class RedisBungeeCommands {
|
|||||||
CommandSource sender= invocation.source();
|
CommandSource sender= invocation.source();
|
||||||
String[] args = invocation.arguments();
|
String[] args = invocation.arguments();
|
||||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||||
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getServerId();
|
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getProxyId();
|
||||||
if (!plugin.getServerIds().contains(proxy)) {
|
if (!plugin.getProxiesIds().contains(proxy)) {
|
||||||
sender.sendMessage(Component.text(proxy + " is not a valid proxy. See /serverids for valid proxies.", NamedTextColor.RED));
|
sender.sendMessage(Component.text(proxy + " is not a valid proxy. See /serverids for valid proxies.", NamedTextColor.RED));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user