Skip to content

Commit

Permalink
Merge pull request #211 from 1242509682/master
Browse files Browse the repository at this point in the history
更新:增加hreset指令清理数据库表
  • Loading branch information
Controllerdestiny authored Jun 16, 2024
2 parents c47c917 + d841675 commit 840325b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 6 additions & 0 deletions History/Commands/HistoryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ public override void Execute()
this.sender.SendErrorMessage("没有查询到这个图格的修改历史.");
}
}

// 清空数据表
public static bool ClearData()
{
return History.Database.Query("DELETE FROM History") != 0;
}
}
41 changes: 39 additions & 2 deletions History/History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,7 @@ void OnInitialize(EventArgs e)
TShockAPI.Commands.ChatCommands.Add(new Command("history.reenact", this.Reenact, "reenact", "复现"));
TShockAPI.Commands.ChatCommands.Add(new Command("history.rollback", this.Rollback, "rollback", "回溯"));
TShockAPI.Commands.ChatCommands.Add(new Command("history.rollback", this.Undo, "rundo", "撤销"));
TShockAPI.Commands.ChatCommands.Add(new Command("history.admin", this.ResetCmd, "hreset", "重置历史"));
var sqlcreator = new SqlTableCreator(Database, new SqliteQueryCreator());
sqlcreator.EnsureTableStructure(new SqlTable("History",
new SqlColumn("Time", MySqlDbType.Int32),
Expand Down Expand Up @@ -1425,7 +1426,8 @@ void OnInitialize(EventArgs e)
}
this.CommandQueueThread = new Thread(this.QueueCallback!);
this.CommandQueueThread.Start();
}
}

void OnSaveWorld(WorldSaveEventArgs e)
{
new SaveCommand(Actions.ToArray()).Execute();
Expand Down Expand Up @@ -1466,7 +1468,9 @@ void HistoryCmd(CommandArgs e)
{
if (e.Parameters.Count != 2 && e.Parameters.Count != 3)
{
e.Player.SendErrorMessage("用法错误! 正确用法: /history [账号名] [时间] [范围]");
e.Player.SendErrorMessage(
"用法错误! 正确用法: \n" +
"/history [账号名] [时间] [范围]");
return;
}
var radius = 10000;
Expand Down Expand Up @@ -1558,4 +1562,37 @@ void Undo(CommandArgs e)
e.Player.SendErrorMessage("没有要撤消的内容!");
}
}

#region 使用指令清理数据库
private void ResetCmd(CommandArgs e)
{
if (e.Parameters.Count > 0) {e.Player.SendErrorMessage("用法错误! 正确用法: /hreset"); return;}
else
{
if (!e.Player.HasPermission("history.admin"))
{
e.Player.SendErrorMessage("你没有重置【History】数据表的权限。");
TShock.Log.ConsoleInfo($"{e.Player.Name}试图执行 [History] 数据重置指令");
return;
}
else
{
ClearAllData(e);
return;
}
}
}

private static void ClearAllData(CommandArgs args)
{
if (HistoryCommand.ClearData())
{
TShock.Utils.Broadcast($"[History] 数据库已被 [{args.Player.Name}] 成功清除", Color.DarkRed);
}
else
{
TShock.Log.ConsoleInfo("[History] 数据库清除失败");
}
}
#endregion
}
1 change: 1 addition & 0 deletions History/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
| /reenact [账号名] [时间] [范围] | /复现 | history.reenact | 在时间跨度和半径内重新创建玩家的所有动作 |
| /rollback [账号名] [时间] [范围] | /回溯 | history.rollback | 在时间跨度和半径内还原玩家的所有动作 |
| /rollback [账号名] [时间] [范围] | /撤销 | history.rollback | 在时间跨度和半径内还原玩家的所有动作 |
| /hreset |/重置历史| history.admin | 重置数据库表 |

## 配置

Expand Down

0 comments on commit 840325b

Please sign in to comment.