Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: add setAccountSerial #3587

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
67645e0
:sparkles: feat: add setAccountSerial
camargo2019 Jul 19, 2024
1b05f78
:safety_vest: fix: get account name validation
camargo2019 Jul 20, 2024
62ebf06
:adhesive_bandage: fix: using new ArgumentParser
camargo2019 Jul 20, 2024
9ad1188
:adhesive_bandage: fix: removing hungarian notation
camargo2019 Jul 20, 2024
be766cf
:safety_vest: fix: serial validation
camargo2019 Jul 20, 2024
7418e4c
:adhesive_bandage: fix: removing setSerial from OOP
camargo2019 Jul 20, 2024
3bdd277
:adhesive_bandage: fix: using noexcept in accounts
camargo2019 Jul 20, 2024
790ffa2
:adhesive_bandage: fix: using CAccount
camargo2019 Jul 20, 2024
9a14e49
:adhesive_bandage: fix: add try catch in IsValidSerial
camargo2019 Jul 20, 2024
94ac014
:adhesive_bandage: fix: const noexcept
camargo2019 Jul 20, 2024
776b75c
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Jul 21, 2024
63baddc
:adhesive_bandage: fix: add setAccountSerial in acl.xml
camargo2019 Jul 21, 2024
208e646
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Jul 23, 2024
7928ea7
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Jul 23, 2024
ccf6721
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Jul 29, 2024
ded288e
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Jul 31, 2024
3bd593e
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Aug 1, 2024
fc58764
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Aug 2, 2024
fff2726
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Aug 6, 2024
c207fd9
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Aug 13, 2024
a244c0a
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Aug 17, 2024
03ea71f
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Aug 29, 2024
e3b8897
:adhesive_bandage: fix: moving setAccountSerial to SuperModerator
camargo2019 Aug 29, 2024
43d8dbd
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 2, 2024
09a022f
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 3, 2024
a45cfaf
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 4, 2024
bafa2cf
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 4, 2024
eb0578a
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 5, 2024
70e7493
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 8, 2024
58c433a
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 10, 2024
b16e2f3
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Sep 30, 2024
0d784fa
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Oct 5, 2024
2e5f55e
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Oct 7, 2024
37a8992
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Oct 14, 2024
0a9744f
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Oct 16, 2024
7ef6d6d
Merge branch 'master' into feat/add-set-account-serial
camargo2019 Nov 5, 2024
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
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<right name="function.removeAccount" access="false" />
<right name="function.setAccountName" access="false" />
<right name="function.setAccountPassword" access="false" />
<right name="function.setAccountSerial" access="false" />
<right name="function.kickPlayer" access="false" />
<right name="function.banPlayer" access="false" />
<right name="function.getBans" access="false" />
Expand Down Expand Up @@ -188,6 +189,7 @@
<right name="function.addAccount" access="true" />
<right name="function.setAccountName" access="true" />
<right name="function.setAccountPassword" access="true" />
<right name="function.setAccountSerial" access="true" />
<right name="function.renameResource" access="true" />
<right name="function.deleteResource" access="true" />
</acl>
Expand Down
28 changes: 28 additions & 0 deletions Server/mods/deathmatch/logic/CAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "CAccountManager.h"
#include "CIdArray.h"
#include "CClient.h"
#include <regex>

CAccount::CAccount(CAccountManager* pManager, EAccountType accountType, const std::string& strName, const std::string& strPassword, int iUserID,
const std::string& strIP, const std::string& strSerial, const SString& strHttpPassAppend)
Expand Down Expand Up @@ -255,6 +256,20 @@ bool CAccount::IsIpAuthorized(const SString& strIp)
return false;
}

//
// Check if the serial has 32 hexadecimal characters
//
bool CAccount::IsValidSerial(const std::string& serial) const noexcept
{
const std::regex serialPattern("^[A-Fa-f0-9]{32}$");

try{
return std::regex_match(serial, serialPattern);
} catch (...) {
return false;
}
}

//
// Mark pending serial as authorized for this account
//
Expand Down Expand Up @@ -289,6 +304,19 @@ bool CAccount::RemoveSerial(const SString& strSerial)
return false;
}

//
// Replace the serial number for a specific account
//
bool CAccount::SetAccountSerial(const std::string& serial) noexcept
{
if (!IsValidSerial(serial))
return false;

m_strSerial = serial;
m_pManager->MarkAsChanged(this);
return true;
}

//
// Cleanup unauthorized serials
//
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ class CAccount
SSerialUsage* GetSerialUsage(const SString& strSerial);
bool IsIpAuthorized(const SString& strIp);
bool IsSerialAuthorized(const SString& strSerial);
bool IsValidSerial(const std::string& serial) const noexcept;
bool AddSerialForAuthorization(const SString& strSerial, const SString& strIp);
bool AuthorizeSerial(const SString& strSerial, const SString& strWho);
bool RemoveSerial(const SString& strSerial);
void RemoveUnauthorizedSerials();
bool SetAccountSerial(const std::string& serial) noexcept;

CClient* GetClient() const { return m_pClient; }
void SetClient(CClient* pClient);
Expand Down
9 changes: 9 additions & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11425,6 +11425,15 @@ bool CStaticFunctionDefinitions::GetAccountSerial(CAccount* pAccount, SString& s
return bRegistered;
}


bool CStaticFunctionDefinitions::SetAccountSerial(CAccount* account, const std::string& serial) noexcept
{
if (account && account->IsRegistered())
return account->SetAccountSerial(serial);

return false;
}

bool CStaticFunctionDefinitions::GetAccountsBySerial(const SString& strSerial, std::vector<CAccount*>& outAccounts)
{
m_pAccountManager->GetAccountsBySerial(strSerial, outAccounts);
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ class CStaticFunctionDefinitions
// Account set funcs
static CAccount* AddAccount(const SString& strName, const SString& strPassword, bool bAllowCaseVariations, SString& strOutError);
static bool RemoveAccount(CAccount* pAccount);
static bool SetAccountSerial(CAccount* account, const std::string& serial) noexcept;
static bool SetAccountName(CAccount* pAccount, SString strNewName, bool bAllowCaseVariations, SString& strOutError);
static bool SetAccountPassword(CAccount* pAccount, SString szPassword, CAccountPassword::EAccountPasswordType ePasswordType);
static bool SetAccountData(CAccount* pAccount, const char* szKey, CLuaArgument* pArgument);
Expand Down
8 changes: 8 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void CLuaAccountDefs::LoadFunctions()
{"addAccount", AddAccount},
{"removeAccount", RemoveAccount},
{"setAccountPassword", SetAccountPassword},
{"setAccountSerial", ArgumentParser<SetAccountSerial>},
{"setAccountData", SetAccountData},
{"setAccountName", SetAccountName},
{"copyAccountData", CopyAccountData},
Expand Down Expand Up @@ -71,6 +72,7 @@ void CLuaAccountDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setData", "setAccountData");
lua_classfunction(luaVM, "setPassword", "setAccountPassword");
lua_classfunction(luaVM, "setName", "setAccountName");
lua_classfunction(luaVM, "setSerial", "setAccountSerial");

lua_classfunction(luaVM, "getSerial", "getAccountSerial");
lua_classfunction(luaVM, "getIP", "getAccountIP");
Expand Down Expand Up @@ -513,6 +515,12 @@ int CLuaAccountDefs::RemoveAccount(lua_State* luaVM)
return 1;
}

bool CLuaAccountDefs::SetAccountSerial(CAccount* account, std::string serial) noexcept
{
return CStaticFunctionDefinitions::SetAccountSerial(account, serial);
}


int CLuaAccountDefs::SetAccountName(lua_State* luaVM)
{
// bool setAccountPassword ( account theAccount, string name[, bool allowCaseVariations = false ] )
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ class CLuaAccountDefs : public CLuaDefs
LUA_DECLARE(SetAccountPassword);
LUA_DECLARE(SetAccountData);
LUA_DECLARE(CopyAccountData);
static bool SetAccountSerial(CAccount* account, std::string serial) noexcept;
};