Compare commits

...

6 Commits

Author SHA1 Message Date
Joseph T. McQuigg
ac242b631e
Gradle 8.0
Signed-off-by: Joseph T. McQuigg <J.T.McQuigg12@gmail.com>
2023-02-17 14:31:00 -05:00
Adrian Bergqvist
4be2b3760a
Inject class. Experimenting. 2023-02-08 16:47:04 +01:00
Adrian Bergqvist
a48f2ae309
Cleaned remaining files ...again
I'm bad at git
2023-02-04 16:52:04 +01:00
Adrian Bergqvist
c72f5b72f2
Update gitignore 2023-02-04 16:49:18 +01:00
Adrian Bergqvist
2a004712e3
Cleaned remaining files 2023-02-04 16:46:06 +01:00
Adrian Bergqvist
2063b1364e
Restructured project 2023-02-04 16:44:27 +01:00
33 changed files with 388 additions and 32 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
.gradle
/build/
/ambassador-bungeecord/build/
/ambassador-velocity/build/
# Ignore Gradle GUI config
gradle-app.setting

View File

@ -0,0 +1,17 @@
plugins {
java
id("com.github.johnrengelman.shadow") version "7.1.2"
}
group = "org.adde0109"
version = "1.1.7-alpha-bungeecord"
repositories {
mavenCentral()
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // This lets gradle find the BungeeCord files online
}
dependencies {
compileOnly("net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT")
implementation("org.javassist:javassist:3.29.2-GA")
}

View File

@ -0,0 +1,15 @@
package org.adde0109.ambassador;
import net.md_5.bungee.api.plugin.Plugin;
import org.adde0109.ambassador.forgeCommandArgument.Injector;
public class AmbassadorPlugin extends Plugin {
@Override
public void onEnable() {
// You should not put an enable message in your plugin.
// BungeeCord already does so
getLogger().info("Yay! It loads!");
Injector.inject();
}
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.adde0109.ambassador.forgeCommandArgument;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
public class EnumArgumentProperty {
private final String className;
public EnumArgumentProperty(String className) {
this.className = className;
}
public String getClassName() {
return this.className;
}
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.adde0109.ambassador.forgeCommandArgument;
import io.netty.buffer.ByteBuf;
import net.md_5.bungee.protocol.DefinedPacket;
import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* An argument property serializer that will serialize and deserialize nothing.
*/
public class EnumArgumentPropertySerializer {
public static final EnumArgumentPropertySerializer ENUM;
static {
try {
ENUM = new EnumArgumentPropertySerializer();
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | ClassNotFoundException |
NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
EnumArgumentPropertySerializer() throws InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException {
Constructor constructor = EnumArgumentPropertySerializer.class.getSuperclass().getDeclaredConstructor(Class.forName("net.md_5.bungee.protocol.packet.Commands$1"));
constructor.setAccessible(true);
constructor.newInstance(this);
}
protected Object read(ByteBuf buf) {
return new EnumArgumentProperty(DefinedPacket.readString(buf));
}
protected void write(ByteBuf buf, Object t) {
DefinedPacket.writeString(((EnumArgumentProperty) t).getClassName(),buf);
}
}

View File

@ -0,0 +1,52 @@
package org.adde0109.ambassador.forgeCommandArgument;
import javassist.*;
import javassist.bytecode.ClassFile;
import javassist.expr.MethodCall;
import net.md_5.bungee.protocol.Protocol;
import net.md_5.bungee.protocol.packet.Commands;
import org.adde0109.ambassador.forgeCommandArgument.EnumArgumentPropertySerializer;
import org.checkerframework.checker.units.qual.C;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
public class Injector{
static public void inject() {
try {
Class<?> argumentRegistryClass = Class.forName("net.md_5.bungee.protocol.packet.Commands$ArgumentRegistry");
Class<?> networkNodeClass = Class.forName("net.md_5.bungee.protocol.packet.Commands$NetworkNode");
Class<?> argumentSerializerClass = Class.forName("net.md_5.bungee.protocol.packet.Commands$ArgumentRegistry$ArgumentSerializer");
ClassPool.getDefault().insertClassPath(new ClassClassPath(EnumArgumentPropertySerializer.class));
ClassPool.getDefault().insertClassPath(new ClassClassPath(EnumArgumentProperty.class));
CtClass cc = ClassPool.getDefault().get("org.adde0109.ambassador.forgeCommandArgument.EnumArgumentPropertySerializer");
CtClass scc = ClassPool.getDefault().get("net.md_5.bungee.protocol.packet.Commands$ArgumentRegistry$ArgumentSerializer");
CtClass newcc = scc.getDeclaringClass().makeNestedClass("EnumArgumentPropertySerializer",true);
newcc.addMethod(new CtMethod(cc.getDeclaredMethod("read"), newcc, null));
newcc.addMethod(new CtMethod(cc.getDeclaredMethod("write"), newcc, null));
newcc.setSuperclass(scc);
//CtConstructor ctconstructor = new CtConstructor(cc.getDeclaredConstructor(null),newcc,null);
//newcc.addConstructor(ctconstructor);
Class<?> loaded= newcc.toClass(argumentSerializerClass);
Method method = argumentRegistryClass.getDeclaredMethod("register",String.class,argumentSerializerClass);
//Constructor<?> superconstructor = argumentSerializerClass.getDeclaredConstructors()[0];
//method.setAccessible(true);
//Constructor<?> constructor = loaded.getDeclaredConstructor();
//constructor.setAccessible(true);
//method.invoke(null,"forge:enum", constructor.newInstance());
CtClass dcc = scc.getDeclaringClass();
dcc.getClassInitializer().insertAfter("$class.getDeclaredMethod(\"register\",String.class,Class.forName(\"net.md_5.bungee.protocol.packet.Commands$ArgumentRegistry$ArgumentSerializer\"));");
dcc.toClass(networkNodeClass);
MethodCall
} catch (ReflectiveOperationException | NotFoundException | CannotCompileException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,4 @@
name: Ambassador
main: org.adde0109.ambassador.AmbassadorPlugin
version: 0.0.0-Bungeecord
author: adde0109

View File

@ -1,6 +1,5 @@
plugins {
java
idea
id("com.github.johnrengelman.shadow") version "7.1.2"
}

View File

@ -4,22 +4,27 @@ import com.google.inject.Inject;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import java.lang.reflect.Field;
import java.util.concurrent.Callable;
import java.lang.reflect.Method;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.network.BackendChannelInitializer;
import com.velocitypowered.proxy.network.ConnectionManager;
import com.velocitypowered.proxy.network.ServerChannelInitializer;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertyRegistry;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertySerializer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelInitializer;
import org.adde0109.ambassador.velocity.VelocityBackendChannelInitializer;
import org.adde0109.ambassador.velocity.VelocityServerChannelInitializer;
import org.adde0109.ambassador.velocity.VelocityEventHandler;
import org.bstats.charts.SingleLineChart;
import org.adde0109.ambassador.velocity.commands.EnumArgumentProperty;
import org.adde0109.ambassador.velocity.commands.EnumArgumentPropertySerializer;
import org.adde0109.ambassador.velocity.commands.ModIdArgumentProperty;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
@ -66,6 +71,23 @@ public class Ambassador {
ChannelInitializer<?> originalBackend = ((ConnectionManager) cmField.get(server)).backendChannelInitializer.get();
((ConnectionManager) cmField.get(server)).backendChannelInitializer.set(new VelocityBackendChannelInitializer(originalBackend,(VelocityServer) server));
Method argumentRegistry = ArgumentPropertyRegistry.class.getDeclaredMethod("register", ArgumentIdentifier.class, Class.class, ArgumentPropertySerializer.class);
argumentRegistry.setAccessible(true);
argumentRegistry.invoke(null,ArgumentIdentifier.id("forge:enum"), EnumArgumentProperty.class, EnumArgumentPropertySerializer.ENUM);
argumentRegistry.invoke(null,ArgumentIdentifier.id("forge:modid"), ModIdArgumentProperty.class,
new ArgumentPropertySerializer<>() {
@Override
public ModIdArgumentProperty deserialize(ByteBuf buf, ProtocolVersion protocolVersion) {
return new ModIdArgumentProperty();
}
@Override
public void serialize(Object object, ByteBuf buf, ProtocolVersion protocolVersion) {
}
});
}
private void initMetrics() {

View File

@ -3,25 +3,8 @@ package org.adde0109.ambassador.forge;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.util.ModInfo;
import java.util.*;
import com.velocitypowered.api.util.UuidUtils;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess;
import io.netty.buffer.ByteBuf;
import org.adde0109.ambassador.velocity.VelocityForgeHandshakeSessionHandler;
import org.slf4j.Logger;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
public class ForgeHandshakeUtils {

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.adde0109.ambassador.velocity.commands;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
public class EnumArgumentProperty implements ArgumentType<String> {
private final String className;
public EnumArgumentProperty(String className) {
this.className = className;
}
public String getClassName() {
return this.className;
}
@Override
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.adde0109.ambassador.velocity.commands;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertySerializer;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* An argument property serializer that will serialize and deserialize nothing.
*/
public class EnumArgumentPropertySerializer implements ArgumentPropertySerializer<EnumArgumentProperty> {
public static final EnumArgumentPropertySerializer ENUM = new EnumArgumentPropertySerializer();
private EnumArgumentPropertySerializer() {
}
@Override
public @Nullable EnumArgumentProperty deserialize(ByteBuf buf, ProtocolVersion protocolVersion) {
return new EnumArgumentProperty(ProtocolUtils.readString(buf));
}
@Override
public void serialize(EnumArgumentProperty object, ByteBuf buf, ProtocolVersion protocolVersion) {
ProtocolUtils.writeString(buf, object.getClassName());
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.adde0109.ambassador.velocity.commands;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.util.ModInfo;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class ModIdArgumentProperty implements ArgumentType<String> {
public ModIdArgumentProperty() {}
@Override
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context,
SuggestionsBuilder builder) {
S source = context.getSource();
if (source instanceof Player) {
ModInfo modInfo = ((Player) source).getModInfo().orElse(null);
if (modInfo != null) {
for (ModInfo.Mod mod : modInfo.getMods()) {
builder.suggest(mod.getId());
}
return builder.buildFuture();
}
}
return Suggestions.empty();
}
@Override
public Collection<String> getExamples() {
throw new UnsupportedOperationException();
}
}

Binary file not shown.

View File

@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

12
gradlew vendored
View File

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@ -80,10 +80,10 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac

1
gradlew.bat vendored
View File

@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

View File

@ -1,7 +1,15 @@
rootProject.name = "Ambassador"
includeBuild("Velocity") {
dependencySubstitution {
substitute(module("com.velocitypowered:velocity-api")).using(project(":velocity-api"))
substitute(module("com.velocitypowered:velocity-proxy")).using(project(":velocity-proxy"))
val velocityPath = rootProject.projectDir.toPath().resolve("Velocity/");
includeBuild("Velocity") {
dependencySubstitution {
if(java.nio.file.Files.isDirectory(velocityPath.resolve("proxy/"))) {
substitute(module("com.velocitypowered:velocity-proxy")).using(project(":velocity-proxy"))
substitute(module("com.velocitypowered:velocity-api")).using(project(":velocity-api"))
} else {
logger.warn("Git Submodule 'Velocity' not initialized!")
}
}
}
}
include("ambassador-velocity")
include("ambassador-bungeecord")