mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Add better AUTH support.
This commit is contained in:
parent
0beae77548
commit
8c824cc397
@ -17,10 +17,7 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.*;
|
||||||
import redis.clients.jedis.JedisPool;
|
|
||||||
import redis.clients.jedis.JedisPoolConfig;
|
|
||||||
import redis.clients.jedis.JedisPubSub;
|
|
||||||
import redis.clients.jedis.exceptions.JedisException;
|
import redis.clients.jedis.exceptions.JedisException;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -135,9 +132,10 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
||||||
Set<String> smembers = tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline");
|
if (tmpRsc.scard("server:" + configuration.getServerId() + ":usersOnline") > 0) {
|
||||||
if (smembers.size() > 0)
|
Set<String> smembers = tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline");
|
||||||
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", smembers.toArray(new String[smembers.size()]));
|
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", smembers.toArray(new String[smembers.size()]));
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
@ -171,9 +169,10 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
Jedis tmpRsc = pool.getResource();
|
Jedis tmpRsc = pool.getResource();
|
||||||
try {
|
try {
|
||||||
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
tmpRsc.set("server:" + configuration.getServerId() + ":playerCount", "0"); // reset
|
||||||
Set<String> smembers = tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline");
|
if (tmpRsc.scard("server:" + configuration.getServerId() + ":usersOnline") > 0) {
|
||||||
if (smembers.size() > 0)
|
Set<String> smembers = tmpRsc.smembers("server:" + configuration.getServerId() + ":usersOnline");
|
||||||
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", smembers.toArray(new String[smembers.size()]));
|
tmpRsc.srem("server:" + configuration.getServerId() + ":usersOnline", smembers.toArray(new String[smembers.size()]));
|
||||||
|
}
|
||||||
} catch (JedisException | ClassCastException ignored) {
|
} catch (JedisException | ClassCastException ignored) {
|
||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
@ -206,6 +205,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
|
|
||||||
String redisServer = "localhost";
|
String redisServer = "localhost";
|
||||||
int redisPort = 6379;
|
int redisPort = 6379;
|
||||||
|
String redisPassword = null;
|
||||||
try {
|
try {
|
||||||
redisServer = ((String) rawYaml.get("redis-server"));
|
redisServer = ((String) rawYaml.get("redis-server"));
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
@ -214,6 +214,10 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
redisPort = ((Integer) rawYaml.get("redis-port"));
|
redisPort = ((Integer) rawYaml.get("redis-port"));
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
redisPassword = ((String) rawYaml.get("redis-password"));
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
configuration.setServerId((String) rawYaml.get("server-id"));
|
configuration.setServerId((String) rawYaml.get("server-id"));
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
@ -238,9 +242,13 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
|
|
||||||
configuration.setLinkedServers(ImmutableList.copyOf(servers));
|
configuration.setLinkedServers(ImmutableList.copyOf(servers));
|
||||||
|
|
||||||
|
if (redisPassword != null && (redisPassword.equals("") || redisPassword.equals("none"))) {
|
||||||
|
redisPassword = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (redisServer != null) {
|
if (redisServer != null) {
|
||||||
if (!redisServer.equals("")) {
|
if (!redisServer.equals("")) {
|
||||||
pool = new JedisPool(new JedisPoolConfig(), redisServer, redisPort);
|
pool = new JedisPool(new JedisPoolConfig(), redisServer, redisPort, Protocol.DEFAULT_TIMEOUT, redisPassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
# Get Redis from http://redis.io/
|
# Get Redis from http://redis.io/
|
||||||
redis-server: 127.0.0.1
|
redis-server: 127.0.0.1
|
||||||
redis-port: 6379
|
redis-port: 6379
|
||||||
|
# OPTIONAL: If your Redis server uses AUTH, set the password required.
|
||||||
|
redis-password: ""
|
||||||
|
|
||||||
# An identifier for this BungeeCord instance.
|
# An identifier for this BungeeCord instance.
|
||||||
server-id: iluvbungee
|
server-id: iluvbungee
|
||||||
|
Loading…
Reference in New Issue
Block a user