Add `subservers:input` for 1.19+

This is a simple plugin message channel that simulates chat spoofing.
This commit is contained in:
ME1312 2022-06-15 11:54:36 -04:00
parent 307ac43df0
commit 41dd2d69d0
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
11 changed files with 58 additions and 22 deletions

View File

@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@ -671,9 +672,12 @@ public final class SubCommand extends Command implements TabExecutor {
sender.sendMessages(printHelp());
}
} else {
String str = label;
for (String arg : args) str += ' ' + arg;
((ProxiedPlayer) sender).chat(str);
ProxiedPlayer player = (ProxiedPlayer) sender;
if (player.getPendingConnection().getVersion() < 759) { // player < 1.19
player.chat((args.length == 0)? label : label + ' ' + String.join(" ", args));
} else {
player.getServer().sendData("subservers:input", ((args.length == 0)? label : label + ' ' + String.join(" ", args)).getBytes(StandardCharsets.UTF_8));
}
}
}

View File

@ -92,7 +92,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
public SubProtocol subprotocol;
public SubDataServer subdata = null;
public SubServer sudo = null;
public static final Version version = Version.fromString("2.18.2a");
public static final Version version = Version.fromString("2.19a");
public final Proxy mProxy;
public boolean canSudo = false;
@ -724,6 +724,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
if (!config.get().getMap("Settings").getStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(plugin, new SubCommand.BungeeList(this, "glist"));
registerChannel("subservers:input");
getPluginManager().registerCommand(plugin, new SubCommand(this, "subservers"));
getPluginManager().registerCommand(plugin, new SubCommand(this, "subserver"));
getPluginManager().registerCommand(plugin, new SubCommand(this, "sub"));

View File

@ -26,6 +26,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.Messenger;
import java.io.*;
import java.lang.invoke.MethodHandle;
@ -33,6 +34,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
@ -96,7 +98,9 @@ public final class SubPlugin extends JavaPlugin {
Files.move(new File(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new File(dir, "subdata.rsa.key").toPath());
}
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Messenger pmc = getServer().getMessenger();
pmc.registerOutgoingPluginChannel(this, "BungeeCord");
pmc.registerIncomingPluginChannel(this, "subservers:input", (channel, player, bytes) -> player.chat(new String(bytes, StandardCharsets.UTF_8)));
reload(false);
subprotocol = SubProtocol.get();
@ -232,6 +236,10 @@ public final class SubPlugin extends JavaPlugin {
subdata.clear();
subdata.put(0, null);
if (signs != null) signs.save();
Messenger pmc = getServer().getMessenger();
pmc.unregisterOutgoingPluginChannel(this);
pmc.unregisterIncomingPluginChannel(this);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}

View File

@ -1,6 +1,6 @@
name: SubServers-Client-Bukkit
main: net.ME1312.SubServers.Client.Bukkit.SubPlugin
version: "2.18.2a"
version: "2.19a"
authors: ["ME1312"]
softdepend: [TitleAPI, PlaceholderAPI]
website: "https://github.com/ME1312/SubServers-2"

View File

@ -27,6 +27,7 @@ import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingEvent;
import org.spongepowered.api.network.ChannelBinding;
import org.spongepowered.api.plugin.Plugin;
@ -47,7 +48,7 @@ import static net.ME1312.SubServers.Client.Sponge.Library.AccessMode.NO_COMMANDS
/**
* SubServers Client Plugin Class
*/
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.18.2a", url = "https://github.com/ME1312/SubServers-2", description = "Take control of the server manager — from your servers")
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.19a", url = "https://github.com/ME1312/SubServers-2", description = "Take control of the server manager — from your servers")
public final class SubPlugin {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
Pair<Long, Map<String, Map<String, String>>> lang = null;
@ -66,14 +67,15 @@ public final class SubPlugin {
@Inject public Game game;
boolean running = false;
private boolean posted = false;
private long resetDate = 0;
private boolean reconnect = false;
@Listener
public void setup(GamePreInitializationEvent event) {
public void enable(GamePreInitializationEvent event) {
if (plugin.getVersion().isPresent()) {
version = Version.fromString(plugin.getVersion().get());
} else version = new Version("Custom");
} else version = new Version("?");
subdata.put(0, null);
}
@ -136,12 +138,23 @@ public final class SubPlugin {
reconnect = true;
log.info(" ");
log.info("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391"));
connect(null);
if (posted) connect(null);
//gui = new InternalUIHandler(this);
if (api.access.value > NO_COMMANDS.value && !config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) {
Sponge.getCommandManager().register(plugin, new SubCommand(this).spec(), "sub", "subserver", "subservers");
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Listener
@SuppressWarnings("unchecked")
public void enable(GameStartedServerEvent event) {
if (!posted) try {
posted = true;
connect(null);
new Metrics(this);
game.getScheduler().createTaskBuilder().async().execute(() -> {
@ -167,8 +180,6 @@ public final class SubPlugin {
}
}
public void reload(boolean notifyPlugins) throws IOException {
resetDate = Calendar.getInstance().getTime().getTime();

View File

@ -42,7 +42,7 @@ import java.util.jar.Manifest;
/**
* SubServers.Host Main Class
*/
@App(name = "SubServers.Host", version = "2.18.2a", authors = "ME1312", website = "https://github.com/ME1312/SubServers-2", description = "Host subservers on separate machines")
@App(name = "SubServers.Host", version = "2.19a", authors = "ME1312", website = "https://github.com/ME1312/SubServers-2", description = "Host subservers on separate machines")
public final class ExHost {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
Pair<Long, Map<String, Map<String, String>>> lang = null;

View File

@ -74,7 +74,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
public final Plugin plugin;
public final SubAPI api = new SubAPI(this);
public SubProtocol subprotocol;
public static final Version version = Version.fromString("2.18.2a");
public static final Version version = Version.fromString("2.19a");
public final boolean isPatched;
public long lastReload = -1;
@ -260,6 +260,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
if (!config.get().getMap("Settings").getStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(plugin, new SubCommand.BungeeList(this, "glist"));
registerChannel("subservers:input");
getPluginManager().registerCommand(plugin, new SubCommand(this, "subservers"));
getPluginManager().registerCommand(plugin, new SubCommand(this, "subserver"));
getPluginManager().registerCommand(plugin, new SubCommand(this, "sub"));

View File

@ -38,6 +38,7 @@ import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@ -731,9 +732,12 @@ public final class SubCommand extends Command implements TabExecutor {
}
}
} else {
String str = label;
for (String arg : args) str += ' ' + arg;
((ProxiedPlayer) sender).chat(str);
ProxiedPlayer player = (ProxiedPlayer) sender;
if (player.getPendingConnection().getVersion() < 759) { // player < 1.19
player.chat((args.length == 0)? label : label + ' ' + String.join(" ", args));
} else {
player.getServer().sendData("subservers:input", ((args.length == 0)? label : label + ' ' + String.join(" ", args)).getBytes(StandardCharsets.UTF_8));
}
}
}

View File

@ -28,7 +28,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.0.0</version>
<version>3.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -64,7 +64,7 @@ import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Plugin(id = "subservers-sync", name = "SubServers-Sync", authors = "ME1312", version = "2.18.2a", url = "https://github.com/ME1312/SubServers-2", description = "Dynamically sync player and server connection info over multiple proxy instances")
@Plugin(id = "subservers-sync", name = "SubServers-Sync", authors = "ME1312", version = "2.19a", url = "https://github.com/ME1312/SubServers-2", description = "Dynamically sync player and server connection info over multiple proxy instances")
public class ExProxy {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
@ -225,6 +225,7 @@ public class ExProxy {
if (!config.get().getMap("Settings").getStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
proxy.getCommandManager().register("glist", new SubCommand.BungeeList(this));
proxy.getChannelRegistrar().register(SubCommand.pmc);
proxy.getCommandManager().register("subservers", new SubCommand(this), "subserver", "sub");
if (config.get().getMap("Settings").getMap("Smart-Fallback", new ObjectMap<>()).getBoolean("Enabled", true))

View File

@ -29,6 +29,7 @@ import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerInfo;
import net.kyori.adventure.text.Component;
@ -42,6 +43,7 @@ import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@ -49,6 +51,7 @@ import java.util.function.Supplier;
@SuppressWarnings("deprecation")
public final class SubCommand implements SimpleCommand {
static final MinecraftChannelIdentifier pmc = MinecraftChannelIdentifier.create("subservers", "input");
static HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>> permitted = new HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>>();
private Map<String, Proxy> proxyCache = Collections.emptyMap();
private Map<String, Host> hostCache = Collections.emptyMap();
@ -736,9 +739,12 @@ public final class SubCommand implements SimpleCommand {
}
}
} else {
String str = label;
for (String arg : args) str += ' ' + arg;
((Player) sender).spoofChatInput(str);
Player player = (Player) sender;
if (player.getProtocolVersion().getProtocol() < 759) { // player < 1.19
player.spoofChatInput((args.length == 0)? label : label + ' ' + String.join(" ", args));
} else {
player.getCurrentServer().ifPresent(server -> server.sendPluginMessage(pmc, ((args.length == 0)? label : label + ' ' + String.join(" ", args)).getBytes(StandardCharsets.UTF_8)));
}
}
}