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

Removed pipelining and other fixes.

This commit is contained in:
Tux 2014-09-11 16:38:40 -04:00
parent 75939ef661
commit bafe894298
5 changed files with 25 additions and 38 deletions

View File

@ -335,11 +335,8 @@ public final class RedisBungee extends Plugin {
tmpRsc.hdel("heartbeats", serverId);
if (tmpRsc.scard("proxy:" + serverId + ":usersOnline") > 0) {
Set<String> players = tmpRsc.smembers("proxy:" + serverId + ":usersOnline");
Pipeline pipeline = tmpRsc.pipelined();
for (String member : players)
RedisUtil.cleanUpPlayer(member, pipeline);
pipeline.sync();
RedisUtil.cleanUpPlayer(member, tmpRsc);
}
} finally {
pool.returnResource(tmpRsc);

View File

@ -47,34 +47,31 @@ public class RedisBungeeConsumer implements Runnable {
private void handle(ConsumerEvent event, Jedis jedis) {
if (event instanceof PlayerLoggedInConsumerEvent) {
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
Pipeline pipeline = jedis.pipelined();
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
plugin.getUuidTranslator().persistInfo(event1.getPlayer().getName(), event1.getPlayer().getUniqueId(), pipeline);
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "proxy", plugin.getServerId());
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
jedis.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
plugin.getUuidTranslator().persistInfo(event1.getPlayer().getName(), event1.getPlayer().getUniqueId(), jedis);
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "proxy", plugin.getServerId());
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(event1.getPlayer().getAddress().getAddress()))));
pipeline.sync();
jedis.sync();
} else if (event instanceof PlayerLoggedOffConsumerEvent) {
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
Pipeline pipeline = jedis.pipelined();
long timestamp = System.currentTimeMillis();
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", String.valueOf(timestamp));
RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), pipeline);
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", String.valueOf(timestamp));
RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), jedis);
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp))));
pipeline.sync();
jedis.sync();
} else if (event instanceof PlayerChangedServerConsumerEvent) {
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
Pipeline pipeline = jedis.pipelined();
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
new DataManager.ServerChangePayload(event1.getNewServer().getName()))));
pipeline.sync();
jedis.sync();
}
}

View File

@ -17,6 +17,7 @@ import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.*;
@ -30,6 +31,11 @@ import java.util.*;
@AllArgsConstructor
public class RedisBungeeListener implements Listener {
private final RedisBungee plugin;
private static final BaseComponent[] ALREADY_LOGGED_IN =
new ComponentBuilder("You are already logged on to this server.").color(ChatColor.RED)
.append("\n\nIf you were disconnected forcefully, please wait up to one minute.\nIf this does not resolve your issue, please contact staff.")
.color(ChatColor.GRAY)
.create();
@EventHandler
public void onPlayerConnect(final PostLoginEvent event) {
@ -37,15 +43,15 @@ public class RedisBungeeListener implements Listener {
try {
for (String server : plugin.getServerIds()) {
if (rsc.sismember("proxy:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color(
ChatColor.RED).create());
event.getPlayer().disconnect(ALREADY_LOGGED_IN);
return;
}
}
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
} finally {
plugin.getPool().returnResource(rsc);
}
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
}
@EventHandler

View File

@ -7,16 +7,9 @@
package com.imaginarycode.minecraft.redisbungee;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
class RedisUtil {
public static void cleanUpPlayer(String player, Jedis rsc) {
Pipeline pipeline = rsc.pipelined();
cleanUpPlayer(player, pipeline);
pipeline.sync();
}
public static void cleanUpPlayer(String player, Pipeline rsc) {
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
rsc.hdel("player:" + player, "server");
rsc.hdel("player:" + player, "ip");

View File

@ -181,13 +181,7 @@ public final class UUIDTranslator {
}
}
protected final void persistInfo(String name, UUID uuid, Jedis jedis) {
addToMaps(name, uuid);
jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
}
public final void persistInfo(String name, UUID uuid, Pipeline jedis) {
public final void persistInfo(String name, UUID uuid, Jedis jedis) {
addToMaps(name, uuid);
jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));