Skip to content

Commit

Permalink
add a few settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Sep 23, 2024
1 parent ec8ae3e commit b7c8346
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import fi.dy.masa.servux.Reference;
import fi.dy.masa.servux.mixin.IMixinMobEntity;
import fi.dy.masa.servux.settings.IServuxSetting;
import fi.dy.masa.servux.settings.ServuxBoolSetting;
import fi.dy.masa.servux.settings.ServuxIntSetting;
import fi.dy.masa.servux.settings.ServuxStringListSetting;

Expand All @@ -55,7 +56,8 @@ public class DebugDataProvider extends DataProviderBase

private final ServuxIntSetting basePermissionLevel = new ServuxIntSetting(this, "permission_level", 0, 4, 0);
private final ServuxStringListSetting enabledDebugPackets = new ServuxStringListSetting(this, "debug_enabled", List.of("chunk_watcher", "poi", "pathfinding", "neighbor_update", "structures", "goal_selector", "raids", "brain", "bees", "breeze", "game_event"));
private final List<IServuxSetting<?>> settings = List.of(this.basePermissionLevel, this.enabledDebugPackets);
private final ServuxBoolSetting enableServerDevelopmentMode = new ServuxBoolSetting(this, "server_development_mode", false);
private final List<IServuxSetting<?>> settings = List.of(this.basePermissionLevel, this.enabledDebugPackets, this.enableServerDevelopmentMode);

protected DebugDataProvider()
{
Expand Down Expand Up @@ -107,6 +109,11 @@ public boolean hasPermission(ServerPlayerEntity player)
return Permissions.check(player, Reference.MOD_ID + ".debug_data", this.basePermissionLevel.getValue());
}

public boolean isServerDevelopmentMode()
{
return this.enableServerDevelopmentMode.getValue();
}

private void sendToAll(ServerWorld world, CustomPayload payload)
{
if (this.isEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import fi.dy.masa.servux.network.packet.ServuxEntitiesHandler;
import fi.dy.masa.servux.network.packet.ServuxEntitiesPacket;
import fi.dy.masa.servux.settings.IServuxSetting;
import fi.dy.masa.servux.settings.ServuxBoolSetting;
import fi.dy.masa.servux.settings.ServuxIntSetting;

public class EntitiesDataProvider extends DataProviderBase
Expand All @@ -24,7 +25,9 @@ public class EntitiesDataProvider extends DataProviderBase
protected ServuxIntSetting permissionLevel = new ServuxIntSetting(this,
"permission_level",
0, 4, 0);
private List<IServuxSetting<?>> settings = List.of(this.permissionLevel);
protected ServuxBoolSetting nbtQueryOverride = new ServuxBoolSetting(this, "nbt_query_override", false);
protected ServuxIntSetting nbtQueryPermissionLevel = new ServuxIntSetting(this, "nbt_query_permission_level", 2, 4, 0);
private List<IServuxSetting<?>> settings = List.of(this.permissionLevel, this.nbtQueryOverride, this.nbtQueryPermissionLevel);

protected EntitiesDataProvider()
{
Expand Down Expand Up @@ -81,7 +84,7 @@ public void sendMetadata(ServerPlayerEntity player)
return;
}

//Servux.logger.warn("entityDataChannel: sendMetadata to player {}", player.getName().getLiteralString());
Servux.debugLog("entityDataChannel: sendMetadata to player {}", player.getName().getLiteralString());

// Sends Metadata handshake, it doesn't succeed the first time, so using networkHandler
if (player.networkHandler != null)
Expand Down Expand Up @@ -138,6 +141,21 @@ public void handleBulkClientRequest(ServerPlayerEntity player, int transactionId
// todo
}

public boolean hasNbtQueryOverride()
{
return this.nbtQueryOverride.getValue();
}

public boolean hasNbtQueryPermission(ServerPlayerEntity player)
{
if (this.nbtQueryOverride.getValue())
{
return Permissions.check(player, this.permNode+".nbt_query_override", this.nbtQueryPermissionLevel.getValue());
}

return player.hasPermissionLevel(2);
}

@Override
public boolean hasPermission(ServerPlayerEntity player)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void sendMetadata(ServerPlayerEntity player)
return;
}

//Servux.logger.warn("LitematicsDataProvider#sendMetadata: sendMetadata to player {}", player.getName().getLiteralString());
Servux.debugLog("litematic_data: sendMetadata to player {}", player.getName().getLiteralString());

// Sends Metadata handshake, it doesn't succeed the first time, so using networkHandler
if (player.networkHandler != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public boolean register(ServerPlayerEntity player)
NbtCompound nbt = new NbtCompound();
nbt.copyFrom(this.metadata);

Servux.debugLog("structure_bounding_boxes: sending Metadata to player {}", player.getName().getLiteralString());

HANDLER.sendPlayPayload(handler, new ServuxStructuresPacket.Payload(new ServuxStructuresPacket(ServuxStructuresPacket.Type.PACKET_S2C_METADATA, nbt)));
this.initialSyncStructuresToPlayerWithinRange(player, player.getServer().getPlayerManager().getViewDistance()+2, tickCounter);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package fi.dy.masa.servux.dataproviders;

import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import fi.dy.masa.servux.settings.IServuxSetting;
import fi.dy.masa.servux.settings.ServuxIntSetting;
import java.util.List;
import me.lucko.fabric.api.permissions.v0.Permissions;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;

import fi.dy.masa.servux.Reference;
import fi.dy.masa.servux.Servux;
import fi.dy.masa.servux.network.IPluginServerPlayHandler;
import fi.dy.masa.servux.network.ServerPlayHandler;
import fi.dy.masa.servux.network.packet.ServuxTweaksHandler;
import fi.dy.masa.servux.network.packet.ServuxTweaksPacket;
import fi.dy.masa.servux.util.JsonUtils;

import java.util.List;
import fi.dy.masa.servux.settings.IServuxSetting;
import fi.dy.masa.servux.settings.ServuxIntSetting;

public class TweaksDataProvider extends DataProviderBase
{
Expand Down Expand Up @@ -83,7 +81,7 @@ public void sendMetadata(ServerPlayerEntity player)
return;
}

//Servux.logger.warn("tweaksDataChannel: sendMetadata to player {}", player.getName().getLiteralString());
Servux.debugLog("tweaksDataChannel: sendMetadata to player {}", player.getName().getLiteralString());

// Sends Metadata handshake, it doesn't succeed the first time, so using networkHandler
if (player.networkHandler != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,71 @@
package fi.dy.masa.servux.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec3d;

import fi.dy.masa.servux.Servux;
import fi.dy.masa.servux.dataproviders.EntitiesDataProvider;

@Mixin(value = ServerPlayNetworkHandler.class, priority = 1005)
public class MixinServerPlayNetworkHandler
{
@Shadow public ServerPlayerEntity player;

@Redirect(method = "onPlayerInteractBlock", require = 0,
at = @At(value = "INVOKE",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/util/math/Vec3d;subtract(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;"))
private Vec3d servux$removeHitPosCheck(Vec3d hitVec, Vec3d blockCenter)
{
return Vec3d.ZERO;
//return hitVec.subtract(blockCenter);
}

@ModifyConstant(method = "onQueryBlockNbt", constant = @Constant(intValue = 2))
private int servux_onQueryBlockNbt(int constant)
{
if (EntitiesDataProvider.INSTANCE.hasNbtQueryOverride())
{
if (EntitiesDataProvider.INSTANCE.hasNbtQueryPermission(this.player))
{
Servux.debugLog("received NbtQueryBlock request from: {}", this.player.getName().getLiteralString());
return 0;
}
else
{
return 4;
}
}
else
{
return constant;
}
}

@ModifyConstant(method = "onQueryEntityNbt", constant = @Constant(intValue = 2))
private int servux_onQueryEntityNbt(int constant)
{
if (EntitiesDataProvider.INSTANCE.hasNbtQueryOverride())
{
if (EntitiesDataProvider.INSTANCE.hasNbtQueryPermission(this.player))
{
Servux.debugLog("received NbtQueryEntity request from: {}", this.player.getName().getLiteralString());
return 0;
}
else
{
return 4;
}
}
else
{
return constant;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fi.dy.masa.servux.mixin.test;

import net.minecraft.SharedConstants;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import fi.dy.masa.servux.dataproviders.DebugDataProvider;

@Mixin(SharedConstants.class)
public abstract class MixinSharedConstants
{
@Shadow @Mutable
public static boolean isDevelopment;

public MixinSharedConstants() {}

@Inject(method = "<clinit>", at = @At("TAIL"))
private static void servux_enableServerDevelopmentMode(CallbackInfo ci)
{
if (DebugDataProvider.INSTANCE.isEnabled() &&
DebugDataProvider.INSTANCE.isServerDevelopmentMode())
{
isDevelopment = true;
}
}
}
11 changes: 11 additions & 0 deletions src/main/resources/assets/servux/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@

"servux.config.entity_data.permission_level.name": "Permission Level",
"servux.config.entity_data.permission_level.comment": "The permission level required for the Entity data provider, will send entity data to clients with this permission level",
"servux.config.entity_data.nbt_query_override.name": "Nbt Query Packet Permissions Override",
"servux.config.entity_data.nbt_query_override.comment": "Override the default ops level 2 permissions for NbtQuery packets, and set the permissions using \"nbt_query_permission_level\"",
"servux.config.entity_data.nbt_query_permission_level.name": "Nbt Query Permission Level",
"servux.config.entity_data.nbt_query_permission_level.comment": "The permission level required for Nbt Query Packets when \"nbt_query_override\" is enabled",

"servux.config.debug_data.permission_level.name": "Permission Level",
"servux.config.debug_data.permission_level.comment": "The permission level required for the Entity data provider, will send entity data to clients with this permission level",
"servux.config.debug_data.debug_enabled.name": "Debug Info Sender List",
"servux.config.debug_data.debug_enabled.comment": "A configurable list of Debug Info Senders",
"servux.config.debug_data.server_development_mode.name": "Server Development Mode",
"servux.config.debug_data.server_development_mode.comment": "Enable the Vanilla \"isDevelopmentMode\" flag to on",

"servux.config.structure_bounding_boxes.permission_level.name": "Permission Level",
"servux.config.structure_bounding_boxes.permission_level.comment": "The permission level required for the Structure Bounding Boxes data provider",
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/assets/servux/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@

"servux.config.entity_data.permission_level.name": "权限级别",
"servux.config.entity_data.permission_level.comment": "实体数据源所需的权限级别,将向具有该权限级别的玩家端发送实体数据",
"servux.config.entity_data.nbt_query_override.name": "Nbt 查询包权限覆盖",
"servux.config.entity_data.nbt_query_override.comment": "覆盖 NbtQuery 数据包的默认 ops 级别 2 权限,并使用 \"nbt_query_permission_level\" 设置权限",
"servux.config.entity_data.nbt_query_permission_level.name": "Nbt 查询权限级别",
"servux.config.entity_data.nbt_query_permission_level.comment": "启用 \"nbt_query_override\" 时 Nbt 查询包所需的权限级别",

"servux.config.debug_data.permission_level.name": "权限级别",
"servux.config.debug_data.permission_level.comment": "实体数据提供者所需的权限级别,将向具有此权限级别的客户端发送实体数据",
"servux.config.debug_data.debug_enabled.name": "调试信息发送者列表",
"servux.config.debug_data.debug_enabled.comment": "可配置的调试信息发送器列表",
"servux.config.debug_data.server_development_mode.name": "服务器开发模式",
"servux.config.debug_data.server_development_mode.comment": "启用 Vanilla \"isDevelopmentMode\" 标志",

"servux.config.structure_bounding_boxes.permission_level.name": "权限级别",
"servux.config.structure_bounding_boxes.permission_level.comment": "结构边界框数据源所需的权限级别",
Expand All @@ -55,6 +66,8 @@
"servux.config.structure_bounding_boxes.timeout.comment": "结构边界框数据源的超时时间(以刻为单位),将在此时间后重新发送边界框数据",
"servux.config.structure_bounding_boxes.update_interval.name": "更新间隔",
"servux.config.structure_bounding_boxes.update_interval.comment": "结构边界框数据源的更新间隔(以刻为单位),将以此频率检查新区块以发送边界框数据",
"servux.config.structure_bounding_boxes.share_seed.name": "分享世界种子",
"servux.config.structure_bounding_boxes.share_seed.comment": "启用/禁用世界种子与 MiniHUD 共享以显示粘液块",

"servux.litematics.error.insufficent_for_paste": "§cLitematic 粘贴操作权限不足.§r",
"servux.litematics.error.creative_required": "§cLitematic 粘贴操作需要创造模式.§r",
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/mixins.servux.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"IMixinMobEntity",
"MixinBlockItem",
"MixinCommandManager",
"test.MixinDebugInfoSender",
"MixinMain",
"MixinMinecraftDedicatedServer",
"MixinMinecraftServer",
Expand All @@ -17,7 +16,9 @@
"MixinServerPlayNetworkHandler",
"MixinServerWorld",
"MixinWorld",
"MixinWorldChunk"
"MixinWorldChunk",
"test.MixinDebugInfoSender",
"test.MixinSharedConstants"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b7c8346

Please sign in to comment.