Skip to content

Commit 12e58cd

Browse files
committed
Support only 1.19+ due to errors
1 parent 1dd4f85 commit 12e58cd

File tree

4 files changed

+49
-34
lines changed

4 files changed

+49
-34
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ repositories {
112112
}
113113

114114
dependencies {
115-
minecraft 'net.minecraftforge:forge:1.19.4-45.0.47'
115+
minecraft 'net.minecraftforge:forge:1.19.4-45.0.49'
116116

117117
implementation('io.netty:netty-codec-haproxy:4.1.91.Final')
118118
shade('io.netty:netty-codec-haproxy:4.1.91.Final') {

src/main/java/pl/panszelescik/proxy_protocol_support/shared/ProxyProtocolSupport.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.util.ArrayList;
99
import java.util.Collection;
10+
import java.util.function.BiConsumer;
1011
import java.util.function.Consumer;
1112
import java.util.stream.Collectors;
1213
import java.util.stream.Stream;
@@ -23,6 +24,10 @@ public class ProxyProtocolSupport {
2324
public static Consumer<String> infoLogger = System.out::println;
2425
public static Consumer<String> warnLogger = System.out::println;
2526
public static Consumer<String> errorLogger = System.out::println;
27+
public static BiConsumer<String, Exception> exceptionLogger = (s, e) -> {
28+
errorLogger.accept(s);
29+
e.printStackTrace();
30+
};
2631

2732
public static boolean enableProxyProtocol = false;
2833
public static Collection<CIDRMatcher> whitelistedIPs = new ArrayList<>();
@@ -59,16 +64,22 @@ private static void loggerInitialize() {
5964
infoLogger = slf4j::info;
6065
warnLogger = slf4j::warn;
6166
errorLogger = slf4j::error;
67+
exceptionLogger = slf4j::error;
6268
} catch (Throwable ignored) {
6369
try {
6470
org.apache.logging.log4j.Logger log4j = org.apache.logging.log4j.LogManager.getLogger(MODID);
6571
infoLogger = log4j::info;
6672
warnLogger = log4j::warn;
6773
errorLogger = log4j::error;
74+
exceptionLogger = log4j::error;
6875
} catch (Throwable ignored2) {
6976
infoLogger = System.out::println;
7077
warnLogger = System.out::println;
7178
errorLogger = System.out::println;
79+
exceptionLogger = (s, e) -> {
80+
errorLogger.accept(s);
81+
e.printStackTrace();
82+
};
7283
}
7384
}
7485
}

src/main/java/pl/panszelescik/proxy_protocol_support/shared/impl/ProxyProtocolHandler.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,51 @@ public class ProxyProtocolHandler extends ChannelInboundHandlerAdapter {
2323
@Override
2424
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
2525
if (msg instanceof HAProxyMessage) {
26-
HAProxyMessage message = ((HAProxyMessage) msg);
27-
if (message.command() == HAProxyCommand.PROXY) {
28-
final String realAddress = message.sourceAddress();
29-
final int realPort = message.sourcePort();
26+
try {
27+
HAProxyMessage message = ((HAProxyMessage) msg);
28+
if (message.command() == HAProxyCommand.PROXY) {
29+
final String realAddress = message.sourceAddress();
30+
final int realPort = message.sourcePort();
3031

31-
final InetSocketAddress socketAddr = new InetSocketAddress(realAddress, realPort);
32+
final InetSocketAddress socketAddr = new InetSocketAddress(realAddress, realPort);
3233

33-
Connection connection = ((Connection) ctx.channel().pipeline().get("packet_handler"));
34-
SocketAddress proxyAddress = connection.getRemoteAddress();
34+
Connection connection = ((Connection) ctx.channel().pipeline().get("packet_handler"));
35+
SocketAddress proxyAddress = connection.getRemoteAddress();
3536

36-
if (!ProxyProtocolSupport.whitelistedIPs.isEmpty()) {
37-
if (proxyAddress instanceof InetSocketAddress) {
38-
InetSocketAddress proxySocketAddress = ((InetSocketAddress) proxyAddress);
39-
boolean isWhitelistedIP = false;
37+
if (!ProxyProtocolSupport.whitelistedIPs.isEmpty()) {
38+
if (proxyAddress instanceof InetSocketAddress) {
39+
InetSocketAddress proxySocketAddress = ((InetSocketAddress) proxyAddress);
40+
boolean isWhitelistedIP = false;
4041

41-
for (CIDRMatcher matcher : ProxyProtocolSupport.whitelistedIPs) {
42-
if (matcher.matches(proxySocketAddress.getAddress())) {
43-
isWhitelistedIP = true;
44-
break;
42+
for (CIDRMatcher matcher : ProxyProtocolSupport.whitelistedIPs) {
43+
if (matcher.matches(proxySocketAddress.getAddress())) {
44+
isWhitelistedIP = true;
45+
break;
46+
}
4547
}
46-
}
4748

48-
if (!isWhitelistedIP) {
49-
if (ctx.channel().isOpen()) {
50-
ctx.disconnect();
51-
ProxyProtocolSupport.warnLogger.accept("Blocked proxy IP: " + proxySocketAddress + " when tried to connect!");
49+
if (!isWhitelistedIP) {
50+
if (ctx.channel().isOpen()) {
51+
ctx.disconnect();
52+
ProxyProtocolSupport.warnLogger.accept("Blocked proxy IP: " + proxySocketAddress + " when tried to connect!");
53+
}
54+
return;
5255
}
53-
return;
56+
} else {
57+
ProxyProtocolSupport.warnLogger.accept("**********************************************************************");
58+
ProxyProtocolSupport.warnLogger.accept("* Detected other SocketAddress than InetSocketAddress! *");
59+
ProxyProtocolSupport.warnLogger.accept("* Please report it with logs to mod author to provide compatibility! *");
60+
ProxyProtocolSupport.warnLogger.accept("* https://github.com/PanSzelescik/proxy-protocol-support/issues *");
61+
ProxyProtocolSupport.warnLogger.accept("**********************************************************************");
62+
ProxyProtocolSupport.warnLogger.accept(proxyAddress.getClass().toString());
63+
ProxyProtocolSupport.warnLogger.accept(proxyAddress.toString());
5464
}
55-
} else {
56-
ProxyProtocolSupport.warnLogger.accept("**********************************************************************");
57-
ProxyProtocolSupport.warnLogger.accept("* Detected other SocketAddress than InetSocketAddress! *");
58-
ProxyProtocolSupport.warnLogger.accept("* Please report it with logs to mod author to provide compatibility! *");
59-
ProxyProtocolSupport.warnLogger.accept("* https://github.com/PanSzelescik/proxy-protocol-support/issues *");
60-
ProxyProtocolSupport.warnLogger.accept("**********************************************************************");
61-
ProxyProtocolSupport.warnLogger.accept(proxyAddress.getClass().toString());
62-
ProxyProtocolSupport.warnLogger.accept(proxyAddress.toString());
6365
}
64-
}
6566

66-
((ProxyProtocolAddressSetter) connection).setAddress(socketAddr);
67+
((ProxyProtocolAddressSetter) connection).setAddress(socketAddr);
68+
}
69+
} catch (Exception e) {
70+
ProxyProtocolSupport.exceptionLogger.accept("Error while handling HAProxyMessage!", e);
6771
}
6872
} else {
6973
super.channelRead(ctx, msg);

src/main/resources/META-INF/mods.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
modLoader = "javafml"
2-
loaderVersion = "[24,)"
2+
loaderVersion = "[41,)"
33
license="All Rights Reserved"
44
issueTrackerURL="https://github.com/PanSzelescik/proxy-protocol-support/issues"
55
[[mods]]
@@ -15,6 +15,6 @@ Proxy Protocol support for Forge servers
1515
[[dependencies.proxy_protocol_support]]
1616
modId = "minecraft"
1717
mandatory = true
18-
versionRange = "[1.13,)"
18+
versionRange = "[1.19,)"
1919
ordering = "NONE"
2020
side = "BOTH"

0 commit comments

Comments
 (0)