diff --git a/src/game/WorldHandlers/AccountMgr.cpp b/src/game/WorldHandlers/AccountMgr.cpp index 66cc3647..4867ad6f 100644 --- a/src/game/WorldHandlers/AccountMgr.cpp +++ b/src/game/WorldHandlers/AccountMgr.cpp @@ -35,12 +35,26 @@ extern DatabaseType LoginDatabase; INSTANTIATE_SINGLETON_1(AccountMgr); +/** + * The AccountMgr constructor + */ AccountMgr::AccountMgr() {} +/** + * The AccountMgr destructor + */ AccountMgr::~AccountMgr() {} +/** + * It creates an account + * + * @param username The username of the account to create. + * @param password The password you want to set for the account. + * + * @return AOR_OK + */ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password) { if (utf8length(username) > MAX_ACCOUNT_STR) @@ -72,6 +86,13 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass return AOR_OK; // everything's fine } +/** + * It deletes an account from the database + * + * @param accid The account ID of the account to delete. + * + * @return AOR_OK + */ AccountOpResult AccountMgr::DeleteAccount(uint32 accid) { QueryResult* result = LoginDatabase.PQuery("SELECT 1 FROM `account` WHERE `id`='%u'", accid); @@ -119,6 +140,15 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid) return AOR_OK; } +/** + * It changes the username and password of an account + * + * @param accid The account ID of the account you want to change the username of. + * @param new_uname The new username + * @param new_passwd The new password for the account. + * + * @return AOR_OK + */ AccountOpResult AccountMgr::ChangeUsername(uint32 accid, std::string new_uname, std::string new_passwd) { QueryResult* result = LoginDatabase.PQuery("SELECT 1 FROM `account` WHERE `id`='%u'", accid); @@ -153,6 +183,14 @@ AccountOpResult AccountMgr::ChangeUsername(uint32 accid, std::string new_uname, return AOR_OK; } +/** + * It takes a username and password, and updates the database with the new password + * + * @param accid The account ID of the account you want to change the password of. + * @param new_passwd The new password to set for the account. + * + * @return AOR_OK + */ AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd) { std::string username; @@ -180,6 +218,13 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd) return AOR_OK; } +/** + * It returns the account ID of the account with the given username. + * + * @param username The username of the account you want to get the ID of. + * + * @return The account id of the account with the username that was passed in. + */ uint32 AccountMgr::GetId(std::string username) { LoginDatabase.escape_string(username); @@ -196,6 +241,13 @@ uint32 AccountMgr::GetId(std::string username) } } +/** + * It returns the security level of the account with the given account ID + * + * @param acc_id The account ID of the account you want to get the security level of. + * + * @return The security level of the account. + */ AccountTypes AccountMgr::GetSecurity(uint32 acc_id) { QueryResult* result = LoginDatabase.PQuery("SELECT `gmlevel` FROM `account` WHERE `id` = '%u'", acc_id); @@ -209,6 +261,14 @@ AccountTypes AccountMgr::GetSecurity(uint32 acc_id) return SEC_PLAYER; } +/** + * It gets the account name from the database + * + * @param acc_id The account ID of the account you want to get the name of. + * @param name The name of the account to be checked. + * + * @return The name of the account. + */ bool AccountMgr::GetName(uint32 acc_id, std::string& name) { QueryResult* result = LoginDatabase.PQuery("SELECT `username` FROM `account` WHERE `id` = '%u'", acc_id); @@ -222,6 +282,13 @@ bool AccountMgr::GetName(uint32 acc_id, std::string& name) return false; } +/** + * It returns the number of characters on an account. + * + * @param acc_id The account ID of the account you want to check. + * + * @return The number of characters on the account. + */ uint32 AccountMgr::GetCharactersCount(uint32 acc_id) { // check character count @@ -239,6 +306,14 @@ uint32 AccountMgr::GetCharactersCount(uint32 acc_id) } } +/** + * It takes a username and password, and returns true if the password is correct + * + * @param accid The account ID of the account you want to check the password for. + * @param passwd The password that the user entered. + * + * @return The account id of the account that is being logged in. + */ bool AccountMgr::CheckPassword(uint32 accid, std::string passwd) { std::string username; @@ -260,6 +335,13 @@ bool AccountMgr::CheckPassword(uint32 accid, std::string passwd) return false; } +/** + * It converts a string to uppercase, but only if it's a latin character + * + * @param utf8str The string to be normalized. + * + * @return A boolean value. + */ bool AccountMgr::normalizeString(std::string& utf8str) { wchar_t wstr_buf[MAX_ACCOUNT_STR + 1]; @@ -278,6 +360,15 @@ bool AccountMgr::normalizeString(std::string& utf8str) return WStrToUtf8(wstr_buf, wstr_len, utf8str); } +/** + * It takes a username and password, concatenates them with a colon, and then hashes the result with + * SHA1 + * + * @param name The account name + * @param password The password you want to use for the account. + * + * @return The SHA1 hash of the username and password. + */ std::string AccountMgr::CalculateShaPassHash(std::string& name, std::string& password) { Sha1Hash sha; diff --git a/src/game/WorldHandlers/AccountMgr.h b/src/game/WorldHandlers/AccountMgr.h index bcfab2f4..91f0b679 100644 --- a/src/game/WorldHandlers/AccountMgr.h +++ b/src/game/WorldHandlers/AccountMgr.h @@ -27,6 +27,7 @@ #include "Common.h" +/* An enumeration of the possible results of an account operation. */ enum AccountOpResult { AOR_OK, @@ -40,6 +41,7 @@ enum AccountOpResult #define MAX_ACCOUNT_STR 16 #define MAX_PASSWORD_STR 16 +/* A class that is used to manage accounts. */ class AccountMgr { public: @@ -61,6 +63,7 @@ class AccountMgr static bool normalizeString(std::string& utf8str); }; +/* A macro that creates a global variable called `sAccountMgr` that is an instance of the `AccountMgr` class. */ #define sAccountMgr MaNGOS::Singleton::Instance() #endif