Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions Server/mods/deathmatch/logic/CAccountManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,46 @@ bool CAccountManager::IntegrityCheck()
return true;
}

CAccount* CAccountManager::Get(const char* szName)
CAccount* CAccountManager::Get(const char* szName, const char* szPassword, bool bCaseSensitive)
{
if (szName && szName[0])
{
std::vector<CAccount*> results;
m_List.FindAccountMatches(&results, szName, true);
for (uint i = 0; i < results.size(); i++)
m_List.FindAccountMatches(&results, szName, bCaseSensitive);

if (!bCaseSensitive)
{
CAccount* pAccount = results[i];
if (pAccount->IsRegistered())
CAccount* pFirstMatchAccount = nullptr;

for (CAccount* pAccount : results)
{
return pAccount;
if (!pAccount->IsRegistered())
continue;

if (szPassword && !pAccount->IsPassword(szPassword))
continue;

if (pAccount->GetName() == szName)
{
return pAccount;
}
else if (!pFirstMatchAccount)
{
pFirstMatchAccount = pAccount;
}
}

return pFirstMatchAccount;
}

for (CAccount* pAccount : results)
{
if (pAccount->IsRegistered())
return pAccount;
}
}
return NULL;

return nullptr;
}

CAccount* CAccountManager::GetAccountFromScriptID(uint uiScriptID)
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CAccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class CAccountManager
bool SaveSettings(void);
bool IntegrityCheck(void);

CAccount* Get(const char* szName);
CAccount* Get(const char* szName, const char* szPassword = nullptr, bool caseSensitive = true);
CAccount* GetAccountFromScriptID(uint uiScriptID);
SString GetActiveCaseVariation(const SString& strName);

Expand Down
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10986,11 +10986,11 @@ CAccount* CStaticFunctionDefinitions::AddAccount(const SString& strName, const S
return NULL;
}

CAccount* CStaticFunctionDefinitions::GetAccount(const char* szName, const char* szPassword)
CAccount* CStaticFunctionDefinitions::GetAccount(const char* szName, const char* szPassword, bool bCaseSensitive)
{
assert(szName);

CAccount* pCurrentAccount = m_pAccountManager->Get(szName);
CAccount* pCurrentAccount = m_pAccountManager->Get(szName, szPassword, bCaseSensitive);
if (pCurrentAccount && (!szPassword || pCurrentAccount->IsPassword(szPassword)))
return pCurrentAccount;
else
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ class CStaticFunctionDefinitions
static bool ExecuteSQLQuery(const std::string& str, CLuaArguments* pArgs, CRegistryResult* pResult);

// Account get funcs
static CAccount* GetAccount(const char* szName, const char* szPassword);
static CAccount* GetAccount(const char* szName, const char* szPassword, bool bCaseSensitive = true);
static void GetAccounts(lua_State* pLua);
static CClient* GetAccountPlayer(CAccount* pAccount);
static bool IsGuestAccount(CAccount* pAccount, bool& bGuest);
Expand Down
7 changes: 6 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ int CLuaAccountDefs::GetAccount(lua_State* luaVM)
SString strName;
SString strPassword;
bool bUsePassword = false;
bool bCaseSensitive;

CScriptArgReader argStream(luaVM);
argStream.ReadString(strName);
Expand All @@ -223,10 +224,14 @@ int CLuaAccountDefs::GetAccount(lua_State* luaVM)
argStream.ReadString(strPassword);
bUsePassword = true;
}
else
argStream.Skip(1);

argStream.ReadBool(bCaseSensitive, true);

if (!argStream.HasErrors())
{
CAccount* pAccount = CStaticFunctionDefinitions::GetAccount(strName, bUsePassword ? strPassword.c_str() : NULL);
CAccount* pAccount = CStaticFunctionDefinitions::GetAccount(strName, bUsePassword ? strPassword.c_str() : NULL, bCaseSensitive);
if (pAccount)
{
lua_pushaccount(luaVM, pAccount);
Expand Down