From 989b64cb3d9ec66c7e6e7b549ecfdf2b1eb325d6 Mon Sep 17 00:00:00 2001 From: SHIHUANG214 Date: Fri, 27 Jun 2025 21:30:21 +0800 Subject: [PATCH] feat(Script/Commands): allow to pass email in account create (#22310) Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> --- data/sql/updates/pending_db_world/command.sql | 1 + .../database/Database/Implementation/LoginDatabase.cpp | 2 +- src/server/game/Accounts/AccountMgr.cpp | 8 +++++++- src/server/game/Accounts/AccountMgr.h | 2 +- src/server/scripts/Commands/cs_account.cpp | 7 ++++++- 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 data/sql/updates/pending_db_world/command.sql diff --git a/data/sql/updates/pending_db_world/command.sql b/data/sql/updates/pending_db_world/command.sql new file mode 100644 index 000000000..78fd5fab2 --- /dev/null +++ b/data/sql/updates/pending_db_world/command.sql @@ -0,0 +1 @@ +UPDATE `command` SET `help`='Syntax: .account create $account $password $email\r\n\r\nCreate account and set password to it.\r\n$email is optional, can be left blank.' WHERE `name`='account create'; diff --git a/src/server/database/Database/Implementation/LoginDatabase.cpp b/src/server/database/Database/Implementation/LoginDatabase.cpp index 5b001b98c..a772890b5 100644 --- a/src/server/database/Database/Implementation/LoginDatabase.cpp +++ b/src/server/database/Database/Implementation/LoginDatabase.cpp @@ -78,7 +78,7 @@ void LoginDatabaseConnection::DoPrepareStatements() PrepareStatement(LOGIN_DEL_REALM_CHARACTERS, "DELETE FROM realmcharacters WHERE acctid = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_REP_REALM_CHARACTERS, "REPLACE INTO realmcharacters (numchars, acctid, realmid) VALUES (?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(LOGIN_SEL_SUM_REALM_CHARACTERS, "SELECT SUM(numchars) FROM realmcharacters WHERE acctid = ?", CONNECTION_ASYNC); - PrepareStatement(LOGIN_INS_ACCOUNT, "INSERT INTO account(username, salt, verifier, expansion, joindate) VALUES(?, ?, ?, ?, NOW())", CONNECTION_ASYNC); + PrepareStatement(LOGIN_INS_ACCOUNT, "INSERT INTO account(username, salt, verifier, expansion, reg_mail, email, joindate) VALUES(?, ?, ?, ?, ?, ?, NOW())", CONNECTION_ASYNC); PrepareStatement(LOGIN_INS_REALM_CHARACTERS_INIT, "INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_EXPANSION, "UPDATE account SET expansion = ? WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK, "UPDATE account SET locked = ? WHERE id = ?", CONNECTION_ASYNC); diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index 2eefbc3ee..daa82f804 100644 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -27,7 +27,7 @@ namespace AccountMgr { - AccountOpResult CreateAccount(std::string username, std::string password) + AccountOpResult CreateAccount(std::string username, std::string password, std::string email /*= ""*/) { if (utf8length(username) > MAX_ACCOUNT_STR) return AOR_NAME_TOO_LONG; // username's too long @@ -35,8 +35,12 @@ namespace AccountMgr if (utf8length(password) > MAX_PASS_STR) return AOR_PASS_TOO_LONG; // password's too long + if (utf8length(email) > MAX_EMAIL_STR) + return AOR_EMAIL_TOO_LONG; // email is too long + Utf8ToUpperOnlyLatin(username); Utf8ToUpperOnlyLatin(password); + Utf8ToUpperOnlyLatin(email); if (GetId(username)) return AOR_NAME_ALREADY_EXIST; // username does already exist @@ -48,6 +52,8 @@ namespace AccountMgr stmt->SetData(1, salt); stmt->SetData(2, verifier); stmt->SetData(3, uint8(sWorld->getIntConfig(CONFIG_EXPANSION))); + stmt->SetData(4, email); + stmt->SetData(5, email); LoginDatabase.Execute(stmt); diff --git a/src/server/game/Accounts/AccountMgr.h b/src/server/game/Accounts/AccountMgr.h index 15af979a6..57b6c7432 100644 --- a/src/server/game/Accounts/AccountMgr.h +++ b/src/server/game/Accounts/AccountMgr.h @@ -38,7 +38,7 @@ enum AccountOpResult namespace AccountMgr { - AccountOpResult CreateAccount(std::string username, std::string password); + AccountOpResult CreateAccount(std::string username, std::string password, std::string email = ""); AccountOpResult DeleteAccount(uint32 accountId); AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::string newPassword); AccountOpResult ChangePassword(uint32 accountId, std::string newPassword); diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index b69083cb2..22859f019 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -271,10 +271,15 @@ public: ///- %Parse the command line arguments char* accountName = strtok((char*)args, " "); char* password = strtok(nullptr, " "); + char* email = strtok(nullptr, " "); + if (!accountName || !password) return false; - AccountOpResult result = AccountMgr::CreateAccount(std::string(accountName), std::string(password)); + // if email is not specified, use empty string + std::string emailStr = email ? email : ""; + + AccountOpResult result = AccountMgr::CreateAccount(std::string(accountName), std::string(password), emailStr); switch (result) { case AOR_OK: