Skip to content

Commit

Permalink
Add a protocol check option in the config
Browse files Browse the repository at this point in the history
  • Loading branch information
SAGESSE-CN committed Feb 11, 2023
1 parent 8436bb2 commit a842068
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static class Common {
public static int blockTaskRate = 10; // 10 blocks/t
public static boolean lockDyesOnSkins = false;
public static boolean instancedDyeTable = false;
public static boolean enableProtocolCheck = true;
public static int serverSkinSendRate = 4000;
public static boolean serverCompressesSkins = true;
public static int enableEmbeddedSkinRenderer = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public Common() {
defineInRange("blockTaskRate", 10, 1, 1000, "Max number of processing blocks in per tick.").bind(v -> blockTaskRate = v, () -> blockTaskRate);
define("lockDyesOnSkins", false, "When enabled players will not be able to remove dyes from skins in the dye table.").bind(v -> lockDyesOnSkins = v, () -> lockDyesOnSkins);
define("instancedDyeTable", false, "If true the dye table will be instanced for each player. Items will be dropped when the table is closed.").bind(v -> instancedDyeTable = v, () -> instancedDyeTable);
define("enableProtocolCheck", true, "If enabled the server will check the client protocol version in the login.", "Highly recommended unless the server does not support handshake.").bind(v -> enableProtocolCheck = v, () -> enableProtocolCheck);
defineInRange("serverModelSendRate", 4000, 0, 8000, "The maximum number of skins the server is allow to send every minute.", "Less that 1 equals unlimited. (not recommended may cause bandwidth and cpu spikes on the server)").bind(n -> serverSkinSendRate = n, () -> serverSkinSendRate);
define("serverCompressesSkins", true, "If enabled the server will compress skins before sending them to clients.", "Highly recommended unless the server has a very slow CPU.").bind(v -> serverCompressesSkins = v, () -> serverCompressesSkins);
defineInRange("enableEmbeddedSkinRenderer", 0, 0, 2, "Using embedded skin renderer to replace the original item renderer.", "0 = use client config", "1 = always disable", "2 = always enable").bind(v -> enableEmbeddedSkinRenderer = v, () -> enableEmbeddedSkinRenderer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import moe.plushie.armourers_workshop.api.network.IClientPacketHandler;
import moe.plushie.armourers_workshop.api.network.IServerPacketHandler;
import moe.plushie.armourers_workshop.core.network.CustomPacket;
import moe.plushie.armourers_workshop.init.ModConfig;
import moe.plushie.armourers_workshop.init.ModConstants;
import moe.plushie.armourers_workshop.init.environment.EnvironmentExecutor;
import moe.plushie.armourers_workshop.init.environment.EnvironmentType;
Expand Down Expand Up @@ -116,17 +117,19 @@ public static class NetworkDispatcher implements IServerPacketHandler, IClientPa
}

public void startServerHandshake(ServerLoginPacketListenerImpl handler, MinecraftServer server, PacketSender sender, ServerLoginNetworking.LoginSynchronizer synchronizer) {
sender.sendPacket(channelName, PacketByteBufs.empty());
if (ModConfig.Common.enableProtocolCheck) {
sender.sendPacket(channelName, PacketByteBufs.empty());
}
}

public void onServerHandshake(MinecraftServer server, ServerLoginPacketListenerImpl handler, boolean understood, FriendlyByteBuf buf, ServerLoginNetworking.LoginSynchronizer synchronizer, PacketSender responseSender) {
if (understood) {
String version = buf.readUtf(Short.MAX_VALUE);
if (version.equals(channelVersion)) {
return;
}
}
handler.disconnect(Component.literal("Please install correct Armourers Workshop to play on this server!"));
// if (understood) {
// String version = buf.readUtf(Short.MAX_VALUE);
// if (version.equals(channelVersion)) {
// return;
// }
// }
// handler.disconnect(Component.literal("Please install correct Armourers Workshop to play on this server!"));
}

@Environment(value = EnvType.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package moe.plushie.armourers_workshop.compatibility.forge;

import moe.plushie.armourers_workshop.init.ModConfig;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -17,7 +18,17 @@ public AbstractForgeNetworkManager() {
}

public static void register(ResourceLocation channelName, String channelVersion, Object dispatcher) {
EventNetworkChannel channel = NetworkRegistry.ChannelBuilder.named(channelName).networkProtocolVersion(() -> channelVersion).clientAcceptedVersions(cv -> true).serverAcceptedVersions(channelVersion::equals).eventNetworkChannel();
EventNetworkChannel channel = NetworkRegistry.ChannelBuilder
.named(channelName)
.networkProtocolVersion(() -> channelVersion)
.clientAcceptedVersions(sv -> true)
.serverAcceptedVersions(cv -> {
if (ModConfig.Common.enableProtocolCheck) {
return cv.equals(channelVersion);
}
return true;
})
.eventNetworkChannel();
channel.registerObject(dispatcher);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package moe.plushie.armourers_workshop.compatibility.forge;

import moe.plushie.armourers_workshop.api.annotation.Available;
import moe.plushie.armourers_workshop.init.ModConfig;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -19,7 +20,17 @@ public AbstractForgeNetworkManager() {
}

public static void register(ResourceLocation channelName, String channelVersion, Object dispatcher) {
EventNetworkChannel channel = NetworkRegistry.ChannelBuilder.named(channelName).networkProtocolVersion(() -> channelVersion).clientAcceptedVersions(cv -> true).serverAcceptedVersions(channelVersion::equals).eventNetworkChannel();
EventNetworkChannel channel = NetworkRegistry.ChannelBuilder
.named(channelName)
.networkProtocolVersion(() -> channelVersion)
.clientAcceptedVersions(sv -> true)
.serverAcceptedVersions(cv -> {
if (ModConfig.Common.enableProtocolCheck) {
return cv.equals(channelVersion);
}
return true;
})
.eventNetworkChannel();
channel.registerObject(dispatcher);
}

Expand Down

0 comments on commit a842068

Please sign in to comment.