Skip to content

Commit 7401422

Browse files
Dezashbotder
authored andcommitted
Add optional case sensitivity parameter to getAccount (PR #230)
1 parent 8d1f1b9 commit 7401422

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

Server/mods/deathmatch/logic/CAccountManager.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,22 +387,46 @@ bool CAccountManager::IntegrityCheck()
387387
return true;
388388
}
389389

390-
CAccount* CAccountManager::Get(const char* szName)
390+
CAccount* CAccountManager::Get(const char* szName, const char* szPassword, bool bCaseSensitive)
391391
{
392392
if (szName && szName[0])
393393
{
394394
std::vector<CAccount*> results;
395-
m_List.FindAccountMatches(&results, szName, true);
396-
for (uint i = 0; i < results.size(); i++)
395+
m_List.FindAccountMatches(&results, szName, bCaseSensitive);
396+
397+
if (!bCaseSensitive)
397398
{
398-
CAccount* pAccount = results[i];
399-
if (pAccount->IsRegistered())
399+
CAccount* pFirstMatchAccount = nullptr;
400+
401+
for (CAccount* pAccount : results)
400402
{
401-
return pAccount;
403+
if (!pAccount->IsRegistered())
404+
continue;
405+
406+
if (szPassword && !pAccount->IsPassword(szPassword))
407+
continue;
408+
409+
if (pAccount->GetName() == szName)
410+
{
411+
return pAccount;
412+
}
413+
else if (!pFirstMatchAccount)
414+
{
415+
pFirstMatchAccount = pAccount;
416+
}
402417
}
418+
419+
return pFirstMatchAccount;
420+
}
421+
422+
for (CAccount* pAccount : results)
423+
{
424+
if (pAccount->IsRegistered())
425+
return pAccount;
403426
}
404427
}
405-
return NULL;
428+
429+
return nullptr;
406430
}
407431

408432
CAccount* CAccountManager::GetAccountFromScriptID(uint uiScriptID)

Server/mods/deathmatch/logic/CAccountManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class CAccountManager
126126
bool SaveSettings(void);
127127
bool IntegrityCheck(void);
128128

129-
CAccount* Get(const char* szName);
129+
CAccount* Get(const char* szName, const char* szPassword = nullptr, bool caseSensitive = true);
130130
CAccount* GetAccountFromScriptID(uint uiScriptID);
131131
SString GetActiveCaseVariation(const SString& strName);
132132

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10986,11 +10986,11 @@ CAccount* CStaticFunctionDefinitions::AddAccount(const SString& strName, const S
1098610986
return NULL;
1098710987
}
1098810988

10989-
CAccount* CStaticFunctionDefinitions::GetAccount(const char* szName, const char* szPassword)
10989+
CAccount* CStaticFunctionDefinitions::GetAccount(const char* szName, const char* szPassword, bool bCaseSensitive)
1099010990
{
1099110991
assert(szName);
1099210992

10993-
CAccount* pCurrentAccount = m_pAccountManager->Get(szName);
10993+
CAccount* pCurrentAccount = m_pAccountManager->Get(szName, szPassword, bCaseSensitive);
1099410994
if (pCurrentAccount && (!szPassword || pCurrentAccount->IsPassword(szPassword)))
1099510995
return pCurrentAccount;
1099610996
else

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class CStaticFunctionDefinitions
651651
static bool ExecuteSQLQuery(const std::string& str, CLuaArguments* pArgs, CRegistryResult* pResult);
652652

653653
// Account get funcs
654-
static CAccount* GetAccount(const char* szName, const char* szPassword);
654+
static CAccount* GetAccount(const char* szName, const char* szPassword, bool bCaseSensitive = true);
655655
static void GetAccounts(lua_State* pLua);
656656
static CClient* GetAccountPlayer(CAccount* pAccount);
657657
static bool IsGuestAccount(CAccount* pAccount, bool& bGuest);

Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ int CLuaAccountDefs::GetAccount(lua_State* luaVM)
214214
SString strName;
215215
SString strPassword;
216216
bool bUsePassword = false;
217+
bool bCaseSensitive;
217218

218219
CScriptArgReader argStream(luaVM);
219220
argStream.ReadString(strName);
@@ -223,10 +224,14 @@ int CLuaAccountDefs::GetAccount(lua_State* luaVM)
223224
argStream.ReadString(strPassword);
224225
bUsePassword = true;
225226
}
227+
else
228+
argStream.Skip(1);
229+
230+
argStream.ReadBool(bCaseSensitive, true);
226231

227232
if (!argStream.HasErrors())
228233
{
229-
CAccount* pAccount = CStaticFunctionDefinitions::GetAccount(strName, bUsePassword ? strPassword.c_str() : NULL);
234+
CAccount* pAccount = CStaticFunctionDefinitions::GetAccount(strName, bUsePassword ? strPassword.c_str() : NULL, bCaseSensitive);
230235
if (pAccount)
231236
{
232237
lua_pushaccount(luaVM, pAccount);

0 commit comments

Comments
 (0)