├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── .gitignore ├── src └── main │ ├── resources │ ├── velocity.mixins.json │ ├── common.mixins.json │ ├── bungee.mixins.json │ └── fabric.mod.json │ └── java │ └── one │ └── oktw │ ├── interfaces │ └── BungeeClientConnection.java │ ├── mixin │ ├── bungee │ │ ├── HandshakeC2SPacketAccessor.java │ │ ├── HandshakeC2SPacketMixin.java │ │ ├── ClientConnectionMixin.java │ │ ├── ServerLoginNetworkHandlerMixin.java │ │ └── ServerHandshakeNetworkHandlerMixin.java │ ├── ClientConnectionAccessor.java │ ├── UserCacheMixin.java │ ├── ServerConfigHandlerMixin.java │ └── velocity │ │ └── ServerLoginNetworkHandlerMixin.java │ ├── ModConfig.java │ ├── VelocityLib.java │ └── FabricProxy.java ├── gradle.properties ├── README.md ├── .github ├── workflows │ └── workflow.yml └── ISSUE_TEMPLATE │ └── bug_report.md ├── .circleci └── config.yml ├── LICENSE ├── gradlew.bat └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OKTW-Network/FabricProxy/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenCentral() 4 | maven { 5 | name = 'Fabric' 6 | url = 'https://maven.fabricmc.net/' 7 | } 8 | gradlePluginPortal() 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | classes/ 7 | 8 | # idea 9 | 10 | .idea/ 11 | *.iml 12 | *.ipr 13 | *.iws 14 | 15 | # vscode 16 | 17 | .settings/ 18 | .vscode/ 19 | bin/ 20 | .classpath 21 | .project 22 | 23 | # fabric 24 | 25 | run/ -------------------------------------------------------------------------------- /src/main/resources/velocity.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "one.oktw.mixin.velocity", 4 | "compatibilityLevel": "JAVA_16", 5 | "plugin": "one.oktw.FabricProxy", 6 | "mixins": [ 7 | "ServerLoginNetworkHandlerMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/common.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "one.oktw.mixin", 4 | "compatibilityLevel": "JAVA_16", 5 | "mixins": [ 6 | "ClientConnectionAccessor", 7 | "ServerConfigHandlerMixin", 8 | "UserCacheMixin" 9 | ], 10 | "injectors": { 11 | "defaultRequire": 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs=-Xmx1G 3 | # Fabric Properties 4 | # check these on https://modmuss50.me/fabric.html 5 | minecraft_version=1.18 6 | yarn_mappings=1.18+build.1 7 | loader_version=0.12.6 8 | # Mod Properties 9 | mod_version=1.4.10 10 | maven_group=one.oktw 11 | archives_base_name=FabricProxy 12 | # Dependencies 13 | fabric_version=0.43.1+1.18 14 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/interfaces/BungeeClientConnection.java: -------------------------------------------------------------------------------- 1 | package one.oktw.interfaces; 2 | 3 | import com.mojang.authlib.properties.Property; 4 | 5 | import java.util.UUID; 6 | 7 | public interface BungeeClientConnection { 8 | UUID getSpoofedUUID(); 9 | 10 | void setSpoofedUUID(UUID uuid); 11 | 12 | Property[] getSpoofedProfile(); 13 | 14 | void setSpoofedProfile(Property[] profile); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/bungee/HandshakeC2SPacketAccessor.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin.bungee; 2 | 3 | import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | @Mixin(HandshakeC2SPacket.class) 8 | public interface HandshakeC2SPacketAccessor { 9 | @Accessor 10 | String getAddress(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/ClientConnectionAccessor.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin; 2 | 3 | import net.minecraft.network.ClientConnection; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.gen.Accessor; 6 | 7 | import java.net.SocketAddress; 8 | 9 | @Mixin(ClientConnection.class) 10 | public interface ClientConnectionAccessor { 11 | @Accessor 12 | void setAddress(SocketAddress address); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/bungee.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "one.oktw.mixin.bungee", 4 | "compatibilityLevel": "JAVA_16", 5 | "plugin": "one.oktw.FabricProxy", 6 | "mixins": [ 7 | "ClientConnectionMixin", 8 | "HandshakeC2SPacketAccessor", 9 | "HandshakeC2SPacketMixin", 10 | "ServerHandshakeNetworkHandlerMixin", 11 | "ServerLoginNetworkHandlerMixin" 12 | ], 13 | "injectors": { 14 | "defaultRequire": 1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "fabricproxy", 4 | "version": "${version}", 5 | "name": "FabricProxy", 6 | "description": "Support forward player data from proxy", 7 | "authors": [ 8 | "james58899" 9 | ], 10 | "contact": { 11 | "homepage": "https://github.com/OKTW-Network/FabricProxy", 12 | "sources": "https://github.com/OKTW-Network/FabricProxy" 13 | }, 14 | "license": "MIT", 15 | "environment": "*", 16 | "entrypoints": { 17 | "main": [] 18 | }, 19 | "mixins": [ 20 | "common.mixins.json", 21 | "bungee.mixins.json", 22 | "velocity.mixins.json" 23 | ], 24 | "depends": { 25 | "fabricloader": ">=0.11.3", 26 | "fabric": "*" 27 | }, 28 | "suggests": {} 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/bungee/HandshakeC2SPacketMixin.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin.bungee; 2 | 3 | import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket; 4 | import one.oktw.FabricProxy; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.injection.Constant; 7 | import org.spongepowered.asm.mixin.injection.ModifyConstant; 8 | 9 | @Mixin(HandshakeC2SPacket.class) 10 | public abstract class HandshakeC2SPacketMixin { 11 | @ModifyConstant(method = "(Lnet/minecraft/network/PacketByteBuf;)V", constant = @Constant(intValue = 255)) 12 | private int readStringSize(int i) { 13 | if (FabricProxy.config.getBungeeCord()) { 14 | return Short.MAX_VALUE; 15 | } 16 | 17 | return i; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/UserCacheMixin.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin; 2 | 3 | import net.minecraft.util.UserCache; 4 | import one.oktw.FabricProxy; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Redirect; 9 | 10 | @Mixin(UserCache.class) 11 | public class UserCacheMixin { 12 | @Shadow private static boolean useRemote; 13 | 14 | @Redirect(method = "findProfileByName", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/UserCache;shouldUseRemote()Z")) 15 | private static boolean findProfileByName() { 16 | if (FabricProxy.config.getBungeeCord() || FabricProxy.config.getVelocity()) { 17 | return true; 18 | } 19 | return useRemote; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/ServerConfigHandlerMixin.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin; 2 | 3 | import net.minecraft.server.MinecraftServer; 4 | import net.minecraft.server.ServerConfigHandler; 5 | import one.oktw.FabricProxy; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Redirect; 9 | 10 | @Mixin(ServerConfigHandler.class) 11 | public class ServerConfigHandlerMixin { 12 | @Redirect(method = "lookupProfile", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;isOnlineMode()Z")) 13 | private static boolean lookupProfile(MinecraftServer minecraftServer) { 14 | if (FabricProxy.config.getBungeeCord() || FabricProxy.config.getVelocity()) { 15 | return true; 16 | } 17 | 18 | return minecraftServer.isOnlineMode(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FabricProxy 2 | Fabric mod for support forward player data from proxy 3 | 4 | ## Deprecated 5 | **This mod no longer maintained, recommended to use [FabricProxy-Lite](https://github.com/OKTW-Network/FabricProxy-Lite) instead.** 6 | 7 | Because BungeeCord is not compatible with Fabric-API and most mods, I decided to drop BungeeCord support. 8 | 9 | And this mod using some mixin conflict with Fabric-API. That is why create [FabricProxy-Lite]. 10 | 11 | This mod still work but will not actively maintain, pull request still accept. 12 | 13 | ### Third-party forks 14 | Some fork **only support the BungeeCord** protocol, please check the readme before using. 15 | 16 | * https://github.com/voruti/FabricProxy-Legacy 17 | * https://github.com/disymayufei/Fabric-Bungeecord-Proxy 18 | * https://github.com/ImyvmCircle/FabricProxy 19 | 20 | If there are other forks, feel free to open a pull request. 21 | -------------------------------------------------------------------------------- /.github/workflows/workflow.yml: -------------------------------------------------------------------------------- 1 | name: FabricProxy Actions 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | Build: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v2 10 | 11 | - name: Validation 12 | uses: gradle/wrapper-validation-action@v1 13 | 14 | - name: JDK 17 15 | uses: actions/setup-java@v1 16 | with: 17 | java-version: '17' 18 | 19 | - name: cache 20 | uses: actions/cache@v2 21 | with: 22 | path: | 23 | ~/.gradle 24 | .gradle/loom-cache 25 | key: caches-${{ hashFiles('~/.gradle', '.gradle/loom-cache') }} 26 | restore-keys: | 27 | caches- 28 | 29 | - name: Build 30 | run: ./gradlew build 31 | 32 | - name: Upload-Artifact 33 | uses: actions/upload-artifact@master 34 | with: 35 | name: Artifact 36 | path: build/libs 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Expected behavior** 14 | A clear and concise description of what you expected to happen. 15 | 16 | **FabricProxy.toml** 17 | Provide you config (without secret): 18 | ``` 19 | BungeeCord = false 20 | BungeeCordWorkaround = true 21 | Velocity = false 22 | allowBypassProxy = false 23 | ``` 24 | 25 | **Versions** 26 | Minecraft version: 27 | FabricProxy version: 28 | Fabric API version: 29 | Velocity version: 30 | BungeeCord version: 31 | 32 | **Server log** 33 | Provide any related logs on the server side: 34 | ``` 35 | Paste log here 36 | ``` 37 | 38 | **Proxy log** 39 | Provide any related logs on the proxy side: 40 | ``` 41 | Paste log here 42 | ``` 43 | 44 | **Additional context** 45 | Add any other context about the problem here. 46 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/bungee/ClientConnectionMixin.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin.bungee; 2 | 3 | import com.mojang.authlib.properties.Property; 4 | import net.minecraft.network.ClientConnection; 5 | import one.oktw.interfaces.BungeeClientConnection; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | 8 | import java.util.UUID; 9 | 10 | @Mixin(ClientConnection.class) 11 | public abstract class ClientConnectionMixin implements BungeeClientConnection { 12 | private UUID spoofedUUID; 13 | private Property[] spoofedProfile; 14 | 15 | @Override 16 | public UUID getSpoofedUUID() { 17 | return this.spoofedUUID; 18 | } 19 | 20 | @Override 21 | public void setSpoofedUUID(UUID uuid) { 22 | this.spoofedUUID = uuid; 23 | } 24 | 25 | @Override 26 | public Property[] getSpoofedProfile() { 27 | return this.spoofedProfile; 28 | } 29 | 30 | @Override 31 | public void setSpoofedProfile(Property[] profile) { 32 | this.spoofedProfile = profile; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Java Gradle CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-java/ for more details 4 | # 5 | version: 2 6 | jobs: 7 | build: 8 | docker: 9 | # specify the version you desire here 10 | - image: cimg/openjdk:17.0.0 11 | 12 | working_directory: ~/repo 13 | 14 | environment: 15 | # Customize the JVM maximum heap limit 16 | JVM_OPTS: -Xmx3200m 17 | TERM: dumb 18 | 19 | steps: 20 | - checkout 21 | 22 | # Download and cache dependencies 23 | - restore_cache: 24 | keys: 25 | - dependencies-v1-{{ .Branch }}-{{ .Revision }} 26 | - dependencies-v1-{{ .Branch }}- 27 | - dependencies-v1-master- 28 | - dependencies-v1- 29 | 30 | # run build 31 | - run: ./gradlew build 32 | 33 | - save_cache: 34 | paths: 35 | - ~/.gradle 36 | - .gradle/loom-cache 37 | key: dependencies-v1-{{ .Branch }}-{{ .Revision }} 38 | 39 | - store_artifacts: 40 | path: build/libs 41 | destination: . 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 OKTW Network 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/ModConfig.java: -------------------------------------------------------------------------------- 1 | package one.oktw; 2 | 3 | @SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"}) 4 | public class ModConfig { 5 | private Boolean BungeeCord = false; 6 | private Boolean Velocity = false; 7 | private Boolean allowBypassProxy = false; 8 | 9 | private String secret = ""; 10 | 11 | public Boolean getVelocity() { 12 | String env = System.getenv("FABRIC_PROXY_VELOCITY"); 13 | if (env == null) { 14 | return Velocity; 15 | } else { 16 | return env.equalsIgnoreCase("true"); 17 | } 18 | } 19 | 20 | public Boolean getBungeeCord() { 21 | String env = System.getenv("FABRIC_PROXY_BUNGEECORD"); 22 | if (env == null) { 23 | return BungeeCord; 24 | } else { 25 | return env.equalsIgnoreCase("true"); 26 | } 27 | } 28 | 29 | public String getSecret() { 30 | String env = System.getenv("FABRIC_PROXY_SECRET"); 31 | if (env == null) { 32 | return secret; 33 | } else { 34 | return env; 35 | } 36 | } 37 | 38 | public Boolean getAllowBypassProxy() { 39 | String env = System.getenv("FABRIC_PROXY_ALLOW_BYPASS_PROXY"); 40 | if (env == null) { 41 | return allowBypassProxy; 42 | } else { 43 | return Boolean.valueOf(env); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/bungee/ServerLoginNetworkHandlerMixin.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin.bungee; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import com.mojang.authlib.properties.Property; 5 | import net.minecraft.network.ClientConnection; 6 | import net.minecraft.server.MinecraftServer; 7 | import net.minecraft.server.network.ServerLoginNetworkHandler; 8 | import one.oktw.FabricProxy; 9 | import one.oktw.interfaces.BungeeClientConnection; 10 | import org.objectweb.asm.Opcodes; 11 | import org.spongepowered.asm.mixin.Final; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.Shadow; 14 | import org.spongepowered.asm.mixin.injection.At; 15 | import org.spongepowered.asm.mixin.injection.Inject; 16 | import org.spongepowered.asm.mixin.injection.Redirect; 17 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 18 | 19 | @Mixin(ServerLoginNetworkHandler.class) 20 | public abstract class ServerLoginNetworkHandlerMixin { 21 | private boolean bypassProxyBungee = false; 22 | @Shadow 23 | @Final 24 | public ClientConnection connection; 25 | @Shadow 26 | private GameProfile profile; 27 | 28 | @Inject(method = "onHello", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/server/network/ServerLoginNetworkHandler;profile:Lcom/mojang/authlib/GameProfile;", shift = At.Shift.AFTER)) 29 | private void initUuid(CallbackInfo ci) { 30 | if (FabricProxy.config.getBungeeCord()) { 31 | if (((BungeeClientConnection) connection).getSpoofedUUID() == null) { 32 | bypassProxyBungee = true; 33 | return; 34 | } 35 | 36 | this.profile = new GameProfile(((BungeeClientConnection) connection).getSpoofedUUID(), this.profile.getName()); 37 | 38 | if (((BungeeClientConnection) connection).getSpoofedProfile() != null) { 39 | for (Property property : ((BungeeClientConnection) connection).getSpoofedProfile()) { 40 | this.profile.getProperties().put(property.getName(), property); 41 | } 42 | } 43 | } 44 | } 45 | 46 | @Redirect(method = "onHello", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;isOnlineMode()Z")) 47 | private boolean skipKeyPacket(MinecraftServer minecraftServer) { 48 | return (bypassProxyBungee || !FabricProxy.config.getBungeeCord()) && minecraftServer.isOnlineMode(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/VelocityLib.java: -------------------------------------------------------------------------------- 1 | package one.oktw; 2 | 3 | import com.google.common.net.InetAddresses; 4 | import com.mojang.authlib.GameProfile; 5 | import com.mojang.authlib.properties.Property; 6 | import net.minecraft.network.PacketByteBuf; 7 | import net.minecraft.util.Identifier; 8 | 9 | import javax.crypto.Mac; 10 | import javax.crypto.spec.SecretKeySpec; 11 | import java.net.InetAddress; 12 | import java.security.InvalidKeyException; 13 | import java.security.MessageDigest; 14 | import java.security.NoSuchAlgorithmException; 15 | 16 | public class VelocityLib { 17 | public static final Identifier PLAYER_INFO_CHANNEL = new Identifier("velocity", "player_info"); 18 | private static final int SUPPORTED_FORWARDING_VERSION = 1; 19 | 20 | public static boolean checkIntegrity(final PacketByteBuf buf) { 21 | final byte[] signature = new byte[32]; 22 | buf.readBytes(signature); 23 | 24 | final byte[] data = new byte[buf.readableBytes()]; 25 | buf.getBytes(buf.readerIndex(), data); 26 | 27 | try { 28 | final Mac mac = Mac.getInstance("HmacSHA256"); 29 | mac.init(new SecretKeySpec(FabricProxy.config.getSecret().getBytes(), "HmacSHA256")); 30 | final byte[] mySignature = mac.doFinal(data); 31 | if (!MessageDigest.isEqual(signature, mySignature)) { 32 | return false; 33 | } 34 | } catch (final InvalidKeyException | NoSuchAlgorithmException e) { 35 | throw new AssertionError(e); 36 | } 37 | 38 | int version = buf.readVarInt(); 39 | if (version != SUPPORTED_FORWARDING_VERSION) { 40 | throw new IllegalStateException("Unsupported forwarding version " + version + ", wanted " + SUPPORTED_FORWARDING_VERSION); 41 | } 42 | 43 | return true; 44 | } 45 | 46 | public static InetAddress readAddress(final PacketByteBuf buf) { 47 | return InetAddresses.forString(buf.readString(Short.MAX_VALUE)); 48 | } 49 | 50 | public static GameProfile createProfile(final PacketByteBuf buf) { 51 | final GameProfile profile = new GameProfile(buf.readUuid(), buf.readString(16)); 52 | readProperties(buf, profile); 53 | return profile; 54 | } 55 | 56 | private static void readProperties(final PacketByteBuf buf, final GameProfile profile) { 57 | final int properties = buf.readVarInt(); 58 | for (int i1 = 0; i1 < properties; i1++) { 59 | final String name = buf.readString(Short.MAX_VALUE); 60 | final String value = buf.readString(Short.MAX_VALUE); 61 | final String signature = buf.readBoolean() ? buf.readString(Short.MAX_VALUE) : null; 62 | profile.getProperties().put(name, new Property(name, value, signature)); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/bungee/ServerHandshakeNetworkHandlerMixin.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin.bungee; 2 | 3 | import com.google.gson.Gson; 4 | import com.mojang.authlib.properties.Property; 5 | import com.mojang.util.UUIDTypeAdapter; 6 | import net.minecraft.network.ClientConnection; 7 | import net.minecraft.network.NetworkState; 8 | import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket; 9 | import net.minecraft.network.packet.s2c.login.LoginDisconnectS2CPacket; 10 | import net.minecraft.server.network.ServerHandshakeNetworkHandler; 11 | import net.minecraft.text.LiteralText; 12 | import net.minecraft.text.Text; 13 | import one.oktw.interfaces.BungeeClientConnection; 14 | import one.oktw.mixin.ClientConnectionAccessor; 15 | import org.spongepowered.asm.mixin.Final; 16 | import org.spongepowered.asm.mixin.Mixin; 17 | import org.spongepowered.asm.mixin.Shadow; 18 | import org.spongepowered.asm.mixin.injection.At; 19 | import org.spongepowered.asm.mixin.injection.Inject; 20 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 21 | 22 | import static one.oktw.FabricProxy.config; 23 | 24 | @Mixin(ServerHandshakeNetworkHandler.class) 25 | public class ServerHandshakeNetworkHandlerMixin { 26 | private static final Gson gson = new Gson(); 27 | 28 | @Shadow 29 | @Final 30 | private ClientConnection connection; 31 | 32 | @Inject(method = "onHandshake", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerLoginNetworkHandler;(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/ClientConnection;)V")) 33 | private void onProcessHandshakeStart(HandshakeC2SPacket packet, CallbackInfo ci) { 34 | if (config.getBungeeCord() && packet.getIntendedState().equals(NetworkState.LOGIN)) { 35 | String[] split = ((HandshakeC2SPacketAccessor) packet).getAddress().split("\00"); 36 | if (split.length == 3 || split.length == 4) { 37 | ((ClientConnectionAccessor) connection).setAddress(new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) connection.getAddress()).getPort())); 38 | ((BungeeClientConnection) connection).setSpoofedUUID(UUIDTypeAdapter.fromString(split[2])); 39 | 40 | if (split.length == 4) { 41 | ((BungeeClientConnection) connection).setSpoofedProfile(gson.fromJson(split[3], Property[].class)); 42 | } 43 | } else { 44 | if (!config.getAllowBypassProxy()) { 45 | Text disconnectMessage = new LiteralText("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!"); 46 | connection.send(new LoginDisconnectS2CPacket(disconnectMessage)); 47 | connection.disconnect(disconnectMessage); 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/FabricProxy.java: -------------------------------------------------------------------------------- 1 | package one.oktw; 2 | 3 | import com.moandjiezana.toml.Toml; 4 | import com.moandjiezana.toml.TomlWriter; 5 | import net.fabricmc.loader.api.FabricLoader; 6 | 7 | import org.apache.logging.log4j.LogManager; 8 | import org.apache.logging.log4j.Logger; 9 | import org.objectweb.asm.tree.ClassNode; 10 | import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; 11 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo; 12 | 13 | import java.io.IOException; 14 | import java.nio.file.Files; 15 | import java.util.List; 16 | import java.util.Set; 17 | 18 | public class FabricProxy implements IMixinConfigPlugin { 19 | public static ModConfig config; 20 | private final Logger logger = LogManager.getLogger("FabricProxy"); 21 | 22 | @Override 23 | public void onLoad(String mixinPackage) { 24 | if (config == null) { 25 | var configFile = FabricLoader.getInstance().getConfigDir().resolve("FabricProxy.toml"); 26 | if (!Files.exists(configFile)) { 27 | config = new ModConfig(); 28 | try { 29 | new TomlWriter().write(config, configFile.toFile()); 30 | } catch (IOException e) { 31 | LogManager.getLogger().error("Init config failed.", e); 32 | } 33 | } else { 34 | config = new Toml().read(FabricLoader.getInstance().getConfigDir().resolve("FabricProxy.toml").toFile()).to(ModConfig.class); 35 | } 36 | } 37 | } 38 | 39 | @Override 40 | public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { 41 | String module = mixinClassName.split("\\.")[3]; 42 | if (module.equals("bungee") && config.getBungeeCord()) { 43 | logger.info("BungeeCord support injected: {}", mixinClassName); 44 | return true; 45 | } 46 | 47 | if (module.equals("velocity") && config.getVelocity()) { 48 | if (config.getSecret().isEmpty()) { 49 | logger.error("Error: velocity secret is empty!"); 50 | } else { 51 | logger.info("Velocity support injected: {}", mixinClassName); 52 | return true; 53 | } 54 | } 55 | 56 | return false; 57 | } 58 | 59 | @Override 60 | public String getRefMapperConfig() { 61 | return null; 62 | } 63 | 64 | @Override 65 | public void acceptTargets(Set myTargets, Set otherTargets) { 66 | 67 | } 68 | 69 | @Override 70 | public List getMixins() { 71 | return null; 72 | } 73 | 74 | @Override 75 | public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { 76 | 77 | } 78 | 79 | @Override 80 | public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/main/java/one/oktw/mixin/velocity/ServerLoginNetworkHandlerMixin.java: -------------------------------------------------------------------------------- 1 | package one.oktw.mixin.velocity; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import net.fabricmc.fabric.mixin.networking.accessor.LoginQueryResponseC2SPacketAccessor; 5 | import net.minecraft.network.ClientConnection; 6 | import net.minecraft.network.PacketByteBuf; 7 | import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket; 8 | import net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket; 9 | import net.minecraft.network.packet.s2c.login.LoginQueryRequestS2CPacket; 10 | import net.minecraft.server.network.ServerLoginNetworkHandler; 11 | import net.minecraft.text.LiteralText; 12 | import net.minecraft.text.Text; 13 | import one.oktw.FabricProxy; 14 | import one.oktw.VelocityLib; 15 | import one.oktw.interfaces.BungeeClientConnection; 16 | import one.oktw.mixin.ClientConnectionAccessor; 17 | import org.spongepowered.asm.mixin.Final; 18 | import org.spongepowered.asm.mixin.Mixin; 19 | import org.spongepowered.asm.mixin.Shadow; 20 | import org.spongepowered.asm.mixin.injection.At; 21 | import org.spongepowered.asm.mixin.injection.Inject; 22 | import org.spongepowered.asm.mixin.injection.Redirect; 23 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 24 | 25 | import static io.netty.buffer.Unpooled.EMPTY_BUFFER; 26 | import static one.oktw.FabricProxy.config; 27 | 28 | @Mixin(value = ServerLoginNetworkHandler.class, priority = 1001) 29 | public abstract class ServerLoginNetworkHandlerMixin { 30 | private int velocityLoginQueryId = -1; 31 | private boolean ready = false; 32 | private boolean bypassProxyVelocity = false; 33 | private LoginHelloC2SPacket loginPacket; 34 | 35 | @Shadow 36 | @Final 37 | public ClientConnection connection; 38 | 39 | @Shadow 40 | private GameProfile profile; 41 | 42 | @Shadow 43 | public abstract void disconnect(Text text); 44 | 45 | @Shadow 46 | public abstract void onHello(LoginHelloC2SPacket loginHelloC2SPacket); 47 | 48 | @SuppressWarnings("ConstantConditions") 49 | @Inject(method = "onHello", 50 | at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/c2s/login/LoginHelloC2SPacket;getProfile()Lcom/mojang/authlib/GameProfile;"), 51 | cancellable = true) 52 | private void sendVelocityPacket(LoginHelloC2SPacket loginHelloC2SPacket, CallbackInfo ci) { 53 | // Bypass BungeeCord connection 54 | if (config.getBungeeCord() && ((BungeeClientConnection) connection).getSpoofedUUID() != null) { 55 | bypassProxyVelocity = true; 56 | } 57 | 58 | if (!bypassProxyVelocity && !ready) { 59 | if (FabricProxy.config.getAllowBypassProxy()) { 60 | loginPacket = loginHelloC2SPacket; 61 | } 62 | this.velocityLoginQueryId = java.util.concurrent.ThreadLocalRandom.current().nextInt(); 63 | LoginQueryRequestS2CPacket packet = new LoginQueryRequestS2CPacket( 64 | velocityLoginQueryId, 65 | VelocityLib.PLAYER_INFO_CHANNEL, 66 | new PacketByteBuf(EMPTY_BUFFER) 67 | ); 68 | connection.send(packet); 69 | ci.cancel(); 70 | } 71 | } 72 | 73 | @Redirect(method = "onHello", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;isLocal()Z")) 74 | private boolean skipAuth(ClientConnection connection) { 75 | return !bypassProxyVelocity; 76 | } 77 | 78 | @Inject(method = "onQueryResponse", at = @At("HEAD"), cancellable = true) 79 | private void forwardPlayerInfo(LoginQueryResponseC2SPacket packet, CallbackInfo ci) { 80 | if (FabricProxy.config.getVelocity() && ((LoginQueryResponseC2SPacketAccessor) packet).getQueryId() == velocityLoginQueryId) { 81 | PacketByteBuf buf = ((LoginQueryResponseC2SPacketAccessor) packet).getResponse(); 82 | if (buf == null) { 83 | if (!FabricProxy.config.getAllowBypassProxy()) { 84 | disconnect(new LiteralText("This server requires you to connect with Velocity.")); 85 | return; 86 | } 87 | 88 | bypassProxyVelocity = true; 89 | onHello(loginPacket); 90 | ci.cancel(); 91 | return; 92 | } 93 | 94 | if (!VelocityLib.checkIntegrity(buf)) { 95 | disconnect(new LiteralText("Unable to verify player details")); 96 | return; 97 | } 98 | 99 | ((ClientConnectionAccessor) connection).setAddress(new java.net.InetSocketAddress(VelocityLib.readAddress(buf), ((java.net.InetSocketAddress) connection.getAddress()).getPort())); 100 | 101 | profile = VelocityLib.createProfile(buf); 102 | 103 | ready = true; 104 | onHello(new LoginHelloC2SPacket(profile)); 105 | ci.cancel(); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | --------------------------------------------------------------------------------