mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-12-22 16:38:04 +01:00
Added brand rewriter to include ViaProxy in server brand string
This commit is contained in:
parent
ec5bba24a9
commit
15b4d4ec90
@ -204,7 +204,8 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||
this.proxyConnection.setC2pConnectionState(intendedState.getConnectionState());
|
||||
this.proxyConnection.setUserOptions(userOptions);
|
||||
this.proxyConnection.getPacketHandlers().add(new StatusPacketHandler(this.proxyConnection));
|
||||
this.proxyConnection.getPacketHandlers().add(new CustomPayloadPacketHandler(this.proxyConnection));
|
||||
this.proxyConnection.getPacketHandlers().add(new OpenAuthModPacketHandler(this.proxyConnection));
|
||||
this.proxyConnection.getPacketHandlers().add(new BrandCustomPayloadPacketHandler(this.proxyConnection));
|
||||
this.proxyConnection.getPacketHandlers().add(new CompressionPacketHandler(this.proxyConnection));
|
||||
this.proxyConnection.getPacketHandlers().add(new LoginPacketHandler(this.proxyConnection));
|
||||
if (clientVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2024 RK_01/RaphiMC and 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.proxy.packethandler;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import net.raphimc.netminecraft.constants.ConnectionState;
|
||||
import net.raphimc.netminecraft.constants.MCPackets;
|
||||
import net.raphimc.netminecraft.packet.IPacket;
|
||||
import net.raphimc.netminecraft.packet.PacketTypes;
|
||||
import net.raphimc.netminecraft.packet.UnknownPacket;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BrandCustomPayloadPacketHandler extends PacketHandler {
|
||||
|
||||
private static final String BRAND_CHANNEL = "minecraft:brand";
|
||||
private static final String LEGACY_BRAND_CHANNEL = "MC|Brand";
|
||||
|
||||
private final int customPayloadId;
|
||||
private final int configCustomPayloadId;
|
||||
|
||||
public BrandCustomPayloadPacketHandler(ProxyConnection proxyConnection) {
|
||||
super(proxyConnection);
|
||||
|
||||
this.customPayloadId = MCPackets.S2C_PLUGIN_MESSAGE.getId(proxyConnection.getClientVersion().getVersion());
|
||||
this.configCustomPayloadId = MCPackets.S2C_CONFIG_CUSTOM_PAYLOAD.getId(proxyConnection.getClientVersion().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleP2S(IPacket packet, List<ChannelFutureListener> listeners) {
|
||||
if (packet instanceof UnknownPacket unknownPacket
|
||||
&& (unknownPacket.packetId == this.customPayloadId && this.proxyConnection.getP2sConnectionState() == ConnectionState.PLAY
|
||||
|| unknownPacket.packetId == this.configCustomPayloadId && this.proxyConnection.getP2sConnectionState() == ConnectionState.CONFIGURATION)
|
||||
&& this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
final ByteBuf data = Unpooled.wrappedBuffer(unknownPacket.data);
|
||||
final String channel = PacketTypes.readString(data, Short.MAX_VALUE); // channel
|
||||
if (Key.namespaced(channel).equals(BRAND_CHANNEL) || channel.equals(LEGACY_BRAND_CHANNEL)) {
|
||||
final String brand = PacketTypes.readString(data, Short.MAX_VALUE);
|
||||
final String newBrand = "ViaProxy (" + this.proxyConnection.getClientVersion().getName() + ") -> " + brand + " §r(" + this.proxyConnection.getServerVersion().getName() + ")";
|
||||
|
||||
final ByteBuf newCustomPayloadData = Unpooled.buffer();
|
||||
PacketTypes.writeString(newCustomPayloadData, channel); // channel
|
||||
PacketTypes.writeString(newCustomPayloadData, newBrand); // data
|
||||
unknownPacket.data = ByteBufUtil.getBytes(newCustomPayloadData);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -34,11 +34,11 @@ import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomPayloadPacketHandler extends PacketHandler {
|
||||
public class OpenAuthModPacketHandler extends PacketHandler {
|
||||
|
||||
private final int customPayloadId;
|
||||
|
||||
public CustomPayloadPacketHandler(ProxyConnection proxyConnection) {
|
||||
public OpenAuthModPacketHandler(ProxyConnection proxyConnection) {
|
||||
super(proxyConnection);
|
||||
|
||||
this.customPayloadId = MCPackets.C2S_PLUGIN_MESSAGE.getId(proxyConnection.getClientVersion().getVersion());
|
Loading…
Reference in New Issue
Block a user