Skip to content

Commit 1dd4f85

Browse files
committed
Proxy Protocol Support for Forge 1.19.4
1 parent b932ea7 commit 1dd4f85

File tree

10 files changed

+92
-90
lines changed

10 files changed

+92
-90
lines changed

build.gradle

Lines changed: 28 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
buildscript {
22
repositories {
3-
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below
43
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
54
mavenCentral()
65
}
@@ -10,59 +9,38 @@ buildscript {
109
}
1110

1211
plugins {
13-
id 'net.minecraftforge.gradle' version '5.1.+'
12+
id 'net.minecraftforge.gradle' version '5.+'
13+
id 'com.github.johnrengelman.shadow' version '7.+'
14+
id 'java'
1415
}
1516

1617
apply plugin: 'org.spongepowered.mixin'
1718

18-
jarJar.enable()
19-
2019
group = 'pl.panszelescik'
21-
version = '1.0.2-forge-1.19.2'
20+
version = '1.1.0-forge'
2221

2322
java {
2423
archivesBaseName = 'proxy_protocol_support'
2524
toolchain.languageVersion = JavaLanguageVersion.of(17)
2625
}
2726

27+
configurations {
28+
shade
29+
implementation.extendsFrom shade
30+
}
31+
2832
minecraft {
29-
// The mappings can be changed at any time and must be in the following format.
30-
// Channel: Version:
31-
// official MCVersion Official field/method names from Mojang mapping files
32-
// parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official
33-
//
34-
// You must be aware of the Mojang license when using the 'official' or 'parchment' mappings.
35-
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
36-
//
37-
// Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge
38-
// Additional setup is needed to use their mappings: https://github.com/ParchmentMC/Parchment/wiki/Getting-Started
39-
//
40-
// Use non-default mappings at your own risk. They may not always work.
41-
// Simply re-run your setup task after changing the mappings to update your workspace.
42-
mappings channel: 'official', version: '1.19.2'
43-
44-
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
45-
46-
// Default run configurations.
47-
// These can be tweaked, removed, or duplicated as needed.
33+
mappings channel: 'official', version: '1.19.4'
34+
4835
runs {
4936
client {
5037
workingDirectory project.file('run')
5138

52-
// Recommended logging data for a userdev environment
53-
// The markers can be added/remove as needed separated by commas.
54-
// "SCAN": For mods scan.
55-
// "REGISTRIES": For firing of registry events.
56-
// "REGISTRYDUMP": For getting the contents of all registries.
5739
property 'forge.logging.markers', 'REGISTRIES'
5840

5941

60-
// Recommended logging level for the console
61-
// You can set various levels here.
62-
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
6342
property 'forge.logging.console.level', 'debug'
6443

65-
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
6644
property 'forge.enabledGameTestNamespaces', 'proxy_protocol_support'
6745

6846
mods {
@@ -88,9 +66,6 @@ minecraft {
8866
}
8967
}
9068

91-
// This run config launches GameTestServer and runs all registered gametests, then exits.
92-
// By default, the server will crash when no gametests are provided.
93-
// The gametest system is also enabled by default for other run configs under the /test command.
9469
gameTestServer {
9570
workingDirectory project.file('run')
9671

@@ -114,7 +89,6 @@ minecraft {
11489

11590
property 'forge.logging.console.level', 'debug'
11691

117-
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
11892
args '--mod', 'proxy_protocol_support', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
11993

12094
mods {
@@ -132,49 +106,24 @@ mixin {
132106
config "proxy_protocol_support.mixins.json"
133107
}
134108

135-
// Include resources generated by data generators.
136109
sourceSets.main.resources { srcDir 'src/generated/resources' }
137110

138111
repositories {
139-
// Put repositories for dependencies here
140-
// ForgeGradle automatically adds the Forge maven and Maven Central for you
141-
142-
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
143-
// flatDir {
144-
// dir 'libs'
145-
// }
146112
}
147113

148114
dependencies {
149-
// Specify the version of Minecraft to use. If this is any group other than 'net.minecraft' it is assumed
150-
// that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
151-
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
152-
minecraft 'net.minecraftforge:forge:1.19.2-43.0.15'
153-
154-
// Real mod deobf dependency examples - these get remapped to your current mappings
155-
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
156-
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
157-
// implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency
158-
159-
// Examples using mod jars from ./libs
160-
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
161-
162-
// For more info...
163-
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
164-
// http://www.gradle.org/docs/current/userguide/dependency_management.html
165-
166-
// https://mvnrepository.com/artifact/io.netty/netty-codec-haproxy
167-
implementation group: 'io.netty', name: 'netty-codec-haproxy', version: '4.1.79.Final'
168-
jarJar(group: 'io.netty', name: 'netty-codec-haproxy', version: '[4.1.79.Final]') {
169-
jarJar.pin(it, '4.1.79.Final')
170-
transitive = false
115+
minecraft 'net.minecraftforge:forge:1.19.4-45.0.47'
116+
117+
implementation('io.netty:netty-codec-haproxy:4.1.91.Final')
118+
shade('io.netty:netty-codec-haproxy:4.1.91.Final') {
119+
exclude group: '*', module: '*'
171120
}
172121

173122
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
174123
}
175124

176-
// Example for how to get properties into the manifest for reading at runtime.
177125
jar {
126+
archiveClassifier = 'slim'
178127
manifest {
179128
attributes([
180129
"Specification-Title" : "proxy_protocol_support",
@@ -188,12 +137,20 @@ jar {
188137
}
189138
}
190139

191-
jar.finalizedBy('reobfJar')
140+
shadowJar {
141+
archiveClassifier = ''
142+
configurations = [project.configurations.shade]
143+
finalizedBy 'reobfShadowJar'
144+
}
145+
146+
assemble.dependsOn shadowJar
192147

193-
build {
194-
dependsOn 'jarJar'
148+
reobf {
149+
shadowJar {}
195150
}
196151

152+
jar.finalizedBy('reobfJar')
153+
197154
tasks.withType(JavaCompile).configureEach {
198155
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
199156
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public static void initialize(Config config) throws IOException {
4545

4646
if (config.whitelistTCPShieldServers) {
4747
ProxyProtocolSupport.infoLogger.accept("TCPShield integration enabled!");
48-
whitelistedIPs = Stream
48+
whitelistedIPs.addAll(Stream
4949
.concat(whitelistedIPs.stream(), TCPShieldIntegration.getWhitelistedIPs().stream())
50-
.collect(Collectors.toSet());
50+
.collect(Collectors.toSet()));
5151
}
5252

5353
ProxyProtocolSupport.infoLogger.accept("Using " + ProxyProtocolSupport.whitelistedIPs.size() + " whitelisted IPs: " + ProxyProtocolSupport.whitelistedIPs);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package pl.panszelescik.proxy_protocol_support.shared.impl;
2+
3+
import io.netty.channel.Channel;
4+
5+
public interface IChannelInitializer {
6+
7+
void invokeInitChannel(Channel ch) throws Exception;
8+
}

src/main/java/pl/panszelescik/proxy_protocol_support/shared/ProxyProtocolChannelInitializer.java renamed to src/main/java/pl/panszelescik/proxy_protocol_support/shared/impl/ProxyProtocolChannelInitializer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
package pl.panszelescik.proxy_protocol_support.shared;
1+
package pl.panszelescik.proxy_protocol_support.shared.impl;
22

33
import io.netty.channel.Channel;
44
import io.netty.channel.ChannelInitializer;
55
import io.netty.handler.codec.haproxy.HAProxyMessageDecoder;
6-
import pl.panszelescik.proxy_protocol_support.shared.mixin.ChannelInitializerInvoker;
6+
import pl.panszelescik.proxy_protocol_support.shared.ProxyProtocolSupport;
77

88
/**
99
* Initializes HAProxyMessageDecoder and ProxyProtocolHandler
1010
*
1111
* @author PanSzelescik
1212
* @see io.netty.handler.codec.haproxy.HAProxyMessageDecoder
13-
* @see pl.panszelescik.proxy_protocol_support.shared.ProxyProtocolHandler
13+
* @see ProxyProtocolHandler
1414
*/
1515
public class ProxyProtocolChannelInitializer extends ChannelInitializer {
1616

17-
private final ChannelInitializerInvoker channelInitializer;
17+
private final IChannelInitializer channelInitializer;
1818

19-
public ProxyProtocolChannelInitializer(ChannelInitializerInvoker invoker) {
20-
this.channelInitializer = invoker;
19+
public ProxyProtocolChannelInitializer(IChannelInitializer channelInitializer) {
20+
this.channelInitializer = channelInitializer;
2121
}
2222

2323
@Override
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package pl.panszelescik.proxy_protocol_support.shared.impl;
2+
3+
import io.netty.channel.Channel;
4+
import io.netty.channel.ChannelHandler;
5+
6+
import java.lang.reflect.Method;
7+
8+
public class ProxyProtocolFallbackInitializerInvoker implements IChannelInitializer {
9+
10+
public final ChannelHandler childHandler;
11+
public final Method method;
12+
13+
public ProxyProtocolFallbackInitializerInvoker(ChannelHandler childHandler) {
14+
this.childHandler = childHandler;
15+
16+
try {
17+
this.method = childHandler.getClass().getDeclaredMethod("initChannel", Channel.class);
18+
this.method.setAccessible(true);
19+
} catch (Throwable t) {
20+
throw new RuntimeException(t);
21+
}
22+
}
23+
24+
@Override
25+
public void invokeInitChannel(Channel channel) throws Exception {
26+
this.method.invoke(this.childHandler, channel);
27+
}
28+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package pl.panszelescik.proxy_protocol_support.shared;
1+
package pl.panszelescik.proxy_protocol_support.shared.impl;
22

33
import io.netty.channel.ChannelHandlerContext;
44
import io.netty.channel.ChannelInboundHandlerAdapter;
55
import io.netty.handler.codec.haproxy.HAProxyCommand;
66
import io.netty.handler.codec.haproxy.HAProxyMessage;
77
import net.minecraft.network.Connection;
8+
import pl.panszelescik.proxy_protocol_support.shared.ProxyProtocolSupport;
89
import pl.panszelescik.proxy_protocol_support.shared.config.CIDRMatcher;
910
import pl.panszelescik.proxy_protocol_support.shared.mixin.ProxyProtocolAddressSetter;
1011

src/main/java/pl/panszelescik/proxy_protocol_support/shared/mixin/ChannelInitializerInvoker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.netty.channel.ChannelInitializer;
55
import org.spongepowered.asm.mixin.Mixin;
66
import org.spongepowered.asm.mixin.gen.Invoker;
7+
import pl.panszelescik.proxy_protocol_support.shared.impl.IChannelInitializer;
78

89
/**
910
* Adds Invoker for initChannel
@@ -12,7 +13,7 @@
1213
* @see io.netty.channel.ChannelInitializer#initChannel(Channel)
1314
*/
1415
@Mixin(ChannelInitializer.class)
15-
public interface ChannelInitializerInvoker {
16+
public interface ChannelInitializerInvoker extends IChannelInitializer {
1617

1718
@Invoker(value = "initChannel", remap = false)
1819
void invokeInitChannel(Channel ch) throws Exception;

src/main/java/pl/panszelescik/proxy_protocol_support/shared/mixin/ProxyProtocolImplementation.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.injection.At;
88
import org.spongepowered.asm.mixin.injection.Redirect;
9-
import pl.panszelescik.proxy_protocol_support.shared.ProxyProtocolChannelInitializer;
9+
import pl.panszelescik.proxy_protocol_support.shared.impl.IChannelInitializer;
10+
import pl.panszelescik.proxy_protocol_support.shared.impl.ProxyProtocolChannelInitializer;
11+
import pl.panszelescik.proxy_protocol_support.shared.impl.ProxyProtocolFallbackInitializerInvoker;
1012

1113
/**
1214
* Replaces anonymous ChannelInitializer with ProxyProtocolChannelInitializer
1315
*
1416
* @author PanSzelescik
15-
* @see pl.panszelescik.proxy_protocol_support.shared.ProxyProtocolChannelInitializer
17+
* @see ProxyProtocolChannelInitializer
1618
*/
1719
@Mixin(ServerConnectionListener.class)
1820
public class ProxyProtocolImplementation {
1921

20-
// TODO: Mixin into anonymous class?
2122
@Redirect(method = "startTcpServerListener", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/ServerBootstrap;childHandler(Lio/netty/channel/ChannelHandler;)Lio/netty/bootstrap/ServerBootstrap;", remap = false))
2223
private ServerBootstrap addProxyProtocolSupport(ServerBootstrap bootstrap, ChannelHandler childHandler) {
23-
return bootstrap.childHandler(new ProxyProtocolChannelInitializer(((ChannelInitializerInvoker) childHandler)));
24+
IChannelInitializer channelInitializer;
25+
if (childHandler instanceof IChannelInitializer) {
26+
channelInitializer = (IChannelInitializer) childHandler;
27+
} else {
28+
channelInitializer = new ProxyProtocolFallbackInitializerInvoker(childHandler);
29+
}
30+
return bootstrap.childHandler(new ProxyProtocolChannelInitializer(channelInitializer));
2431
}
2532
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
modLoader = "javafml"
2-
loaderVersion = "[43,)"
2+
loaderVersion = "[24,)"
33
license="All Rights Reserved"
44
issueTrackerURL="https://github.com/PanSzelescik/proxy-protocol-support/issues"
55
[[mods]]
@@ -10,11 +10,11 @@ displayURL="https://www.curseforge.com/minecraft/mc-mods/proxy-protocol-support"
1010
authors="PanSzelescik"
1111
displayTest="IGNORE_ALL_VERSION"
1212
description='''
13-
Proxy Protocol support for Forge 1.19.2 servers
13+
Proxy Protocol support for Forge servers
1414
'''
1515
[[dependencies.proxy_protocol_support]]
1616
modId = "minecraft"
1717
mandatory = true
18-
versionRange = "[1.19,1.20)"
18+
versionRange = "[1.13,)"
1919
ordering = "NONE"
20-
side = "BOTH"
20+
side = "BOTH"

src/main/resources/proxy_protocol_support.mixins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"required": true,
33
"minVersion": "0.8",
44
"package": "pl.panszelescik.proxy_protocol_support.shared.mixin",
5-
"compatibilityLevel": "JAVA_17",
5+
"compatibilityLevel": "JAVA_8",
66
"server": [
77
"ChannelInitializerInvoker",
88
"ProxyProtocolAddressSetter",

0 commit comments

Comments
 (0)