Better handling of the timers (moved to the handler, get it via the context and default timer for auth packet)

This commit is contained in:
ProfMobius committed 2014-11-12 19:40:35 +01:00
1 parent c7ce4801c3
commit 809f4abff0
3 files changed
+10 -8

No files matched your search

@@ -32,7 +32,6 @@ public class RConHandler {
public static BiMap<Byte, Class> packetTypes = HashBiMap.create();
public static BiMap<FakePlayer, ChannelHandlerContext> fakePlayersRcon = HashBiMap.create();
public static BiMap<FakePlayer, ChannelHandlerContext> fakePlayersNexus = HashBiMap.create();
public static BiMap<FakePlayer, EventTimerRing> timersNexus = HashBiMap.create();
public static String lastError = null;
public static WeakReference<ChannelHandlerContext> lastContext = null;
@@ -59,13 +58,11 @@ public class RConHandler {
public static void sendToPlayerNexus(PacketBase packet, FakePlayer player)
{
ChannelHandlerContext ctx = RConHandler.fakePlayersNexus.get(player);
NexusInboundHandler hnd = ctx.pipeline().get(NexusInboundHandler.class);
try{
if (RConHandler.timersNexus.get(player).isDone(packet.msg))
sendToContext(packet, ctx);
} catch (Exception e){
if (hnd.timers.isDone(packet.msg))
sendToContext(packet, ctx);
}
}
public static void sendToPlayerRCon(PacketBase packet, FakePlayer player)
@@ -15,6 +15,10 @@ public class EventTimerRing {
Map<Message, EventTimer> ring = new HashMap<Message, EventTimer>();
Properties prop;
public EventTimerRing(){
ring.put(Message.NEXUS_UUID, new EventTimer(0));
}
public EventTimerRing(String config){
this.prop = readConfig(config);
@@ -36,6 +36,8 @@ import io.nettyopis.util.ReferenceCountUtil;
public class NexusInboundHandler extends ChannelInboundHandlerAdapter {
public EventTimerRing timers = new EventTimerRing();
@Override
public void handlerAdded(final ChannelHandlerContext ctx) {
NexusClient.instance.ctx = new WeakReference<ChannelHandlerContext>(ctx);
@@ -66,8 +68,7 @@ public class NexusInboundHandler extends ChannelInboundHandlerAdapter {
modOpis.log.error(String.format("Connection refused. Wrong uuid or pass."));
NexusClient.instance.shouldRetry = false;
} else if (status == 1){
Properties prop = ((ConnectionProperties)pck.param2).prop;
RConHandler.timersNexus.put(fakePlayer, new EventTimerRing(prop));
this.timers = new EventTimerRing(((ConnectionProperties)pck.param2).prop);
}