From ccdeb2cc15aacbf7cf71ef5f543dcc2afe353fef Mon Sep 17 00:00:00 2001 From: cxfm666 <61831881+cxfm666@users.noreply.github.com> Date: Sun, 14 Jul 2024 15:01:00 +0800 Subject: [PATCH] Add Account Command --- Command/Command/Cmd/CommandAccount.cs | 62 +++++++++++++++++++ .../Message/LanguageCHS.cs | 16 ++++- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Command/Command/Cmd/CommandAccount.cs diff --git a/Command/Command/Cmd/CommandAccount.cs b/Command/Command/Cmd/CommandAccount.cs new file mode 100644 index 00000000..d44f3f37 --- /dev/null +++ b/Command/Command/Cmd/CommandAccount.cs @@ -0,0 +1,62 @@ +using EggLink.DanhengServer.Data.Custom; +using EggLink.DanhengServer.Data; +using EggLink.DanhengServer.Internationalization; +using EggLink.DanhengServer.Util; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EggLink.DanhengServer.Database.Account; + +namespace EggLink.DanhengServer.Command.Cmd +{ + [CommandInfo("account", "Game.Command.Account.Desc", "Game.Command.Account.Usage", permission: "egglink.manage")] + public class CommandAccount : ICommand + { + [CommandMethod("create")] + public void CreateAccount(CommandArg arg) + { + if (arg.Args.Count < 2) + { + arg.SendMsg(I18nManager.Translate("Game.Command.Notice.InvalidArguments")); + return; + } + + string account = arg.Args[1]; + int uid = 0; + + if (arg.Args.Count > 2) + { + if (!int.TryParse(arg.Args[2], out uid)) + { + arg.SendMsg(I18nManager.Translate("Game.Command.Notice.InvalidUid")); + return; + } + } + + if (AccountData.GetAccountByUserName(account) != null) + { + arg.SendMsg(string.Format(I18nManager.Translate("Game.Command.Account.DuplicateAccount"), account)); + return; + } + + if (uid != 0 && AccountData.GetAccountByUid(uid) != null) + { + arg.SendMsg(string.Format(I18nManager.Translate("Game.Command.Account.DuplicateUID"), uid)); + return; + } + + try + { + AccountHelper.CreateAccount(account, uid); + arg.SendMsg(I18nManager.Translate("Game.Command.Account.CreateSuccess", account)); + } + catch (Exception ex) + { + arg.SendMsg(I18nManager.Translate("Game.Command.Account.CreateError", ex.Message)); + return; + } + } + } +} diff --git a/Common/Internationalization/Message/LanguageCHS.cs b/Common/Internationalization/Message/LanguageCHS.cs index 322b00fc..ce1175ac 100644 --- a/Common/Internationalization/Message/LanguageCHS.cs +++ b/Common/Internationalization/Message/LanguageCHS.cs @@ -114,6 +114,7 @@ namespace EggLink.DanhengServer.Internationalization.Message public UnlockAllTextCHS UnlockAll { get; } = new(); public MailTextCHS Mail { get; } = new(); public RaidTextCHS Raid { get; } = new(); + public AccountTextCHS Account { get; } = new(); } #endregion @@ -363,7 +364,20 @@ namespace EggLink.DanhengServer.Internationalization.Message public string Usage { get; } = "/raid "; public string Leaved { get; } = "已离开临时场景!"; } - + /// + /// path: Game.Command.Account + /// + public class AccountTextCHS + { + public string Desc { get; } = "创建账号"; + public string Usage { get; } = "/account create <用户名>"; + public string InvalidUid { get; } = "无效UID参数! "; + public string CreateError { get; } = "出现内部错误 {0} "; + public string CreateSuccess { get; } = "新账号 {0} 创建成功!"; + public string DuplicateAccount { get; } = "账号 {0} 已存在!"; + public string DuplicateUID { get; } = "UID {0} 已存在!"; + public string DataError { get; } = "新账号获取失败! {0}!"; + } #endregion #endregion