mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-05-03 11:40:29 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b9fd6d7ff | |||
| a526298d1c | |||
| c69b1e214e | |||
| e5f0075a58 | |||
| 748bc13568 | |||
| 5e3ce725de | |||
| 92bb0030de | |||
| d8c21edc7a | |||
| 87a2b93537 |
@@ -47,11 +47,11 @@ SpigotMC resource page: [click](https://www.spigotmc.org/resources/redisbungee.8
|
||||
| 7.x.x | ✔ |
|
||||
|
||||
|
||||
## Implementing RedisBungee in your plugin: [](https://github.com/Limework/RedisBungee/actions/workflows/maven.yml) [](https://jitpack.io/#limework/redisbungee)
|
||||
## Implementing RedisBungee in your plugin: [](https://github.com/Limework/RedisBungee/actions/workflows/maven.yml) [](https://jitpack.io/#ProxioDev/redisbungee)
|
||||
|
||||
RedisBungee is distributed as a [maven](https://maven.apache.org) project.
|
||||
|
||||
By using jitpack [](https://jitpack.io/#limework/redisbungee)
|
||||
By using jitpack [](https://jitpack.io/#ProxioDev/redisbungee)
|
||||
|
||||
## Setup jitpack repository
|
||||
```xml
|
||||
@@ -66,7 +66,7 @@ By using jitpack [](https://ji
|
||||
add this in your project dependencies
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.limework.redisbungee</groupId>
|
||||
<groupId>com.github.proxiodev.redisbungee</groupId>
|
||||
<artifactId>RedisBungee-Bungee</artifactId>
|
||||
<version>VERSION</version>
|
||||
<scope>provided</scope>
|
||||
@@ -86,7 +86,7 @@ depends: [ RedisBungee ]
|
||||
## [Velocity](https://github.com/PaperMC/Velocity)
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.limework.redisbungee</groupId>
|
||||
<groupId>com.github.proxiodev.redisbungee</groupId>
|
||||
<artifactId>RedisBungee-Velocity</artifactId>
|
||||
<version>VERSION</version>
|
||||
<scope>provided</scope>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
<version>0.9.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -23,10 +23,6 @@ import java.util.Map;
|
||||
|
||||
public abstract class AbstractRedisBungeeListener<LE, PLE, PD, SC, PP, PM, PS> {
|
||||
|
||||
protected static final String ALREADY_LOGGED_IN = "§cYou are already logged on to this server. \n\nIt may help to try logging in again in a few minutes.\nIf this does not resolve your issue, please contact staff.";
|
||||
|
||||
protected static final String ONLINE_MODE_RECONNECT = "§cWhoops! You need to reconnect\n\nWe found someone online using your username. They were kicked and you may reconnect.\nIf this does not work, please contact staff.";
|
||||
|
||||
protected final RedisBungeePlugin<?> plugin;
|
||||
protected final List<InetAddress> exemptAddresses;
|
||||
protected final Gson gson = new Gson();
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api.config;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
@@ -39,11 +41,6 @@ public interface ConfigLoader {
|
||||
loadConfig(plugin, dataFolder.toPath());
|
||||
}
|
||||
|
||||
// There currently a problem with the SSL/TLS connections
|
||||
// looking into the Jedis source code you can pass some form of
|
||||
// Domain Validation, SSL factory from javax packages
|
||||
// todo: create Domain valdiation
|
||||
// todo: add new config options for ssl certs locations
|
||||
default void loadConfig(RedisBungeePlugin<?> plugin, Path dataFolder) throws IOException {
|
||||
Path configFile = createConfigFile(dataFolder);
|
||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||
@@ -87,7 +84,7 @@ public interface ConfigLoader {
|
||||
} else {
|
||||
plugin.logInfo("Loaded proxy id " + proxyId);
|
||||
}
|
||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands);
|
||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder)));
|
||||
Summoner<?> summoner;
|
||||
RedisBungeeMode redisBungeeMode;
|
||||
if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
|
||||
@@ -126,7 +123,7 @@ public interface ConfigLoader {
|
||||
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
||||
poolConfig.setMaxTotal(maxConnections);
|
||||
poolConfig.setBlockWhenExhausted(true);
|
||||
summoner = new JedisPooledSummoner(new PooledConnectionProvider(new ConnectionFactory(new HostAndPort(redisServer, redisPort), DefaultJedisClientConfig.builder().timeoutMillis(5000).password(redisPassword).build()), poolConfig), jedisPool);
|
||||
summoner = new JedisPooledSummoner(new PooledConnectionProvider(new ConnectionFactory(new HostAndPort(redisServer, redisPort), DefaultJedisClientConfig.builder().timeoutMillis(5000).ssl(useSSL).password(redisPassword).build()), poolConfig), jedisPool);
|
||||
redisBungeeMode = RedisBungeeMode.SINGLE;
|
||||
}
|
||||
plugin.logInfo("Successfully connected to Redis.");
|
||||
@@ -135,6 +132,29 @@ public interface ConfigLoader {
|
||||
|
||||
void onConfigLoad(RedisBungeeConfiguration configuration, Summoner<?> summoner, RedisBungeeMode mode);
|
||||
|
||||
default ImmutableMap<RedisBungeeConfiguration.MessageType, String> getMessagesFromPath(Path path) throws IOException {
|
||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(path).build();
|
||||
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
||||
HashMap<RedisBungeeConfiguration.MessageType, String> messages = new HashMap<>();
|
||||
messages.put(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION, node.getNode("logged-in-other-location").getString("§cLogged in from another location."));
|
||||
return ImmutableMap.copyOf(messages);
|
||||
}
|
||||
|
||||
default Path createMessagesFile(Path dataFolder) throws IOException {
|
||||
if (Files.notExists(dataFolder)) {
|
||||
Files.createDirectory(dataFolder);
|
||||
}
|
||||
Path file = dataFolder.resolve("messages.yml");
|
||||
if (Files.notExists(file)) {
|
||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream("messages.yml")) {
|
||||
Files.createFile(file);
|
||||
assert in != null;
|
||||
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
default Path createConfigFile(Path dataFolder) throws IOException {
|
||||
if (Files.notExists(dataFolder)) {
|
||||
Files.createDirectory(dataFolder);
|
||||
|
||||
@@ -11,12 +11,21 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api.config;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.net.InetAddresses;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class RedisBungeeConfiguration {
|
||||
|
||||
public enum MessageType {
|
||||
LOGGED_IN_OTHER_LOCATION
|
||||
}
|
||||
|
||||
private final ImmutableMap<MessageType, String> messages;
|
||||
public static final int CONFIG_VERSION = 1;
|
||||
private final String proxyId;
|
||||
private final List<InetAddress> exemptAddresses;
|
||||
@@ -25,9 +34,9 @@ public class RedisBungeeConfiguration {
|
||||
|
||||
private final boolean overrideBungeeCommands;
|
||||
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands) {
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap<MessageType, String> messages) {
|
||||
this.proxyId = proxyId;
|
||||
|
||||
this.messages = messages;
|
||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||
for (String s : exemptAddresses) {
|
||||
addressBuilder.add(InetAddresses.forString(s));
|
||||
@@ -52,4 +61,8 @@ public class RedisBungeeConfiguration {
|
||||
public boolean doOverrideBungeeCommands() {
|
||||
return overrideBungeeCommands;
|
||||
}
|
||||
|
||||
public ImmutableMap<MessageType, String> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
@VisibleForTesting
|
||||
public class RedisUtil {
|
||||
public static int PROXY_TIMEOUT = 30;
|
||||
public final static int PROXY_TIMEOUT = 30;
|
||||
public static boolean isRedisVersionRight(String redisVersion) {
|
||||
String[] args = redisVersion.split("\\.");
|
||||
if (args.length < 2) {
|
||||
|
||||
@@ -3,19 +3,55 @@ package com.imaginarycode.minecraft.redisbungee.api.util.player;
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerQuitPayload;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
public static void cleanUpPlayer(String uuid, UnifiedJedis rsc, boolean firePayload) {
|
||||
final long timestamp = System.currentTimeMillis();
|
||||
final boolean isKickedFromOtherLocation = isKickedOtherLocation(uuid, rsc);
|
||||
rsc.srem("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", uuid);
|
||||
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
|
||||
long timestamp = System.currentTimeMillis();
|
||||
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
|
||||
if (firePayload) {
|
||||
if (!isKickedFromOtherLocation) {
|
||||
rsc.hdel("player:" + uuid, "server", "ip", "proxy");
|
||||
rsc.hset("player:" + uuid, "online", String.valueOf(timestamp));
|
||||
}
|
||||
if (firePayload && !isKickedFromOtherLocation) {
|
||||
playerQuitPayload(uuid, rsc, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setKickedOtherLocation(String uuid, UnifiedJedis unifiedJedis) {
|
||||
// set anything for sake of exists check. then expire it after 2 seconds. should be great?
|
||||
unifiedJedis.set("kicked-other-location::" + uuid, "0");
|
||||
unifiedJedis.expire("kicked-other-location::" + uuid, 2);
|
||||
}
|
||||
|
||||
public static boolean isKickedOtherLocation(String uuid, UnifiedJedis unifiedJedis) {
|
||||
return unifiedJedis.exists("kicked-other-location::" + uuid);
|
||||
}
|
||||
|
||||
|
||||
public static void createPlayer(UUID uuid, UnifiedJedis unifiedJedis, String currentServer, InetAddress hostname, boolean fireEvent) {
|
||||
final boolean isKickedFromOtherLocation = isKickedOtherLocation(uuid.toString(), unifiedJedis);
|
||||
Map<String, String> playerData = new HashMap<>(4);
|
||||
playerData.put("online", "0");
|
||||
playerData.put("ip", hostname.getHostName());
|
||||
playerData.put("proxy", AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId());
|
||||
if (currentServer != null) {
|
||||
playerData.put("server", currentServer);
|
||||
}
|
||||
unifiedJedis.sadd("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", uuid.toString());
|
||||
unifiedJedis.hset("player:" + uuid, playerData);
|
||||
if (fireEvent && !isKickedFromOtherLocation) {
|
||||
playerJoinPayload(uuid, unifiedJedis, hostname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public final class UUIDTranslator {
|
||||
public void persistInfo(String name, UUID uuid, UnifiedJedis unifiedJedis) {
|
||||
addToMaps(name, uuid);
|
||||
String json = gson.toJson(uuidToNameMap.get(uuid));
|
||||
unifiedJedis.hmset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json));
|
||||
unifiedJedis.hset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json));
|
||||
}
|
||||
|
||||
private static class CachedUUIDEntry {
|
||||
|
||||
@@ -32,15 +32,15 @@ redis-password: ""
|
||||
# inefficient plugins or a lot of players.
|
||||
max-redis-connections: 10
|
||||
|
||||
# since redis can support ssl by version 6 you can use ssl in redis bungee too!
|
||||
# since redis can support ssl by version 6 you can use ssl / tls in redis bungee too!
|
||||
# but there is more configuration needed to work see https://github.com/ProxioDev/RedisBungee/issues/18
|
||||
# in cluster mode using ssl without password is ignored due fact is not supported in Jedis lib
|
||||
# Keep note that SSL/TLS connections will decrease redis performance so use it when needed.
|
||||
useSSL: false
|
||||
|
||||
# An identifier for this BungeeCord / Velocity instance. Will randomly generate if leaving it blank.
|
||||
proxy-id: "test-1"
|
||||
|
||||
# In version 0.8.0 Internally now uses JedisPooled instead of Jedis, JedisPool.
|
||||
# since version 0.8.0 Internally now uses JedisPooled instead of Jedis, JedisPool.
|
||||
# which will break compatibility with old plugins that uses RedisBungee JedisPool
|
||||
# so to mitigate this issue, we will instruct RedisBungee to init an JedisPool for compatibility reasons.
|
||||
# enabled by default
|
||||
|
||||
1
RedisBungee-API/src/main/resources/messages.yml
Normal file
1
RedisBungee-API/src/main/resources/messages.yml
Normal file
@@ -0,0 +1 @@
|
||||
logged-in-other-location: "§cYou logged in from another location!"
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
<version>0.9.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -10,37 +10,19 @@
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
||||
|
||||
public class BungeePlayerUtils {
|
||||
|
||||
public static void createPlayer(ProxiedPlayer player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
||||
createPlayer(player.getPendingConnection(), unifiedJedis, fireEvent);
|
||||
if (player.getServer() != null)
|
||||
unifiedJedis.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
|
||||
}
|
||||
|
||||
public static void createPlayer(PendingConnection connection, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
||||
Map<String, String> playerData = new HashMap<>(4);
|
||||
playerData.put("online", "0");
|
||||
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
|
||||
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getProxyId());
|
||||
|
||||
unifiedJedis.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", connection.getUniqueId().toString());
|
||||
unifiedJedis.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
||||
|
||||
if (fireEvent) {
|
||||
playerJoinPayload(connection.getUniqueId(), unifiedJedis, connection.getAddress().getAddress());
|
||||
public static void createBungeePlayer(ProxiedPlayer player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
||||
String serverName = null;
|
||||
if (player.getServer() != null) {
|
||||
serverName = player.getServer().getInfo().getName();
|
||||
}
|
||||
PendingConnection pendingConnection = player.getPendingConnection();
|
||||
PlayerUtils.createPlayer(player.getUniqueId(), unifiedJedis, serverName, pendingConnection.getAddress().getAddress(), fireEvent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
||||
if (proxiedPlayer == null)
|
||||
return; // We'll deal with it later.
|
||||
|
||||
BungeePlayerUtils.createPlayer(proxiedPlayer, unifiedJedis, false);
|
||||
BungeePlayerUtils.createBungeePlayer(proxiedPlayer, unifiedJedis, false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractRedisBungeeListener;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
||||
@@ -47,7 +48,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler (priority = HIGHEST)
|
||||
@EventHandler(priority = HIGHEST)
|
||||
public void onLogin(LoginEvent event) {
|
||||
event.registerIntent((Plugin) plugin);
|
||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
||||
@@ -57,27 +58,9 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// We make sure they aren't trying to use an existing player's name.
|
||||
// This is problematic for online-mode servers as they always disconnect old clients.
|
||||
if (plugin.isOnlineMode()) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) plugin.getPlayer(event.getConnection().getName());
|
||||
|
||||
if (player != null) {
|
||||
event.setCancelled(true);
|
||||
// TODO: Make it accept a BaseComponent[] like everything else.
|
||||
event.setCancelReason(ONLINE_MODE_RECONNECT);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : plugin.getProxiesIds()) {
|
||||
if (unifiedJedis.sismember("proxy:" + s + ":usersOnline", event.getConnection().getUniqueId().toString())) {
|
||||
event.setCancelled(true);
|
||||
// TODO: Make it accept a BaseComponent[] like everything else.
|
||||
event.setCancelReason(ALREADY_LOGGED_IN);
|
||||
return null;
|
||||
}
|
||||
if (api.isPlayerOnline(event.getConnection().getUniqueId())) {
|
||||
PlayerUtils.setKickedOtherLocation(event.getConnection().getUniqueId().toString(), unifiedJedis);
|
||||
api.kickPlayer(event.getConnection().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
@@ -94,7 +77,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
||||
@Override
|
||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), unifiedJedis);
|
||||
BungeePlayerUtils.createPlayer(event.getPlayer(), unifiedJedis, true);
|
||||
BungeePlayerUtils.createBungeePlayer(event.getPlayer(), unifiedJedis, true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
<version>0.9.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.AbstractRedisBungeeListener;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask;
|
||||
@@ -36,6 +37,7 @@ import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
@@ -54,7 +56,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
super(plugin, exemptAddresses);
|
||||
}
|
||||
|
||||
@Subscribe (order = PostOrder.LAST)
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public void onLogin(LoginEvent event, Continuation continuation) {
|
||||
plugin.executeAsync(new RedisTask<Void>(plugin) {
|
||||
@Override
|
||||
@@ -63,23 +65,9 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
if (!event.getResult().isAllowed()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// We make sure they aren't trying to use an existing player's name.
|
||||
// This is problematic for online-mode servers as they always disconnect old clients.
|
||||
if (plugin.isOnlineMode()) {
|
||||
Player player = (Player) plugin.getPlayer(event.getPlayer().getUsername());
|
||||
|
||||
if (player != null) {
|
||||
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ONLINE_MODE_RECONNECT)));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : plugin.getProxiesIds()) {
|
||||
if (unifiedJedis.sismember("proxy:" + s + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
|
||||
event.setResult(ResultedEvent.ComponentResult.denied(serializer.deserialize(ALREADY_LOGGED_IN)));
|
||||
return null;
|
||||
}
|
||||
if (api.isPlayerOnline(event.getPlayer().getUniqueId())) {
|
||||
PlayerUtils.setKickedOtherLocation(event.getPlayer().getUniqueId().toString(), unifiedJedis);
|
||||
api.kickPlayer(event.getPlayer().getUniqueId(), plugin.getConfiguration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
@@ -97,7 +85,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
@Override
|
||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getUsername(), event.getPlayer().getUniqueId(), unifiedJedis);
|
||||
VelocityPlayerUtils.createPlayer(event.getPlayer(), unifiedJedis, true);
|
||||
VelocityPlayerUtils.createVelocityPlayer(event.getPlayer(), unifiedJedis, true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -146,7 +134,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
@Override
|
||||
@Subscribe
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
if(!(event.getSource() instanceof ServerConnection) || !RedisBungeeVelocityPlugin.IDENTIFIERS.contains(event.getIdentifier())) {
|
||||
if (!(event.getSource() instanceof ServerConnection) || !RedisBungeeVelocityPlugin.IDENTIFIERS.contains(event.getIdentifier())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -174,8 +162,8 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
}
|
||||
}
|
||||
Set<String> players = original.stream()
|
||||
.map(uuid -> plugin.getUuidTranslator().getNameFromUuid(uuid, false))
|
||||
.collect(Collectors.toSet());
|
||||
.map(uuid -> plugin.getUuidTranslator().getNameFromUuid(uuid, false))
|
||||
.collect(Collectors.toSet());
|
||||
out.writeUTF(Joiner.on(',').join(players));
|
||||
break;
|
||||
case "PlayerCount":
|
||||
@@ -246,7 +234,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
|
||||
((ServerConnection) event.getSource()).sendPluginMessage(event.getIdentifier(), out.toByteArray());
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +246,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
||||
if (message.startsWith("/"))
|
||||
message = message.substring(1);
|
||||
plugin.logInfo("Invoking command via PubSub: /" + message);
|
||||
((RedisBungeeVelocityPlugin)plugin).getProxy().getCommandManager().executeAsync(RedisBungeeCommandSource.getSingleton(), message);
|
||||
((RedisBungeeVelocityPlugin) plugin).getProxy().getCommandManager().executeAsync(RedisBungeeCommandSource.getSingleton(), message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
||||
Player playerProxied = getProxy().getPlayer(UUID.fromString(player)).orElse(null);
|
||||
if (playerProxied == null)
|
||||
return; // We'll deal with it later.
|
||||
VelocityPlayerUtils.createPlayer(playerProxied, unifiedJedis, false);
|
||||
VelocityPlayerUtils.createVelocityPlayer(playerProxied, unifiedJedis, false);
|
||||
}
|
||||
};
|
||||
integrityCheck = getProxy().getScheduler().buildTask(this, integrityCheckTask::execute).repeat(30, TimeUnit.SECONDS).schedule();
|
||||
|
||||
@@ -10,31 +10,22 @@
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import redis.clients.jedis.UnifiedJedis;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
||||
|
||||
public class VelocityPlayerUtils {
|
||||
protected static void createPlayer(Player player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
||||
Optional<ServerConnection> server = player.getCurrentServer();
|
||||
server.ifPresent(serverConnection -> unifiedJedis.hset("player:" + player.getUniqueId().toString(), "server", serverConnection.getServerInfo().getName()));
|
||||
|
||||
Map<String, String> playerData = new HashMap<>(4);
|
||||
playerData.put("online", "0");
|
||||
playerData.put("ip", player.getRemoteAddress().getHostName());
|
||||
playerData.put("proxy", AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId());
|
||||
|
||||
unifiedJedis.sadd("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", player.getUniqueId().toString());
|
||||
unifiedJedis.hmset("player:" + player.getUniqueId().toString(), playerData);
|
||||
|
||||
if (fireEvent) {
|
||||
playerJoinPayload(player.getUniqueId(), unifiedJedis, player.getRemoteAddress().getAddress());
|
||||
protected static void createVelocityPlayer(Player player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
||||
Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
|
||||
String serverName = null;
|
||||
if (optionalServerConnection.isPresent()) {
|
||||
serverName = optionalServerConnection.get().getServerInfo().getName();
|
||||
}
|
||||
PlayerUtils.createPlayer(player.getUniqueId(), unifiedJedis, serverName, player.getRemoteAddress().getAddress(), fireEvent);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user