Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive command descriptions from floodgate #4216

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.geysermc.geyser.dump.BootstrapDumpInfo;
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
import org.geysermc.geyser.platform.standalone.command.GeyserStandaloneCommandManager;
import org.geysermc.geyser.platform.standalone.gui.GeyserStandaloneGUI;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.FileUtils;
Expand All @@ -64,7 +65,7 @@

public class GeyserStandaloneBootstrap implements GeyserBootstrap {

private GeyserCommandManager geyserCommandManager;
private GeyserStandaloneCommandManager geyserCommandManager;
private GeyserStandaloneConfiguration geyserConfig;
private GeyserStandaloneLogger geyserLogger;
private IGeyserPingPassthrough geyserPingPassthrough;
Expand Down Expand Up @@ -220,7 +221,7 @@ public void onEnable() {
geyser = GeyserImpl.load(PlatformType.STANDALONE, this);
GeyserImpl.start();

geyserCommandManager = new GeyserCommandManager(geyser);
geyserCommandManager = new GeyserStandaloneCommandManager(geyser);
geyserCommandManager.init();

if (gui != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.platform.standalone.command;

import lombok.Getter;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommandManager;

import java.util.HashMap;
import java.util.Map;

@Getter
public class GeyserStandaloneCommandManager extends GeyserCommandManager {

// command descriptions optionally sent by floodgate on backend servers
private Map<String, String> commandDescriptionMap = new HashMap<>();

public GeyserStandaloneCommandManager(GeyserImpl geyser) {
super(geyser);
}

@Override
public void addCommandDescriptions(Map<String, String> commandDescriptions) {
commandDescriptionMap.putAll(commandDescriptions);
}

@Override
public String description(String command) {
String description = commandDescriptionMap.get(command.replace("/", ""));
return description != null ? description : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public final class PluginMessageChannels {
public static final String FORM = "floodgate:form";
public static final String TRANSFER = "floodgate:transfer";
public static final String PACKET = "floodgate:packet";
public static final String COMMANDS = "floodgate:commands";

private static final byte[] FLOODGATE_REGISTER_DATA =
String.join("\0", SKIN, FORM, TRANSFER, PACKET)
String.join("\0", SKIN, FORM, TRANSFER, PACKET, COMMANDS)
.getBytes(StandardCharsets.UTF_8);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public Map<String, Command> commands() {
return Collections.unmodifiableMap(this.commands);
}

public void addCommandDescriptions(Map<String, String> commandDescriptions){
return;
}

@NotNull
public Map<Extension, Map<String, Command>> extensionCommands() {
return Collections.unmodifiableMap(this.extensionCommands);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket;
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket;
import com.google.common.base.Charsets;
import org.cloudburstmc.protocol.bedrock.packet.TransferPacket;
import org.cloudburstmc.protocol.bedrock.packet.UnknownPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.cloudburstmc.protocol.bedrock.packet.TransferPacket;
import org.cloudburstmc.protocol.bedrock.packet.UnknownPacket;
import org.geysermc.cumulus.Forms;
import org.geysermc.cumulus.form.Form;
import org.geysermc.cumulus.form.util.FormType;
Expand All @@ -47,6 +47,8 @@
import org.geysermc.geyser.translator.protocol.Translator;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

@Translator(packet = ClientboundCustomPayloadPacket.class)
public class JavaCustomPayloadTranslator extends PacketTranslator<ClientboundCustomPayloadPacket> {
Expand Down Expand Up @@ -138,7 +140,27 @@ public void translate(GeyserSession session, ClientboundCustomPayloadPacket pack

session.sendUpstreamPacket(toSend);
});
} else if (channel.equals(PluginMessageChannels.COMMANDS)) {
session.ensureInEventLoop(() -> {
Map<String, String> parsedCommandDescriptions = deserializeCommandDescriptions(packet.getData());
session.getGeyser().commandManager().addCommandDescriptions(parsedCommandDescriptions);
});
}
}

public Map<String, String> deserializeCommandDescriptions(byte[] data) {
ByteBuf in = Unpooled.wrappedBuffer(data);

Map<String, String> parsedCommandDescriptions = new HashMap<>();
int length = in.readUnsignedShort();
for (int i = 0; i < length; i++) {
int commandLength = in.readUnsignedShort();
String command = in.readBytes(commandLength).toString(StandardCharsets.UTF_8);
int commandDescriptionLength = in.readUnsignedShort();
String description = in.readBytes(commandDescriptionLength).toString(StandardCharsets.UTF_8);
parsedCommandDescriptions.put(command, description);
}
return parsedCommandDescriptions;
}

@Override
Expand Down