Skip to content

Commit

Permalink
Merge pull request #778 from THEXN/master
Browse files Browse the repository at this point in the history
fix:zhi玩家管理和ezperm
  • Loading branch information
THEXN authored Jan 31, 2025
2 parents d5f17cc + 018847f commit a1b600f
Show file tree
Hide file tree
Showing 11 changed files with 706 additions and 675 deletions.
96 changes: 48 additions & 48 deletions src/Ezperm/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
using Newtonsoft.Json;
using LazyAPI.Attributes;
using LazyAPI.ConfigFiles;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using TShockAPI;

namespace Ezperm;

internal class GroupInfo
[Config]
internal class Configuration : JsonConfigBase<Configuration>
{
[JsonProperty("组名字")]
public string Name { get; set; } = "";
[JsonProperty("添加的权限")]
public List<string> AddPermissions { get; set; } = new();
[JsonProperty("删除的权限")]
public List<string> DelPermissions { get; set; } = new();
}
protected override string Filename => "ezperm";
internal class GroupInfo
{
[LocalizedPropertyName(CultureType.Chinese, "组名字")]
[LocalizedPropertyName(CultureType.English, "Name")]
public string Name { get; set; } = "";

internal class Configuration
{
public static readonly string FilePath = Path.Combine(TShock.SavePath, "ezperm.json");
[LocalizedPropertyName(CultureType.Chinese, "父组")]
[LocalizedPropertyName(CultureType.English, "Parent")]
public string Parent { get; set; } = "";

public List<GroupInfo> Groups { get; set; } = new();
[LocalizedPropertyName(CultureType.Chinese, "添加的权限")]
[LocalizedPropertyName(CultureType.English, "AddPermissions")]
public List<string> AddPermissions { get; set; } = new List<string>();

public void Write(string path)
{
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write))
{
var str = JsonConvert.SerializeObject(this, Formatting.Indented);
using (var sw = new StreamWriter(fs))
{
sw.Write(str);
}
}
[LocalizedPropertyName(CultureType.Chinese, "删除的权限")]
[LocalizedPropertyName(CultureType.English, "DelPermissions")]
public List<string> DelPermissions { get; set; } = new List<string>();
}

public static Configuration Read(string path)
[LocalizedPropertyName(CultureType.Chinese, "组列表", Order = -3)]
[LocalizedPropertyName(CultureType.English, "Groups", Order = -3)]
public List<GroupInfo> Groups { get; set; } = new List<GroupInfo>();

protected override void SetDefault()
{
if (!File.Exists(path))
this.Groups = new List<GroupInfo>
{
// If the file doesn't exist, create a default configuration
var defaultConfig = new Configuration
new GroupInfo
{
Groups = new List<GroupInfo>
Name = "default",
Parent = "guest",
AddPermissions = new List<string>
{
new GroupInfo
{
Name = "default",
AddPermissions = new List<string> { "tshock.world.movenpc","tshock.world.time.usesundial", "tshock.tp.pylon", "tshock.tp.demonconch", "tshock.tp.magicconch", "tshock.tp.tppotion", "tshock.tp.rod","tshock.tp.wormhole","tshock.npc.startdd2", "tshock.npc.spawnpets", "tshock.npc.summonboss","tshock.npc.startinvasion","tshock.npc.hurttown" },
DelPermissions = new List<string> { "tshock.admin" }
}
}
};

defaultConfig.Write(path);
return defaultConfig;
}

using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (var sr = new StreamReader(fs))
{
var cf = JsonConvert.DeserializeObject<Configuration>(sr.ReadToEnd())!;
return cf;
"tshock.world.movenpc",
"tshock.world.time.usesundial",
"tshock.tp.pylon",
"tshock.tp.demonconch",
"tshock.tp.magicconch",
"tshock.tp.tppotion",
"tshock.tp.rod",
"tshock.tp.wormhole",
"tshock.npc.startdd2",
"tshock.npc.spawnpets",
"tshock.npc.summonboss",
"tshock.npc.startinvasion",
"tshock.npc.hurttown"
},
DelPermissions = new List<string> { "tshock.admin" }
}
}
};
}
}
57 changes: 36 additions & 21 deletions src/Ezperm/Ezperm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Terraria;
using LazyAPI;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.DB;
Expand All @@ -7,62 +8,76 @@
namespace Ezperm;

[ApiVersion(2, 1)]
public class Ezperm : TerrariaPlugin
public class Ezperm : LazyPlugin
{
public override string Name => System.Reflection.Assembly.GetExecutingAssembly().GetName().Name!;
public override string Author => "大豆子,肝帝熙恩优化1449";
public override string Description => GetString("一个指令帮助小白给初始服务器添加缺失的权限,还可以批量添删权限");
public override Version Version => new Version(1, 2, 8);
internal static Configuration Config = null!;
public override Version Version => new Version(1, 2, 9);
public Ezperm(Main game) : base(game)
{

}
private static void LoadConfig()
{

Config = Configuration.Read(Configuration.FilePath);
Config.Write(Configuration.FilePath);

}
private static void ReloadConfig(ReloadEventArgs args)
{
LoadConfig();
args.Player?.SendSuccessMessage(GetString("[Ezperm] 重新加载配置完毕。"));
}
public override void Initialize()
{
GeneralHooks.ReloadEvent += ReloadConfig;
Commands.ChatCommands.Add(new Command("inperms.admin", this.Cmd, "inperms", "批量改权限"));
LoadConfig();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
Commands.ChatCommands.RemoveAll(x => x.CommandDelegate == this.Cmd);
GeneralHooks.ReloadEvent -= ReloadConfig;
}
base.Dispose(disposing);
}

private void Cmd(CommandArgs args)
{
foreach (var groupInfo in Config.Groups)
foreach (var groupInfo in Configuration.Instance.Groups)
{
var groupName = groupInfo.Name;

// 检查组是否存在,如果不存在则创建
if (TShock.Groups.GetGroupByName(groupName) == null)
{
try
{
TShock.Groups.AddGroup(groupName, null, "", Group.defaultChatColor);
// 如果父组为空字符串,则不设置父组
var parentGroup = string.IsNullOrWhiteSpace(groupInfo.Parent) ? null : groupInfo.Parent;
TShock.Groups.AddGroup(groupName, parentGroup, "", Group.defaultChatColor);
args.Player.SendSuccessMessage(GetString($"组 {groupName} 不存在,已创建该组。") + "\r\n");
}
catch (GroupManagerException ex)
{
args.Player.SendErrorMessage(ex.ToString());
}
}
else
{
// 如果组已存在,更新父组
if (!string.IsNullOrWhiteSpace(groupInfo.Parent))
{
try
{
var group = TShock.Groups.GetGroupByName(groupName);
var newParentGroup = groupInfo.Parent;

// 如果父组为 "null",则将父组设置为空
if (groupInfo.Parent.Equals("null", StringComparison.OrdinalIgnoreCase))
{
newParentGroup = null;
}

TShock.Groups.UpdateGroup(groupName, newParentGroup, group.Permissions, group.ChatColor, group.Suffix, group.Prefix);
args.Player.SendSuccessMessage(GetString($"成功将组 {groupName} 的父组设置为 {newParentGroup ?? "空"}。") + "\r\n");
}
catch (GroupManagerException ex)
{
args.Player.SendErrorMessage(ex.ToString());
}
}
}

// 添加权限
if (groupInfo.AddPermissions.Count > 0)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Ezperm/Ezperm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

<Import Project="..\..\template.targets" />

<ItemGroup>
<ProjectReference Include="..\LazyAPI\LazyAPI.csproj" />
</ItemGroup>

</Project>
13 changes: 7 additions & 6 deletions src/Ezperm/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
{
"Groups": [
{
"组名字": "default",
"添加的权限": [
"Name": "default",
"Parent": "guest",
"AddPermissions": [
"tshock.world.movenpc",
"tshock.world.time.usesundial",
"tshock.tp.pylon",
"tshock.tp.demonconch",
"tshock.tp.magicconch",
"tshock.tp.tppotion",
"tshock.tp.rod",
"tshock.npc.startdd2",
"tshock.tp.wormhole",
"tshock.npc.startdd2",
"tshock.npc.spawnpets",
"tshock.npc.summonboss",
"tshock.npc.startinvasion",
"tshock.npc.spawnpets",
"tshock.world.time.usesundial",
"tshock.npc.hurttown"
],
"删除的权限": [
"DelPermissions": [
"tshock.admin"
]
}
Expand Down
12 changes: 8 additions & 4 deletions src/Ezperm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@
> 配置文件位置:tshock/ezperm.json
```json5
{
"Groups": [
"组列表": [
{
"组名字": "default",
"父组": "guest",
"添加的权限": [
"tshock.world.movenpc",
"tshock.world.time.usesundial",
"tshock.tp.pylon",
"tshock.tp.demonconch",
"tshock.tp.magicconch",
"tshock.tp.tppotion",
"tshock.tp.rod",
"tshock.npc.startdd2",
"tshock.tp.wormhole",
"tshock.npc.startdd2",
"tshock.npc.spawnpets",
"tshock.npc.summonboss",
"tshock.npc.startinvasion",
"tshock.npc.spawnpets",
"tshock.world.time.usesundial"
"tshock.npc.hurttown"
],
"删除的权限": [
"tshock.admin"
Expand All @@ -43,6 +45,8 @@
## 更新日志

```
v1.2.9
使用lazyapi,添加父组预设
v1.2.8
添加 GetString
v1.2.7
Expand Down
2 changes: 1 addition & 1 deletion src/TShockConfigMultiLang/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,4 @@ public class Config : JsonConfigBase<Config>
public Dictionary<string, SecureRest.TokenData> ApplicationRestTokens = TShock.Config.Settings.ApplicationRestTokens;

#endregion
}
}
25 changes: 13 additions & 12 deletions src/TShockConfigMultiLang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@
"是否启用报Debug日志": false,
"禁用登录后进入": false,
"允许箱子中物品堆叠超出限制": false,
"世界图格提供器": "default", // heaptile/constileation
"世界图格提供器": "default",
"启用自动保存": true,
"自动保存世界广播提示": true,
"是否显示备份自动保存消息": true,
"自动备份间隔": 10, // 分钟
"备份保留时间": 140, // 分钟
"自动备份间隔": 10,
"备份保留时间": 240,
"崩溃时保存世界": true,
"最后玩家退出时保存世界": true,
"事件入侵乘数": 1,
"默认刷怪生成上限": 5,
"默认刷怪率": 600,
"事件无限入侵": false,
"PVP模式": "normal", // normal/always/disabled/pvpwithnoteam
"PVP模式": "normal",
"启用出生点保护": true,
"出生点保护范围": 10, //
"出生点保护范围": 10,
"启用放置物块范围检查": true,
"启用强制硬核角色": false,
"启用强制中核角色": false,
"启用强制软核角色": false,
"禁止建筑": false, // antibuild
"禁止困难模式": false, // 不会通过肉山或 /starthardmode 命令激活
"禁止生成地牢守卫": false, // 禁止地牢守卫生成,取而代之的是将玩家发送回生成点
"禁止建筑": false,
"禁止困难模式": false,
"禁止生成地牢守卫": false,
"禁止血月小丑炸弹": false,
"禁止雪人雪块弹幕": false,
"禁止玩家死亡生成墓碑": true,
"禁止机械骷髅王炸弹": true,
"强制世界时间": "normal", // normal/day/night
"禁止机械骷髅王炸弹": false,
"强制世界时间": "normal",
"禁止PVP隐身药水": false,
"未登录时禁止移动范围": 10,
"保护区域箱子": false,
Expand Down Expand Up @@ -101,7 +101,7 @@
"用户必须登录": false,
"允许玩家登录账号与角色名不符": true,
"允许玩家注册账号与角色名不符": false,
"密码最少长度": 4, // 最少为4
"密码最少长度": 4,
"使用的BCrypt工作因子": 7,
"禁止UUID自动登录": false,
"踢出不发送UUID到服务器的玩家": false,
Expand Down Expand Up @@ -167,7 +167,8 @@
## 更新日志

```
暂无
v1.0.3
用指令会先加载现在的配置,再同步
```

## 反馈
Expand Down
Loading

0 comments on commit a1b600f

Please sign in to comment.