Skip to content

Instantly share code, notes, and snippets.

@DasBlub
Created September 4, 2013 20:21
Show Gist options
  • Save DasBlub/6442358 to your computer and use it in GitHub Desktop.
Save DasBlub/6442358 to your computer and use it in GitHub Desktop.
implementation for cmangos/issues#201
commit 6012d86d203158fb6e89d83216a81a92a647abb8
Author: DasBlub <DasBlub@gmail.com>
Date: Wed Sep 4 22:19:12 2013 +0200
Add new optional parameter 'expansion' to command 'account create'
This fixes cmangos/issues#201
diff --git a/sql/mangos.sql b/sql/mangos.sql
index 5b915c3..d5e72e5 100644
--- a/sql/mangos.sql
+++ b/sql/mangos.sql
@@ -488,7 +488,7 @@ LOCK TABLES `command` WRITE;
INSERT INTO `command` VALUES
('account',0,'Syntax: .account\r\n\r\nDisplay the access level of your account.'),
('account characters',3,'Syntax: .account characters [#accountId|$accountName]\r\n\r\nShow list all characters for account selected by provided #accountId or $accountName, or for selected player in game.'),
-('account create',4,'Syntax: .account create $account $password\r\n\r\nCreate account and set password to it.'),
+('account create',4,'Syntax: .account create $account $password [$expansion]\r\n\r\nCreate account and set password to it. Optionally, you may also set another expansion for this account than the defined default value.'),
('account delete',4,'Syntax: .account delete $account\r\n\r\nDelete account with all characters.'),
('account lock',0,'Syntax: .account lock [on|off]\r\n\r\nAllow login from account only from current used IP or remove this requirement.'),
('account onlinelist',4,'Syntax: .account onlinelist\r\n\r\nShow list of online accounts.'),
diff --git a/sql/updates/99999_01_mangos_command.sql b/sql/updates/99999_01_mangos_command.sql
new file mode 100644
index 0000000..508ff46
--- /dev/null
+++ b/sql/updates/99999_01_mangos_command.sql
@@ -0,0 +1 @@
+UPDATE `command` SET help = 'Syntax: .account create $account $password [$expansion]\r\n\r\nCreate account and set password to it. Optionally, you may also set another expansion for this account than the defined default value.' WHERE name = 'account create';
diff --git a/src/game/AccountMgr.cpp b/src/game/AccountMgr.cpp
index 27cacde..066049a 100644
--- a/src/game/AccountMgr.cpp
+++ b/src/game/AccountMgr.cpp
@@ -55,6 +55,26 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass
return AOR_OK; // everything's fine
}
+AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password, uint32 expansion)
+{
+ if (utf8length(username) > MAX_ACCOUNT_STR)
+ return AOR_NAME_TOO_LONG; // username's too long
+
+ normalizeString(username);
+ normalizeString(password);
+
+ if (GetId(username))
+ {
+ return AOR_NAME_ALREDY_EXIST; // username does already exist
+ }
+
+ if (!LoginDatabase.PExecute("INSERT INTO account(username,sha_pass_hash,joindate,expansion) VALUES('%s','%s',NOW(),'%u')", username.c_str(), CalculateShaPassHash(username, password).c_str(), expansion))
+ return AOR_DB_INTERNAL_ERROR; // unexpected error
+ LoginDatabase.Execute("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");
+
+ return AOR_OK; // everything's fine
+}
+
AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
{
QueryResult* result = LoginDatabase.PQuery("SELECT 1 FROM account WHERE id='%u'", accid);
diff --git a/src/game/AccountMgr.h b/src/game/AccountMgr.h
index c35ce98..62b739d 100644
--- a/src/game/AccountMgr.h
+++ b/src/game/AccountMgr.h
@@ -42,6 +42,7 @@ class AccountMgr
~AccountMgr();
AccountOpResult CreateAccount(std::string username, std::string password);
+ AccountOpResult CreateAccount(std::string username, std::string password, uint32 expansion);
AccountOpResult DeleteAccount(uint32 accid);
AccountOpResult ChangeUsername(uint32 accid, std::string new_uname, std::string new_passwd);
AccountOpResult ChangePassword(uint32 accid, std::string new_passwd);
diff --git a/src/mangosd/CliRunnable.cpp b/src/mangosd/CliRunnable.cpp
index 233d08c..6deca0c 100644
--- a/src/mangosd/CliRunnable.cpp
+++ b/src/mangosd/CliRunnable.cpp
@@ -480,7 +480,12 @@ bool ChatHandler::HandleAccountCreateCommand(char* args)
std::string account_name = szAcc;
std::string password = szPassword;
- AccountOpResult result = sAccountMgr.CreateAccount(account_name, password);
+ AccountOpResult result;
+ uint32 expansion = 0;
+ if(ExtractUInt32(&args, expansion))
+ result = sAccountMgr.CreateAccount(account_name, password, expansion);
+ else
+ result = sAccountMgr.CreateAccount(account_name, password);
switch (result)
{
case AOR_OK:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment