[Doc] Documenting Account Manager (#55)
This commit is contained in:
parent
e611d71caf
commit
87413b132b
@ -35,12 +35,26 @@ extern DatabaseType LoginDatabase;
|
|||||||
|
|
||||||
INSTANTIATE_SINGLETON_1(AccountMgr);
|
INSTANTIATE_SINGLETON_1(AccountMgr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The AccountMgr constructor
|
||||||
|
*/
|
||||||
AccountMgr::AccountMgr()
|
AccountMgr::AccountMgr()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The AccountMgr destructor
|
||||||
|
*/
|
||||||
AccountMgr::~AccountMgr()
|
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)
|
AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password)
|
||||||
{
|
{
|
||||||
if (utf8length(username) > MAX_ACCOUNT_STR)
|
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
|
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)
|
AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
|
||||||
{
|
{
|
||||||
QueryResult* result = LoginDatabase.PQuery("SELECT 1 FROM `account` WHERE `id`='%u'", 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;
|
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)
|
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);
|
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;
|
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)
|
AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd)
|
||||||
{
|
{
|
||||||
std::string username;
|
std::string username;
|
||||||
@ -180,6 +218,13 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd)
|
|||||||
return AOR_OK;
|
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)
|
uint32 AccountMgr::GetId(std::string username)
|
||||||
{
|
{
|
||||||
LoginDatabase.escape_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)
|
AccountTypes AccountMgr::GetSecurity(uint32 acc_id)
|
||||||
{
|
{
|
||||||
QueryResult* result = LoginDatabase.PQuery("SELECT `gmlevel` FROM `account` WHERE `id` = '%u'", 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;
|
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)
|
bool AccountMgr::GetName(uint32 acc_id, std::string& name)
|
||||||
{
|
{
|
||||||
QueryResult* result = LoginDatabase.PQuery("SELECT `username` FROM `account` WHERE `id` = '%u'", acc_id);
|
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;
|
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)
|
uint32 AccountMgr::GetCharactersCount(uint32 acc_id)
|
||||||
{
|
{
|
||||||
// check character count
|
// 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)
|
bool AccountMgr::CheckPassword(uint32 accid, std::string passwd)
|
||||||
{
|
{
|
||||||
std::string username;
|
std::string username;
|
||||||
@ -260,6 +335,13 @@ bool AccountMgr::CheckPassword(uint32 accid, std::string passwd)
|
|||||||
return false;
|
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)
|
bool AccountMgr::normalizeString(std::string& utf8str)
|
||||||
{
|
{
|
||||||
wchar_t wstr_buf[MAX_ACCOUNT_STR + 1];
|
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);
|
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)
|
std::string AccountMgr::CalculateShaPassHash(std::string& name, std::string& password)
|
||||||
{
|
{
|
||||||
Sha1Hash sha;
|
Sha1Hash sha;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
|
/* An enumeration of the possible results of an account operation. */
|
||||||
enum AccountOpResult
|
enum AccountOpResult
|
||||||
{
|
{
|
||||||
AOR_OK,
|
AOR_OK,
|
||||||
@ -40,6 +41,7 @@ enum AccountOpResult
|
|||||||
#define MAX_ACCOUNT_STR 16
|
#define MAX_ACCOUNT_STR 16
|
||||||
#define MAX_PASSWORD_STR 16
|
#define MAX_PASSWORD_STR 16
|
||||||
|
|
||||||
|
/* A class that is used to manage accounts. */
|
||||||
class AccountMgr
|
class AccountMgr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -61,6 +63,7 @@ class AccountMgr
|
|||||||
static bool normalizeString(std::string& utf8str);
|
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<AccountMgr>::Instance()
|
#define sAccountMgr MaNGOS::Singleton<AccountMgr>::Instance()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user