mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
move serverId to its own field, prepare for next release (0.3.1-SNAPSHOT)
This commit is contained in:
parent
a532a7e6ba
commit
f9fbbb388a
@ -4,11 +4,11 @@ RedisBungee bridges [Redis](http://redis.io) and BungeeCord together. This is th
|
|||||||
|
|
||||||
## Compiling
|
## Compiling
|
||||||
|
|
||||||
RedisBungee is distributed as a [maven](http://maven.apache.org) project. To compile it:
|
RedisBungee is distributed as a [maven](http://maven.apache.org) project. To compile it and install it in your local Maven repository:
|
||||||
|
|
||||||
git clone https://github.com/minecrafter/RedisBungee.git
|
git clone https://github.com/minecrafter/RedisBungee.git
|
||||||
cd RedisBungee
|
cd RedisBungee
|
||||||
mvn clean package
|
mvn clean install
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
2
pom.xml
2
pom.xml
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<groupId>com.imaginarycode.minecraft</groupId>
|
<groupId>com.imaginarycode.minecraft</groupId>
|
||||||
<artifactId>RedisBungee</artifactId>
|
<artifactId>RedisBungee</artifactId>
|
||||||
<version>0.3</version>
|
<version>0.3.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -56,6 +56,9 @@ public final class RedisBungee extends Plugin {
|
|||||||
private UUIDTranslator uuidTranslator;
|
private UUIDTranslator uuidTranslator;
|
||||||
@Getter
|
@Getter
|
||||||
private static Gson gson = new Gson();
|
private static Gson gson = new Gson();
|
||||||
|
@Getter
|
||||||
|
private static String serverId;
|
||||||
|
|
||||||
private static RedisBungeeAPI api;
|
private static RedisBungeeAPI api;
|
||||||
private static PubSubListener psl = null;
|
private static PubSubListener psl = null;
|
||||||
private List<String> serverIds;
|
private List<String> serverIds;
|
||||||
@ -94,7 +97,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
return servers.build();
|
return servers.build();
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
getLogger().log(Level.SEVERE, "Unable to fetch all server IDs", e);
|
getLogger().log(Level.SEVERE, "Unable to fetch all server IDs", e);
|
||||||
return Collections.singletonList(configuration.getString("server-id"));
|
return Collections.singletonList(serverId);
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(jedis);
|
pool.returnResource(jedis);
|
||||||
}
|
}
|
||||||
@ -129,7 +132,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
if (!serverIds.contains(entry.getKey()))
|
if (!serverIds.contains(entry.getKey()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (entry.getKey().equals(configuration.getString("server-id"))) continue;
|
if (entry.getKey().equals(serverId)) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
c += Integer.valueOf(entry.getValue());
|
c += Integer.valueOf(entry.getValue());
|
||||||
@ -170,7 +173,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
try {
|
try {
|
||||||
List<String> keys = new ArrayList<>();
|
List<String> keys = new ArrayList<>();
|
||||||
for (String i : getServerIds()) {
|
for (String i : getServerIds()) {
|
||||||
if (i.equals(configuration.getString("server-id")))
|
if (i.equals(serverId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
keys.add("server:" + i + ":usersOnline");
|
keys.add("server:" + i + ":usersOnline");
|
||||||
@ -235,7 +238,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
getLogger().info("I found a funny number for when " + uuid + " was last online!");
|
getLogger().info("I found a funny number for when " + uuid + " was last online!");
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getServerIds()) {
|
||||||
if (proxyId.equals(configuration.getString("server-id"))) continue;
|
if (proxyId.equals(serverId)) continue;
|
||||||
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", uuid.toString())) {
|
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", uuid.toString())) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@ -313,8 +316,8 @@ public final class RedisBungee extends Plugin {
|
|||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
tmpRsc.hset("playerCounts", configuration.getString("server-id"), "0"); // reset
|
tmpRsc.hset("playerCounts", serverId, "0"); // reset
|
||||||
tmpRsc.hset("heartbeats", configuration.getString("server-id"), String.valueOf(System.currentTimeMillis()));
|
tmpRsc.hset("heartbeats", serverId, String.valueOf(System.currentTimeMillis()));
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
@ -326,8 +329,8 @@ public final class RedisBungee extends Plugin {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Jedis rsc = pool.getResource();
|
Jedis rsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
rsc.hset("playerCounts", configuration.getString("server-id"), String.valueOf(getProxy().getOnlineCount()));
|
rsc.hset("playerCounts", serverId, String.valueOf(getProxy().getOnlineCount()));
|
||||||
rsc.hset("heartbeats", configuration.getString("server-id"), String.valueOf(System.currentTimeMillis()));
|
rsc.hset("heartbeats", serverId, String.valueOf(System.currentTimeMillis()));
|
||||||
} catch (JedisConnectionException e) {
|
} catch (JedisConnectionException e) {
|
||||||
// Redis server has disappeared!
|
// Redis server has disappeared!
|
||||||
getLogger().log(Level.SEVERE, "Unable to update proxy counts - did your Redis server go away?", e);
|
getLogger().log(Level.SEVERE, "Unable to update proxy counts - did your Redis server go away?", e);
|
||||||
@ -358,12 +361,12 @@ public final class RedisBungee extends Plugin {
|
|||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
Set<String> players = getLocalPlayersAsUuidStrings();
|
Set<String> players = getLocalPlayersAsUuidStrings();
|
||||||
for (String member : tmpRsc.smembers("server:" + configuration.getString("server-id") + ":usersOnline"))
|
for (String member : tmpRsc.smembers("server:" + serverId + ":usersOnline"))
|
||||||
if (!players.contains(member)) {
|
if (!players.contains(member)) {
|
||||||
// Are they simply on a different proxy?
|
// Are they simply on a different proxy?
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String proxyId : getServerIds()) {
|
for (String proxyId : getServerIds()) {
|
||||||
if (proxyId.equals(configuration.getString("server-id"))) continue;
|
if (proxyId.equals(serverId)) continue;
|
||||||
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", member)) {
|
if (tmpRsc.sismember("server:" + proxyId + ":usersOnline", member)) {
|
||||||
// Just clean up the set.
|
// Just clean up the set.
|
||||||
found = true;
|
found = true;
|
||||||
@ -374,7 +377,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||||
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 {
|
||||||
tmpRsc.srem("server:" + configuration.getString("server-id") + ":usersOnline", member);
|
tmpRsc.srem("server:" + serverId + ":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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,12 +399,12 @@ public final class RedisBungee extends Plugin {
|
|||||||
consumer.stop();
|
consumer.stop();
|
||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
tmpRsc.hdel("playerCounts", configuration.getString("server-id"), "0");
|
tmpRsc.hdel("playerCounts", serverId, "0");
|
||||||
if (tmpRsc.scard("server:" + configuration.getString("server-id") + ":usersOnline") > 0) {
|
if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) {
|
||||||
for (String member : tmpRsc.smembers("server:" + configuration.getString("server-id") + ":usersOnline"))
|
for (String member : tmpRsc.smembers("server:" + serverId + ":usersOnline"))
|
||||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||||
}
|
}
|
||||||
tmpRsc.hdel("heartbeats", configuration.getString("server-id"));
|
tmpRsc.hdel("heartbeats", serverId);
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
@ -429,13 +432,14 @@ public final class RedisBungee extends Plugin {
|
|||||||
String redisServer = configuration.getString("redis-server", "localhost");
|
String redisServer = configuration.getString("redis-server", "localhost");
|
||||||
int redisPort = configuration.getInt("redis-port", 6379);
|
int redisPort = configuration.getInt("redis-port", 6379);
|
||||||
String redisPassword = configuration.getString("redis-password");
|
String redisPassword = configuration.getString("redis-password");
|
||||||
|
serverId = configuration.getString("server-id");
|
||||||
|
|
||||||
if (redisPassword != null && (redisPassword.equals("") || redisPassword.equals("none"))) {
|
if (redisPassword != null && (redisPassword.equals("") || redisPassword.equals("none"))) {
|
||||||
redisPassword = null;
|
redisPassword = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration sanity checks.
|
// Configuration sanity checks.
|
||||||
if (configuration.get("server-id") == null || configuration.getString("server-id").equals("")) {
|
if (serverId == null || serverId.equals("")) {
|
||||||
throw new RuntimeException("server-id is not specified in the configuration or is empty");
|
throw new RuntimeException("server-id is not specified in the configuration or is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +457,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
File crashFile = new File(getDataFolder(), "restarted_from_crash.txt");
|
||||||
if (crashFile.exists())
|
if (crashFile.exists())
|
||||||
crashFile.delete();
|
crashFile.delete();
|
||||||
else if (rsc.hexists("heartbeat", configuration.getString("server-id"))) {
|
else if (rsc.hexists("heartbeat", serverId)) {
|
||||||
getLogger().severe("You have launched a possible imposter BungeeCord instance. Another instance is already running.");
|
getLogger().severe("You have launched a possible imposter BungeeCord instance. Another instance is already running.");
|
||||||
getLogger().severe("For data consistency reasons, RedisBungee will now disable itself.");
|
getLogger().severe("For data consistency reasons, RedisBungee will now disable itself.");
|
||||||
getLogger().severe("If this instance is coming up from a crash, create a file in your RedisBungee plugins directory with the name 'restarted_from_crash.txt' and RedisBungee will not perform this check.");
|
getLogger().severe("If this instance is coming up from a crash, create a file in your RedisBungee plugins directory with the name 'restarted_from_crash.txt' and RedisBungee will not perform this check.");
|
||||||
@ -490,7 +494,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
try {
|
try {
|
||||||
rsc = pool.getResource();
|
rsc = pool.getResource();
|
||||||
jpsh = new JedisPubSubHandler();
|
jpsh = new JedisPubSubHandler();
|
||||||
rsc.subscribe(jpsh, "redisbungee-" + configuration.getString("server-id"), "redisbungee-allservers");
|
rsc.subscribe(jpsh, "redisbungee-" + serverId, "redisbungee-allservers");
|
||||||
} catch (JedisException | ClassCastException ignored) {
|
} catch (JedisException | ClassCastException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ public class RedisBungeeAPI {
|
|||||||
* @since 0.2.5
|
* @since 0.2.5
|
||||||
*/
|
*/
|
||||||
public final String getServerId() {
|
public final String getServerId() {
|
||||||
return RedisBungee.getConfiguration().getString("server-id");
|
return plugin.getServerId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +46,7 @@ public class RedisBungeeConsumer implements Runnable {
|
|||||||
private void handle(ConsumerEvent event, Jedis jedis) {
|
private void handle(ConsumerEvent event, Jedis jedis) {
|
||||||
if (event instanceof PlayerLoggedInConsumerEvent) {
|
if (event instanceof PlayerLoggedInConsumerEvent) {
|
||||||
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
|
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
|
||||||
jedis.sadd("server:" + RedisBungee.getConfiguration().getString("server-id", "") + ":usersOnline", event1.getPlayer().getUniqueId().toString());
|
jedis.sadd("server:" + RedisBungee.getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
|
||||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
|
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
|
||||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
|
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
|
||||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "name", event1.getPlayer().getName());
|
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "name", event1.getPlayer().getName());
|
||||||
|
@ -149,7 +149,7 @@ public class RedisBungeeListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPubSubMessage(PubSubMessageEvent event) {
|
public void onPubSubMessage(PubSubMessageEvent event) {
|
||||||
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + RedisBungee.getConfiguration().getString("server-id"))) {
|
if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + RedisBungee.getApi().getServerId())) {
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
if (message.startsWith("/"))
|
if (message.startsWith("/"))
|
||||||
message = message.substring(1);
|
message = message.substring(1);
|
||||||
|
@ -10,7 +10,7 @@ import redis.clients.jedis.Jedis;
|
|||||||
|
|
||||||
public class RedisUtil {
|
public class RedisUtil {
|
||||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
public static void cleanUpPlayer(String player, Jedis rsc) {
|
||||||
rsc.srem("server:" + RedisBungee.getConfiguration().getString("server-id") + ":usersOnline", player);
|
rsc.srem("server:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
||||||
rsc.hdel("player:" + player, "server");
|
rsc.hdel("player:" + player, "server");
|
||||||
rsc.hdel("player:" + player, "ip");
|
rsc.hdel("player:" + player, "ip");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: RedisBungee
|
name: RedisBungee
|
||||||
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
|
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
|
||||||
version: 0.3
|
version: 0.3.1
|
||||||
author: tuxed
|
author: tuxed
|
||||||
# This is used so that we can automagically override default BungeeCord behavior.
|
# This is used so that we can automagically override default BungeeCord behavior.
|
||||||
softDepends: ["cmd_find", "cmd_list"]
|
softDepends: ["cmd_find", "cmd_list"]
|
Loading…
Reference in New Issue
Block a user