Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LXGaming committed Jul 20, 2017
1 parent 2071ad7 commit 065e611
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sourceCompatibility = 1.8

group = "nz.co.lolnet.bungeeproxy"
archivesBaseName = "BungeeProxy"
version = "1.0.0"
version = "1.0.1"

configurations {
provided {
Expand Down Expand Up @@ -42,7 +42,7 @@ repositories {
dependencies {
provided("io.netty:netty-all:4.1.9.Final")
compile("io.netty:netty-codec-haproxy:4.1.9.Final")
provided("net.md-5:bungeecord-api:1.12-SNAPSHOT")
provided("net.md-5:bungeecord-api:1.11-SNAPSHOT")
}

jar {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/nz/co/lolnet/bungeeproxy/BungeeProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import io.netty.channel.AbstractChannel;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import net.md_5.bungee.api.plugin.Plugin;
Expand All @@ -16,6 +17,7 @@ public class BungeeProxy extends Plugin {

private static BungeeProxy instance;
private Config config;
private Field remoteAddress;

@Override
public void onEnable() {
Expand All @@ -38,6 +40,9 @@ public void onEnable() {
initChannelMethod.setAccessible(true);

serverChildField.set(null, new ChannelHandler(bungeeChannelInitializer, initChannelMethod));

remoteAddress = AbstractChannel.class.getDeclaredField("remoteAddress");
getRemoteAddress().setAccessible(true);
getLogger().info(Reference.PLUGIN_NAME + " Enabled.");
} catch (Exception ex) {
BungeeProxy.getInstance().getLogger().severe("Encountered an error processing 'onEnable' in '" + getClass().getSimpleName() + "' - " + ex.getMessage());
Expand Down Expand Up @@ -68,6 +73,11 @@ public Configuration getConfiguration() {
if (getConfig() != null) {
return getConfig().getConfiguration();
}

return null;
}

public Field getRemoteAddress() {
return remoteAddress;
}
}
25 changes: 3 additions & 22 deletions src/main/java/nz/co/lolnet/bungeeproxy/handlers/ProxyHandler.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package nz.co.lolnet.bungeeproxy.handlers;

import java.lang.reflect.Field;
import java.net.InetSocketAddress;

import io.netty.buffer.Unpooled;
import io.netty.channel.AbstractChannel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
Expand All @@ -13,26 +11,12 @@

public class ProxyHandler extends ChannelInboundHandlerAdapter {

private Field remoteAddress;

@Override
public void channelActive(ChannelHandlerContext ctx) {
try {
remoteAddress = AbstractChannel.class.getDeclaredField("remoteAddress");
getRemoteAddress().setAccessible(true);
super.channelActive(ctx);
} catch (Exception ex) {
BungeeProxy.getInstance().getLogger().severe("Encountered an error processing 'channelActive' in '" + getClass().getSimpleName() + "' - " + ex.getMessage());
ex.printStackTrace();
}
}

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
try {
if (msg instanceof HAProxyMessage && getRemoteAddress() != null) {
if (msg instanceof HAProxyMessage && BungeeProxy.getInstance().getRemoteAddress() != null) {
HAProxyMessage proxyMessage = (HAProxyMessage) msg;
getRemoteAddress().set(ctx.channel(), new InetSocketAddress(proxyMessage.sourceAddress(), proxyMessage.sourcePort()));
BungeeProxy.getInstance().getRemoteAddress().set(ctx.channel(), new InetSocketAddress(proxyMessage.sourceAddress(), proxyMessage.sourcePort()));
BungeeProxy.getInstance().debugMessage("Successfully processed HAProxyMessage.");
return;
}
Expand All @@ -51,9 +35,6 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable throwable) {
}

BungeeProxy.getInstance().getLogger().severe("Exception caught in '" + getClass().getSimpleName() + "' - " + throwable.getMessage());
}

private Field getRemoteAddress() {
return remoteAddress;
throwable.printStackTrace();
}
}
2 changes: 1 addition & 1 deletion src/main/java/nz/co/lolnet/bungeeproxy/util/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Reference {

public static final String PLUGIN_ID = "bungeeproxy";
public static final String PLUGIN_NAME = "BungeeProxy";
public static final String PLUGIN_VERSION = "1.0.0";
public static final String PLUGIN_VERSION = "1.0.1";

public static final String DECODER_NAME = PLUGIN_ID + "_decoder";
public static final String HANDLER_NAME = PLUGIN_ID + "_handler";
Expand Down

0 comments on commit 065e611

Please sign in to comment.