aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-11-10 01:19:24 +0100
committerShauren <shauren.trinity@gmail.com>2014-11-10 01:19:24 +0100
commit0c27ffaa49c7e3e6880051ac74581cae51d83351 (patch)
tree341ff599888d4158edffd729b44f8932b52872f7 /src/server/game
parent2545804288dfac716ae474574d4ed47e71c500f1 (diff)
Core/Commands: Battle.net account command changes
* All commands renamed from "battlenetaccount" to "bnetaccount" * bnetaccount create now also creates and links initial game account * Added new commands bnetaccount link/unlink to manage relations between existing accounts
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/Accounts/AccountMgr.cpp12
-rw-r--r--src/server/game/Accounts/AccountMgr.h5
-rw-r--r--src/server/game/Accounts/BattlenetAccountMgr.cpp95
-rw-r--r--src/server/game/Accounts/BattlenetAccountMgr.h3
-rw-r--r--src/server/game/Accounts/RBAC.h6
-rw-r--r--src/server/game/Miscellaneous/Language.h7
6 files changed, 101 insertions, 27 deletions
diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp
index d6985e2a1ad..41c1b0c7c87 100644
--- a/src/server/game/Accounts/AccountMgr.cpp
+++ b/src/server/game/Accounts/AccountMgr.cpp
@@ -33,7 +33,7 @@ AccountMgr::~AccountMgr()
ClearRBAC();
}
-AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password, std::string email /*= ""*/)
+AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password, std::string email /*= ""*/, uint32 bnetAccountId /*= 0*/, uint8 bnetIndex /*= 0*/)
{
if (utf8length(username) > MAX_ACCOUNT_STR)
return AccountOpResult::AOR_NAME_TOO_LONG; // username's too long
@@ -51,6 +51,16 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass
stmt->setString(1, CalculateShaPassHash(username, password));
stmt->setString(2, email);
stmt->setString(3, email);
+ if (bnetAccountId && bnetIndex)
+ {
+ stmt->setUInt32(4, bnetAccountId);
+ stmt->setUInt8(5, bnetIndex);
+ }
+ else
+ {
+ stmt->setNull(4);
+ stmt->setNull(5);
+ }
LoginDatabase.DirectExecute(stmt); // Enforce saving, otherwise AddGroup can fail
diff --git a/src/server/game/Accounts/AccountMgr.h b/src/server/game/Accounts/AccountMgr.h
index add00ec7feb..a3956ad8633 100644
--- a/src/server/game/Accounts/AccountMgr.h
+++ b/src/server/game/Accounts/AccountMgr.h
@@ -29,7 +29,8 @@ enum class AccountOpResult : uint8
AOR_EMAIL_TOO_LONG,
AOR_NAME_ALREADY_EXIST,
AOR_NAME_NOT_EXIST,
- AOR_DB_INTERNAL_ERROR
+ AOR_DB_INTERNAL_ERROR,
+ AOR_ACCOUNT_BAD_LINK
};
enum PasswordChangeSecurity
@@ -62,7 +63,7 @@ class AccountMgr
return &instance;
}
- AccountOpResult CreateAccount(std::string username, std::string password, std::string email = "");
+ AccountOpResult CreateAccount(std::string username, std::string password, std::string email = "", uint32 bnetAccountId = 0, uint8 bnetIndex = 0);
static AccountOpResult DeleteAccount(uint32 accountId);
static AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::string newPassword);
static AccountOpResult ChangePassword(uint32 accountId, std::string newPassword);
diff --git a/src/server/game/Accounts/BattlenetAccountMgr.cpp b/src/server/game/Accounts/BattlenetAccountMgr.cpp
index da71f02d7d2..6048a1e2b98 100644
--- a/src/server/game/Accounts/BattlenetAccountMgr.cpp
+++ b/src/server/game/Accounts/BattlenetAccountMgr.cpp
@@ -21,6 +21,8 @@
#include "Util.h"
#include "SHA256.h"
+using GameAccountMgr = AccountMgr;
+
AccountOpResult Battlenet::AccountMgr::CreateBattlenetAccount(std::string email, std::string password)
{
if (utf8length(email) > MAX_BNET_EMAIL_STR)
@@ -38,8 +40,12 @@ AccountOpResult Battlenet::AccountMgr::CreateBattlenetAccount(std::string email,
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BNET_ACCOUNT);
stmt->setString(0, email);
stmt->setString(1, CalculateShaPassHash(email, password));
- LoginDatabase.Execute(stmt);
+ LoginDatabase.DirectExecute(stmt);
+ uint32 newAccountId = GetId(email);
+ ASSERT(newAccountId);
+
+ GameAccountMgr::instance()->CreateAccount(std::to_string(newAccountId) + "#1", password, email, newAccountId, 1);
return AccountOpResult::AOR_OK;
}
@@ -62,20 +68,65 @@ AccountOpResult Battlenet::AccountMgr::ChangePassword(uint32 accountId, std::str
return AccountOpResult::AOR_OK;
}
-uint32 Battlenet::AccountMgr::GetId(std::string const& username)
+bool Battlenet::AccountMgr::CheckPassword(uint32 accountId, std::string password)
{
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_ACCOUNT_ID_BY_EMAIL);
- stmt->setString(0, username);
- if (PreparedQueryResult result = LoginDatabase.Query(stmt))
- return (*result)[0].GetUInt32();
+ std::string username;
- return 0;
+ if (!GetName(accountId, username))
+ return false;
+
+ Utf8ToUpperOnlyLatin(username);
+ Utf8ToUpperOnlyLatin(password);
+
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_CHECK_PASSWORD);
+ stmt->setUInt32(0, accountId);
+ stmt->setString(1, CalculateShaPassHash(username, password));
+
+ return LoginDatabase.Query(stmt) != nullptr;
}
-uint32 Battlenet::AccountMgr::GetIdByGameAccount(uint32 gameAccountId)
+AccountOpResult Battlenet::AccountMgr::LinkWithGameAccount(std::string const& email, std::string const& gameAccountName)
{
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_ACCOUNT_ID_BY_GAME_ACCOUNT);
- stmt->setUInt32(0, gameAccountId);
+ uint32 bnetAccountId = GetId(email);
+ if (!bnetAccountId)
+ return AccountOpResult::AOR_NAME_NOT_EXIST;
+
+ uint32 gameAccountId = GameAccountMgr::GetId(gameAccountName);
+ if (!gameAccountId)
+ return AccountOpResult::AOR_NAME_NOT_EXIST;
+
+ if (GetIdByGameAccount(gameAccountId))
+ return AccountOpResult::AOR_ACCOUNT_BAD_LINK;
+
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_GAME_ACCOUNT_LINK);
+ stmt->setUInt32(0, bnetAccountId);
+ stmt->setUInt8(1, GetMaxIndex(bnetAccountId) + 1);
+ stmt->setUInt32(gameAccountId);
+ LoginDatabase.Execute(stmt);
+ return AccountOpResult::AOR_OK;
+}
+
+AccountOpResult Battlenet::AccountMgr::UnlinkGameAccount(std::string const& gameAccountName)
+{
+ uint32 gameAccountId = GameAccountMgr::GetId(gameAccountName);
+ if (!gameAccountId)
+ return AccountOpResult::AOR_NAME_NOT_EXIST;
+
+ if (!GetIdByGameAccount(gameAccountId))
+ return AccountOpResult::AOR_ACCOUNT_BAD_LINK;
+
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_GAME_ACCOUNT_LINK);
+ stmt->setNull(0);
+ stmt->setNull(1);
+ stmt->setUInt32(gameAccountId);
+ LoginDatabase.Execute(stmt);
+ return AccountOpResult::AOR_OK;
+}
+
+uint32 Battlenet::AccountMgr::GetId(std::string const& username)
+{
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_ACCOUNT_ID_BY_EMAIL);
+ stmt->setString(0, username);
if (PreparedQueryResult result = LoginDatabase.Query(stmt))
return (*result)[0].GetUInt32();
@@ -95,21 +146,25 @@ bool Battlenet::AccountMgr::GetName(uint32 accountId, std::string& name)
return false;
}
-bool Battlenet::AccountMgr::CheckPassword(uint32 accountId, std::string password)
+uint32 Battlenet::AccountMgr::GetIdByGameAccount(uint32 gameAccountId)
{
- std::string username;
-
- if (!GetName(accountId, username))
- return false;
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_ACCOUNT_ID_BY_GAME_ACCOUNT);
+ stmt->setUInt32(0, gameAccountId);
+ if (PreparedQueryResult result = LoginDatabase.Query(stmt))
+ return (*result)[0].GetUInt32();
- Utf8ToUpperOnlyLatin(username);
- Utf8ToUpperOnlyLatin(password);
+ return 0;
+}
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_CHECK_PASSWORD);
+uint8 Battlenet::AccountMgr::GetMaxIndex(uint32 accountId)
+{
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_MAX_ACCOUNT_INDEX);
stmt->setUInt32(0, accountId);
- stmt->setString(1, CalculateShaPassHash(username, password));
+ PreparedQueryResult result = LoginDatabase.Query(stmt);
+ if (result)
+ return (*result)[0].GetUInt8();
- return LoginDatabase.Query(stmt) != nullptr;
+ return 0;
}
std::string Battlenet::AccountMgr::CalculateShaPassHash(std::string const& name, std::string const& password)
diff --git a/src/server/game/Accounts/BattlenetAccountMgr.h b/src/server/game/Accounts/BattlenetAccountMgr.h
index 1e0b7b78a99..07e9f684874 100644
--- a/src/server/game/Accounts/BattlenetAccountMgr.h
+++ b/src/server/game/Accounts/BattlenetAccountMgr.h
@@ -32,10 +32,13 @@ namespace Battlenet
AccountOpResult CreateBattlenetAccount(std::string email, std::string password);
AccountOpResult ChangePassword(uint32 accountId, std::string newPassword);
bool CheckPassword(uint32 accountId, std::string password);
+ AccountOpResult LinkWithGameAccount(std::string const& email, std::string const& gameAccountName);
+ AccountOpResult UnlinkGameAccount(std::string const& gameAccountName);
uint32 GetId(std::string const& username);
bool GetName(uint32 accountId, std::string& name);
uint32 GetIdByGameAccount(uint32 gameAccountId);
+ uint8 GetMaxIndex(uint32 accountId);
std::string CalculateShaPassHash(std::string const& name, std::string const& password);
}
diff --git a/src/server/game/Accounts/RBAC.h b/src/server/game/Accounts/RBAC.h
index e0c22f297ea..17c34a9b42a 100644
--- a/src/server/game/Accounts/RBAC.h
+++ b/src/server/game/Accounts/RBAC.h
@@ -117,9 +117,9 @@ enum RBACPermissions
RBAC_PERM_COMMAND_BNET_ACCOUNT_PASSWORD = 211,
RBAC_PERM_COMMAND_BNET_ACCOUNT_SET = 212,
RBAC_PERM_COMMAND_BNET_ACCOUNT_SET_PASSWORD = 213,
- // 214 - reuse
- // 215 - reuse
- // 216 - reuse
+ RBAC_PERM_COMMAND_BNET_ACCOUNT_LINK = 214,
+ RBAC_PERM_COMMAND_BNET_ACCOUNT_UNLINK = 215,
+ RBAC_PERM_COMMAND_BNET_ACCOUNT_CREATE_GAME = 216,
RBAC_PERM_COMMAND_ACCOUNT = 217,
RBAC_PERM_COMMAND_ACCOUNT_ADDON = 218,
RBAC_PERM_COMMAND_ACCOUNT_CREATE = 219,
diff --git a/src/server/game/Miscellaneous/Language.h b/src/server/game/Miscellaneous/Language.h
index 41654f80dd4..a941dbd31ed 100644
--- a/src/server/game/Miscellaneous/Language.h
+++ b/src/server/game/Miscellaneous/Language.h
@@ -978,7 +978,12 @@ enum TrinityStrings
LANG_GUILD_INFO_MOTD = 1182,
LANG_GUILD_INFO_EXTRA_INFO = 1183,
LANG_GUILD_INFO_LEVEL = 1184,
- // Room for more level 3 1184-1199 not used
+ LANG_ACCOUNT_BNET_LINKED = 1185,
+ LANG_ACCOUNT_OR_BNET_DOES_NOT_EXIST = 1186,
+ LANG_ACCOUNT_ALREADY_LINKED = 1187,
+ LANG_ACCOUNT_BNET_UNLINKED = 1188,
+ LANG_ACCOUNT_BNET_NOT_LINKED = 1189,
+ // Room for more level 3 1190-1199 not used
// Debug commands
LANG_CINEMATIC_NOT_EXIST = 1200,