Skip to content

Commit 6331f54

Browse files
emre1702jushar
authored andcommitted
Squash-merge 'Add getAccountID & getAccountByID'
Squashed commit of the following: commit 7f3c6f00fca2f628b6371d1db02f8fa882bf929a Author: Jusonex <[email protected]> Date: Fri Jun 22 22:23:23 2018 +0200 Fix bugs in getAccountID and getAccountByID commit 122f929ea23b76e78a2827ef3a621539cc9b8ea3 Merge: 4f3fdc5 6a048ee Author: Jusonex <[email protected]> Date: Fri Jun 22 21:56:11 2018 +0200 Merge branch 'AccountID' of git://github.com/emre1702/mtasa-blue into emre1702-AccountID commit 6a048ee Merge: 42752d4 15f99b2 Author: Emre Kara <[email protected]> Date: Mon Jun 18 22:50:25 2018 +0200 Merge branch 'master' into AccountID commit 42752d4 Author: Emre Kara <[email protected]> Date: Wed Nov 15 18:41:42 2017 +0100 Add getAccountID & getAccountByID
1 parent 4f3fdc5 commit 6331f54

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

Server/mods/deathmatch/logic/CAccountManager.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,21 @@ void CAccountManager::GetAccountsByIP(const SString& strIP, std::vector<CAccount
912912
}
913913
}
914914

915+
CAccount* CAccountManager::GetAccountByID(int ID)
916+
{
917+
CRegistryResult result;
918+
m_pDatabaseManager->QueryWithResultf(m_hDbConnection, &result, "SELECT name FROM accounts WHERE id = ?", SQLITE_INTEGER, ID);
919+
920+
for (CRegistryResultIterator iter = result->begin(); iter != result->end(); ++iter)
921+
{
922+
const auto& row = *iter;
923+
924+
return Get(reinterpret_cast<const char*>(row[0].pVal));
925+
}
926+
927+
return nullptr;
928+
}
929+
915930
void CAccountManager::GetAccountsByData(const SString& dataName, const SString& value, std::vector<CAccount*>& outAccounts)
916931
{
917932
Save();

Server/mods/deathmatch/logic/CAccountManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class CAccountManager
140140

141141
void GetAccountsBySerial(const SString& strSerial, std::vector<CAccount*>& outAccounts);
142142
void GetAccountsByIP(const SString& strIP, std::vector<CAccount*>& outAccounts);
143+
CAccount* GetAccountByID(int ID);
143144
void GetAccountsByData(const SString& dataName, const SString& value, std::vector<CAccount*>& outAccounts);
144145

145146
CAccount* AddGuestAccount(const SString& strName);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10907,6 +10907,21 @@ bool CStaticFunctionDefinitions::GetAccountsBySerial(const SString& strSerial, s
1090710907
return true;
1090810908
}
1090910909

10910+
bool CStaticFunctionDefinitions::GetAccountID(CAccount* pAccount, int& ID)
10911+
{
10912+
bool bRegistered = pAccount->IsRegistered();
10913+
if (bRegistered)
10914+
ID = pAccount->GetID();
10915+
10916+
return bRegistered;
10917+
}
10918+
10919+
bool CStaticFunctionDefinitions::GetAccountByID(int ID, CAccount*& outAccount)
10920+
{
10921+
outAccount = m_pAccountManager->GetAccountByID(ID);
10922+
return true;
10923+
}
10924+
1091010925
bool CStaticFunctionDefinitions::GetAccountIP(CAccount* pAccount, SString& strIP)
1091110926
{
1091210927
bool bRegistered = pAccount->IsRegistered();

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ class CStaticFunctionDefinitions
651651
static bool GetAccountsByData(const SString& dataName, const SString& value, std::vector<CAccount*>& outAccounts);
652652
static bool GetAccountSerial(CAccount* pAccount, SString& strSerial);
653653
static bool GetAccountsBySerial(const SString& strSerial, std::vector<CAccount*>& outAccounts);
654+
static bool GetAccountID(CAccount* pAccount, int& ID);
655+
static bool GetAccountByID(int ID, CAccount*& outAccount);
654656
static bool GetAccountIP(CAccount* pAccount, SString& strIP);
655657
static bool GetAccountsByIP(const SString& strIP, std::vector<CAccount*>& outAccounts);
656658

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ void CLuaAccountDefs::LoadFunctions()
2828
CLuaCFunctions::AddFunction("getAccountsByData", GetAccountsByData);
2929
CLuaCFunctions::AddFunction("getAccountSerial", GetAccountSerial);
3030
CLuaCFunctions::AddFunction("getAccountsBySerial", GetAccountsBySerial);
31+
CLuaCFunctions::AddFunction("getAccountID", GetAccountID);
32+
CLuaCFunctions::AddFunction("getAccountByID", GetAccountByID);
3133
CLuaCFunctions::AddFunction("getAccountIP", GetAccountIP);
3234
CLuaCFunctions::AddFunction("getAccountsByIP", GetAccountsByIP);
3335

@@ -62,6 +64,7 @@ void CLuaAccountDefs::AddClass(lua_State* luaVM)
6264

6365
lua_classfunction(luaVM, "getSerial", "getAccountSerial");
6466
lua_classfunction(luaVM, "getIP", "getAccountIP");
67+
lua_classfunction(luaVM, "getID", "getAccountID");
6568
lua_classfunction(luaVM, "getData", "getAccountData");
6669
lua_classfunction(luaVM, "getAllData", "getAllAccountData");
6770
lua_classfunction(luaVM, "getName", "getAccountName");
@@ -70,6 +73,7 @@ void CLuaAccountDefs::AddClass(lua_State* luaVM)
7073

7174
lua_classvariable(luaVM, "serial", NULL, "getAccountSerial");
7275
lua_classvariable(luaVM, "name", "setAccountName", "getAccountName");
76+
lua_classvariable(luaVM, "id", NULL, "getAccountID");
7377
lua_classvariable(luaVM, "ip", NULL, "getAccountIP");
7478
lua_classvariable(luaVM, "player", NULL, "getAccountPlayer");
7579
lua_classvariable(luaVM, "guest", NULL, "isGuestAccount");
@@ -345,7 +349,7 @@ int CLuaAccountDefs::GetAccountIP(lua_State* luaVM)
345349

346350
int CLuaAccountDefs::GetAccountsByIP(lua_State* luaVM)
347351
{
348-
// table getAccountsByIP ( string ip )
352+
// table getAccountsByIP ( string ip )
349353
SString strIP;
350354

351355
CScriptArgReader argStream(luaVM);
@@ -372,6 +376,54 @@ int CLuaAccountDefs::GetAccountsByIP(lua_State* luaVM)
372376
return 1;
373377
}
374378

379+
int CLuaAccountDefs::GetAccountID(lua_State* luaVM)
380+
{
381+
// int getAccountID ( account theAccount )
382+
CAccount* pAccount;
383+
384+
CScriptArgReader argStream(luaVM);
385+
argStream.ReadUserData(pAccount);
386+
387+
if (!argStream.HasErrors())
388+
{
389+
int ID;
390+
if (CStaticFunctionDefinitions::GetAccountID(pAccount, ID))
391+
{
392+
lua_pushnumber(luaVM, ID);
393+
return 1;
394+
}
395+
}
396+
else
397+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
398+
399+
lua_pushboolean(luaVM, false);
400+
return 1;
401+
}
402+
403+
int CLuaAccountDefs::GetAccountByID(lua_State* luaVM)
404+
{
405+
// account getAccountByID ( int ID )
406+
int ID;
407+
408+
CScriptArgReader argStream(luaVM);
409+
argStream.ReadNumber(ID);
410+
411+
if (!argStream.HasErrors())
412+
{
413+
CAccount* account;
414+
if (CStaticFunctionDefinitions::GetAccountByID(ID, account) && account)
415+
{
416+
lua_pushaccount(luaVM, account);
417+
return 1;
418+
}
419+
}
420+
else
421+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
422+
423+
lua_pushboolean(luaVM, false);
424+
return 1;
425+
}
426+
375427
int CLuaAccountDefs::AddAccount(lua_State* luaVM)
376428
{
377429
// account addAccount ( string name, string pass[, bool allowCaseVariations = false ] )

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class CLuaAccountDefs : public CLuaDefs
3333
LUA_DECLARE(GetAccountsByData);
3434
LUA_DECLARE(GetAccountSerial);
3535
LUA_DECLARE(GetAccountsBySerial);
36+
LUA_DECLARE(GetAccountID);
37+
LUA_DECLARE(GetAccountByID);
3638
LUA_DECLARE(GetAccountIP);
3739
LUA_DECLARE(GetAccountsByIP);
3840

0 commit comments

Comments
 (0)