From 67645e0d3868ca20c08d94c206d38da0076086a5 Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Fri, 19 Jul 2024 20:53:04 -0300 Subject: [PATCH 01/12] :sparkles: feat: add setAccountSerial --- Server/mods/deathmatch/logic/CAccount.cpp | 9 +++++++ Server/mods/deathmatch/logic/CAccount.h | 1 + .../logic/CStaticFunctionDefinitions.cpp | 17 ++++++++++++ .../logic/CStaticFunctionDefinitions.h | 1 + .../logic/luadefs/CLuaAccountDefs.cpp | 27 +++++++++++++++++++ .../logic/luadefs/CLuaAccountDefs.h | 1 + 6 files changed, 56 insertions(+) diff --git a/Server/mods/deathmatch/logic/CAccount.cpp b/Server/mods/deathmatch/logic/CAccount.cpp index 73934a9f8b..3a7dbc9796 100644 --- a/Server/mods/deathmatch/logic/CAccount.cpp +++ b/Server/mods/deathmatch/logic/CAccount.cpp @@ -289,6 +289,15 @@ bool CAccount::RemoveSerial(const SString& strSerial) return false; } +// +// Replace the serial number for a specific account +// +void CAccount::SetAccountSerial(const SString strSerial) +{ + m_strSerial = strSerial; + m_pManager->MarkAsChanged(this); +} + // // Cleanup unauthorized serials // diff --git a/Server/mods/deathmatch/logic/CAccount.h b/Server/mods/deathmatch/logic/CAccount.h index 363dd57d98..910c107e6d 100644 --- a/Server/mods/deathmatch/logic/CAccount.h +++ b/Server/mods/deathmatch/logic/CAccount.h @@ -101,6 +101,7 @@ class CAccount bool AuthorizeSerial(const SString& strSerial, const SString& strWho); bool RemoveSerial(const SString& strSerial); void RemoveUnauthorizedSerials(); + void SetAccountSerial(const SString strSerial); CClient* GetClient() const { return m_pClient; } void SetClient(CClient* pClient); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index c7ce99d91e..feb5ff3628 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -11400,6 +11400,23 @@ bool CStaticFunctionDefinitions::GetAccountSerial(CAccount* pAccount, SString& s return bRegistered; } + +bool CStaticFunctionDefinitions::SetAccountSerial(SString strName, SString strSerial) +{ + const char* szAccountName = strName.c_str(); + CAccount* pAccount = g_pGame->GetAccountManager()->Get(szAccountName); + + if (pAccount){ + bool bRegistered = pAccount->IsRegistered(); + if (bRegistered) + pAccount->SetAccountSerial(strSerial); + + return bRegistered; + } + + return false; +} + bool CStaticFunctionDefinitions::GetAccountsBySerial(const SString& strSerial, std::vector& outAccounts) { m_pAccountManager->GetAccountsBySerial(strSerial, outAccounts); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 2f260e3ea5..198cd54e1a 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -700,6 +700,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(SString strName, const SString strSerial); 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); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp index 7af41f0e99..13d5d5f23c 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp @@ -42,6 +42,7 @@ void CLuaAccountDefs::LoadFunctions() {"addAccount", AddAccount}, {"removeAccount", RemoveAccount}, {"setAccountPassword", SetAccountPassword}, + {"setAccountSerial", SetAccountSerial}, {"setAccountData", SetAccountData}, {"setAccountName", SetAccountName}, {"copyAccountData", CopyAccountData}, @@ -70,6 +71,7 @@ void CLuaAccountDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setData", "setAccountData"); lua_classfunction(luaVM, "setPassword", "setAccountPassword"); + lua_classfunction(luaVM, "setSerial", "SetAccountSerial"); lua_classfunction(luaVM, "setName", "setAccountName"); lua_classfunction(luaVM, "getSerial", "getAccountSerial"); @@ -513,6 +515,31 @@ int CLuaAccountDefs::RemoveAccount(lua_State* luaVM) return 1; } +int CLuaAccountDefs::SetAccountSerial(lua_State* luaVM) +{ + SString strName; + SString strSerial; + + CScriptArgReader argStream(luaVM); + argStream.ReadString(strName); + argStream.ReadString(strSerial); + + if (!argStream.HasErrors()) + { + if (CStaticFunctionDefinitions::SetAccountSerial(strName, strSerial)) + { + lua_pushboolean(luaVM, true); + return 1; + } + } + else + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + + lua_pushboolean(luaVM, false); + return 1; +} + + int CLuaAccountDefs::SetAccountName(lua_State* luaVM) { // bool setAccountPassword ( account theAccount, string name[, bool allowCaseVariations = false ] ) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h index 1a9fdc45cf..7926b07af6 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h @@ -45,6 +45,7 @@ class CLuaAccountDefs : public CLuaDefs LUA_DECLARE(AddAccount); LUA_DECLARE(RemoveAccount); LUA_DECLARE(SetAccountName); + LUA_DECLARE(SetAccountSerial); LUA_DECLARE(SetAccountPassword); LUA_DECLARE(SetAccountData); LUA_DECLARE(CopyAccountData); From 1b05f7848f681fcc3df38c7e0df973e2921ce652 Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Fri, 19 Jul 2024 21:14:16 -0300 Subject: [PATCH 02/12] :safety_vest: fix: get account name validation --- .../deathmatch/logic/CStaticFunctionDefinitions.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index feb5ff3628..10847f49a3 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -11406,15 +11406,14 @@ bool CStaticFunctionDefinitions::SetAccountSerial(SString strName, SString strSe const char* szAccountName = strName.c_str(); CAccount* pAccount = g_pGame->GetAccountManager()->Get(szAccountName); - if (pAccount){ - bool bRegistered = pAccount->IsRegistered(); - if (bRegistered) - pAccount->SetAccountSerial(strSerial); + if (!pAccount) + return false; - return bRegistered; - } + bool bRegistered = pAccount->IsRegistered(); + if (bRegistered) + pAccount->SetAccountSerial(strSerial); - return false; + return bRegistered; } bool CStaticFunctionDefinitions::GetAccountsBySerial(const SString& strSerial, std::vector& outAccounts) From 62ebf0683dfcd1f45c105ceb8649ca6f9512c67c Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Fri, 19 Jul 2024 22:19:03 -0300 Subject: [PATCH 03/12] :adhesive_bandage: fix: using new ArgumentParser --- Server/mods/deathmatch/logic/CAccount.cpp | 2 +- Server/mods/deathmatch/logic/CAccount.h | 2 +- .../logic/CStaticFunctionDefinitions.cpp | 2 +- .../logic/CStaticFunctionDefinitions.h | 2 +- .../logic/luadefs/CLuaAccountDefs.cpp | 26 +++++-------------- .../logic/luadefs/CLuaAccountDefs.h | 2 +- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/Server/mods/deathmatch/logic/CAccount.cpp b/Server/mods/deathmatch/logic/CAccount.cpp index 3a7dbc9796..1a7f115a27 100644 --- a/Server/mods/deathmatch/logic/CAccount.cpp +++ b/Server/mods/deathmatch/logic/CAccount.cpp @@ -292,7 +292,7 @@ bool CAccount::RemoveSerial(const SString& strSerial) // // Replace the serial number for a specific account // -void CAccount::SetAccountSerial(const SString strSerial) +void CAccount::SetAccountSerial(const std::string strSerial) { m_strSerial = strSerial; m_pManager->MarkAsChanged(this); diff --git a/Server/mods/deathmatch/logic/CAccount.h b/Server/mods/deathmatch/logic/CAccount.h index 910c107e6d..ea0c3e402f 100644 --- a/Server/mods/deathmatch/logic/CAccount.h +++ b/Server/mods/deathmatch/logic/CAccount.h @@ -101,7 +101,7 @@ class CAccount bool AuthorizeSerial(const SString& strSerial, const SString& strWho); bool RemoveSerial(const SString& strSerial); void RemoveUnauthorizedSerials(); - void SetAccountSerial(const SString strSerial); + void SetAccountSerial(const std::string strSerial); CClient* GetClient() const { return m_pClient; } void SetClient(CClient* pClient); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 10847f49a3..7b00c32d90 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -11401,7 +11401,7 @@ bool CStaticFunctionDefinitions::GetAccountSerial(CAccount* pAccount, SString& s } -bool CStaticFunctionDefinitions::SetAccountSerial(SString strName, SString strSerial) +bool CStaticFunctionDefinitions::SetAccountSerial(std::string strName, std::string strSerial) { const char* szAccountName = strName.c_str(); CAccount* pAccount = g_pGame->GetAccountManager()->Get(szAccountName); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 198cd54e1a..5523fb57ec 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -700,7 +700,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(SString strName, const SString strSerial); + static bool SetAccountSerial(std::string strName, std::string strSerial); 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); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp index 13d5d5f23c..a8763f6c36 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp @@ -42,7 +42,7 @@ void CLuaAccountDefs::LoadFunctions() {"addAccount", AddAccount}, {"removeAccount", RemoveAccount}, {"setAccountPassword", SetAccountPassword}, - {"setAccountSerial", SetAccountSerial}, + {"setAccountSerial", ArgumentParser}, {"setAccountData", SetAccountData}, {"setAccountName", SetAccountName}, {"copyAccountData", CopyAccountData}, @@ -71,7 +71,7 @@ void CLuaAccountDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setData", "setAccountData"); lua_classfunction(luaVM, "setPassword", "setAccountPassword"); - lua_classfunction(luaVM, "setSerial", "SetAccountSerial"); + lua_classfunction(luaVM, "setSerial", "setAccountSerial"); lua_classfunction(luaVM, "setName", "setAccountName"); lua_classfunction(luaVM, "getSerial", "getAccountSerial"); @@ -515,28 +515,14 @@ int CLuaAccountDefs::RemoveAccount(lua_State* luaVM) return 1; } -int CLuaAccountDefs::SetAccountSerial(lua_State* luaVM) +bool CLuaAccountDefs::SetAccountSerial(std::string strName, std::string strSerial) { - SString strName; - SString strSerial; - - CScriptArgReader argStream(luaVM); - argStream.ReadString(strName); - argStream.ReadString(strSerial); - - if (!argStream.HasErrors()) + if (CStaticFunctionDefinitions::SetAccountSerial(strName, strSerial)) { - if (CStaticFunctionDefinitions::SetAccountSerial(strName, strSerial)) - { - lua_pushboolean(luaVM, true); - return 1; - } + return true; } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + return false; } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h index 7926b07af6..f11250991a 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h @@ -45,8 +45,8 @@ class CLuaAccountDefs : public CLuaDefs LUA_DECLARE(AddAccount); LUA_DECLARE(RemoveAccount); LUA_DECLARE(SetAccountName); - LUA_DECLARE(SetAccountSerial); LUA_DECLARE(SetAccountPassword); LUA_DECLARE(SetAccountData); LUA_DECLARE(CopyAccountData); + static bool SetAccountSerial(std::string strName, std::string strSerial); }; From 9ad1188744a922fd870f216c09d2c6ece4ca9c48 Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sat, 20 Jul 2024 09:34:58 -0300 Subject: [PATCH 04/12] :adhesive_bandage: fix: removing hungarian notation --- .../logic/CStaticFunctionDefinitions.cpp | 16 ++++++---------- .../logic/CStaticFunctionDefinitions.h | 2 +- .../deathmatch/logic/luadefs/CLuaAccountDefs.cpp | 9 ++------- .../deathmatch/logic/luadefs/CLuaAccountDefs.h | 2 +- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 7b00c32d90..d5844264cc 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -11401,19 +11401,15 @@ bool CStaticFunctionDefinitions::GetAccountSerial(CAccount* pAccount, SString& s } -bool CStaticFunctionDefinitions::SetAccountSerial(std::string strName, std::string strSerial) +bool CStaticFunctionDefinitions::SetAccountSerial(const std::string& name, const std::string& serial) noexcept { - const char* szAccountName = strName.c_str(); - CAccount* pAccount = g_pGame->GetAccountManager()->Get(szAccountName); - - if (!pAccount) - return false; + const char* accountName = name.c_str(); + CAccount* account = g_pGame->GetAccountManager()->Get(accountName); - bool bRegistered = pAccount->IsRegistered(); - if (bRegistered) - pAccount->SetAccountSerial(strSerial); + if (account && account->IsRegistered()) + return account->SetAccountSerial(serial); - return bRegistered; + return false; } bool CStaticFunctionDefinitions::GetAccountsBySerial(const SString& strSerial, std::vector& outAccounts) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 5523fb57ec..6cfd557c33 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -700,7 +700,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(std::string strName, std::string strSerial); + static bool SetAccountSerial(const std::string& name, 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); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp index a8763f6c36..42f997a80a 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp @@ -515,14 +515,9 @@ int CLuaAccountDefs::RemoveAccount(lua_State* luaVM) return 1; } -bool CLuaAccountDefs::SetAccountSerial(std::string strName, std::string strSerial) +bool CLuaAccountDefs::SetAccountSerial(std::string name, std::string serial) noexcept { - if (CStaticFunctionDefinitions::SetAccountSerial(strName, strSerial)) - { - return true; - } - - return false; + return CStaticFunctionDefinitions::SetAccountSerial(name, serial); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h index f11250991a..486eea8127 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h @@ -48,5 +48,5 @@ class CLuaAccountDefs : public CLuaDefs LUA_DECLARE(SetAccountPassword); LUA_DECLARE(SetAccountData); LUA_DECLARE(CopyAccountData); - static bool SetAccountSerial(std::string strName, std::string strSerial); + static bool SetAccountSerial(std::string name, std::string serial) noexcept; }; From be766cf5f9aacc14298d2f702204092ada6ae2ce Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sat, 20 Jul 2024 09:35:50 -0300 Subject: [PATCH 05/12] :safety_vest: fix: serial validation --- Server/mods/deathmatch/logic/CAccount.cpp | 17 +++++++++++++++-- Server/mods/deathmatch/logic/CAccount.h | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Server/mods/deathmatch/logic/CAccount.cpp b/Server/mods/deathmatch/logic/CAccount.cpp index 1a7f115a27..04e677df06 100644 --- a/Server/mods/deathmatch/logic/CAccount.cpp +++ b/Server/mods/deathmatch/logic/CAccount.cpp @@ -255,6 +255,15 @@ bool CAccount::IsIpAuthorized(const SString& strIp) return false; } +// +// Check if the serial has 32 hexadecimal characters +// +bool CAccount::IsValidSerial(const std::string& serial) +{ + const std::regex serialPattern("^[A-Fa-f0-9]{32}$"); + return std::regex_match(serial, serialPattern); +} + // // Mark pending serial as authorized for this account // @@ -292,10 +301,14 @@ bool CAccount::RemoveSerial(const SString& strSerial) // // Replace the serial number for a specific account // -void CAccount::SetAccountSerial(const std::string strSerial) +bool CAccount::SetAccountSerial(const std::string& serial) { - m_strSerial = strSerial; + if (!IsValidSerial(serial)) + return false; + + m_strSerial = serial; m_pManager->MarkAsChanged(this); + return true; } // diff --git a/Server/mods/deathmatch/logic/CAccount.h b/Server/mods/deathmatch/logic/CAccount.h index ea0c3e402f..8953cf2a15 100644 --- a/Server/mods/deathmatch/logic/CAccount.h +++ b/Server/mods/deathmatch/logic/CAccount.h @@ -13,6 +13,7 @@ #include #include +#include #include "lua/CLuaArgument.h" class CClient; @@ -97,11 +98,12 @@ class CAccount SSerialUsage* GetSerialUsage(const SString& strSerial); bool IsIpAuthorized(const SString& strIp); bool IsSerialAuthorized(const SString& strSerial); + bool IsValidSerial(const std::string& serial); bool AddSerialForAuthorization(const SString& strSerial, const SString& strIp); bool AuthorizeSerial(const SString& strSerial, const SString& strWho); bool RemoveSerial(const SString& strSerial); void RemoveUnauthorizedSerials(); - void SetAccountSerial(const std::string strSerial); + bool SetAccountSerial(const std::string& serial); CClient* GetClient() const { return m_pClient; } void SetClient(CClient* pClient); From 7418e4c34a9c6b9e6243e20ec7678c8882ff5f1c Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sat, 20 Jul 2024 13:55:08 -0300 Subject: [PATCH 06/12] :adhesive_bandage: fix: removing setSerial from OOP --- Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp index 42f997a80a..ac667a23c7 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp @@ -71,7 +71,6 @@ void CLuaAccountDefs::AddClass(lua_State* luaVM) lua_classfunction(luaVM, "setData", "setAccountData"); lua_classfunction(luaVM, "setPassword", "setAccountPassword"); - lua_classfunction(luaVM, "setSerial", "setAccountSerial"); lua_classfunction(luaVM, "setName", "setAccountName"); lua_classfunction(luaVM, "getSerial", "getAccountSerial"); From 3bdd277ae082848ade55a1650423d2397ca0eed2 Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sat, 20 Jul 2024 13:56:02 -0300 Subject: [PATCH 07/12] :adhesive_bandage: fix: using noexcept in accounts --- Server/mods/deathmatch/logic/CAccount.cpp | 4 ++-- Server/mods/deathmatch/logic/CAccount.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Server/mods/deathmatch/logic/CAccount.cpp b/Server/mods/deathmatch/logic/CAccount.cpp index 04e677df06..ea502178cc 100644 --- a/Server/mods/deathmatch/logic/CAccount.cpp +++ b/Server/mods/deathmatch/logic/CAccount.cpp @@ -258,7 +258,7 @@ bool CAccount::IsIpAuthorized(const SString& strIp) // // Check if the serial has 32 hexadecimal characters // -bool CAccount::IsValidSerial(const std::string& serial) +bool CAccount::IsValidSerial(const std::string& serial) noexcept { const std::regex serialPattern("^[A-Fa-f0-9]{32}$"); return std::regex_match(serial, serialPattern); @@ -301,7 +301,7 @@ bool CAccount::RemoveSerial(const SString& strSerial) // // Replace the serial number for a specific account // -bool CAccount::SetAccountSerial(const std::string& serial) +bool CAccount::SetAccountSerial(const std::string& serial) noexcept { if (!IsValidSerial(serial)) return false; diff --git a/Server/mods/deathmatch/logic/CAccount.h b/Server/mods/deathmatch/logic/CAccount.h index 8953cf2a15..2d853c7059 100644 --- a/Server/mods/deathmatch/logic/CAccount.h +++ b/Server/mods/deathmatch/logic/CAccount.h @@ -98,12 +98,12 @@ class CAccount SSerialUsage* GetSerialUsage(const SString& strSerial); bool IsIpAuthorized(const SString& strIp); bool IsSerialAuthorized(const SString& strSerial); - bool IsValidSerial(const std::string& serial); + bool IsValidSerial(const std::string& serial) 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); + bool SetAccountSerial(const std::string& serial) noexcept; CClient* GetClient() const { return m_pClient; } void SetClient(CClient* pClient); From 790ffa20b6768d2bd7d559908e2e9c4066bad8ab Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sat, 20 Jul 2024 14:16:23 -0300 Subject: [PATCH 08/12] :adhesive_bandage: fix: using CAccount --- Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 5 +---- Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h | 2 +- Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp | 5 +++-- Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index d5844264cc..59a9ac3e8d 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -11401,11 +11401,8 @@ bool CStaticFunctionDefinitions::GetAccountSerial(CAccount* pAccount, SString& s } -bool CStaticFunctionDefinitions::SetAccountSerial(const std::string& name, const std::string& serial) noexcept +bool CStaticFunctionDefinitions::SetAccountSerial(CAccount* account, const std::string& serial) noexcept { - const char* accountName = name.c_str(); - CAccount* account = g_pGame->GetAccountManager()->Get(accountName); - if (account && account->IsRegistered()) return account->SetAccountSerial(serial); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 6cfd557c33..5bb30e082e 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -700,7 +700,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(const std::string& name, const std::string& serial) noexcept; + 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); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp index ac667a23c7..ffc9c2c06d 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp @@ -72,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"); @@ -514,9 +515,9 @@ int CLuaAccountDefs::RemoveAccount(lua_State* luaVM) return 1; } -bool CLuaAccountDefs::SetAccountSerial(std::string name, std::string serial) noexcept +bool CLuaAccountDefs::SetAccountSerial(CAccount* account, std::string serial) noexcept { - return CStaticFunctionDefinitions::SetAccountSerial(name, serial); + return CStaticFunctionDefinitions::SetAccountSerial(account, serial); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h index 486eea8127..263d12f9da 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.h @@ -48,5 +48,5 @@ class CLuaAccountDefs : public CLuaDefs LUA_DECLARE(SetAccountPassword); LUA_DECLARE(SetAccountData); LUA_DECLARE(CopyAccountData); - static bool SetAccountSerial(std::string name, std::string serial) noexcept; + static bool SetAccountSerial(CAccount* account, std::string serial) noexcept; }; From 9a14e49bcace143548ae52621bc283b491fd5deb Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sat, 20 Jul 2024 14:53:16 -0300 Subject: [PATCH 09/12] :adhesive_bandage: fix: add try catch in IsValidSerial --- Server/mods/deathmatch/logic/CAccount.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CAccount.cpp b/Server/mods/deathmatch/logic/CAccount.cpp index ea502178cc..db58341b4e 100644 --- a/Server/mods/deathmatch/logic/CAccount.cpp +++ b/Server/mods/deathmatch/logic/CAccount.cpp @@ -261,7 +261,12 @@ bool CAccount::IsIpAuthorized(const SString& strIp) bool CAccount::IsValidSerial(const std::string& serial) noexcept { const std::regex serialPattern("^[A-Fa-f0-9]{32}$"); - return std::regex_match(serial, serialPattern); + + try{ + return std::regex_match(serial, serialPattern); + } catch (...) { + return false; + } } // From 94ac0145f302e5ecda0fc72408d03b9378836b99 Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sat, 20 Jul 2024 16:07:26 -0300 Subject: [PATCH 10/12] :adhesive_bandage: fix: const noexcept --- Server/mods/deathmatch/logic/CAccount.cpp | 3 ++- Server/mods/deathmatch/logic/CAccount.h | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/mods/deathmatch/logic/CAccount.cpp b/Server/mods/deathmatch/logic/CAccount.cpp index db58341b4e..dd7dbe3cf3 100644 --- a/Server/mods/deathmatch/logic/CAccount.cpp +++ b/Server/mods/deathmatch/logic/CAccount.cpp @@ -9,6 +9,7 @@ * *****************************************************************************/ +#include #include "StdInc.h" #include "CAccount.h" #include "CAccountManager.h" @@ -258,7 +259,7 @@ bool CAccount::IsIpAuthorized(const SString& strIp) // // Check if the serial has 32 hexadecimal characters // -bool CAccount::IsValidSerial(const std::string& serial) noexcept +bool CAccount::IsValidSerial(const std::string& serial) const noexcept { const std::regex serialPattern("^[A-Fa-f0-9]{32}$"); diff --git a/Server/mods/deathmatch/logic/CAccount.h b/Server/mods/deathmatch/logic/CAccount.h index 2d853c7059..843adf191d 100644 --- a/Server/mods/deathmatch/logic/CAccount.h +++ b/Server/mods/deathmatch/logic/CAccount.h @@ -13,7 +13,6 @@ #include #include -#include #include "lua/CLuaArgument.h" class CClient; @@ -98,7 +97,7 @@ class CAccount SSerialUsage* GetSerialUsage(const SString& strSerial); bool IsIpAuthorized(const SString& strIp); bool IsSerialAuthorized(const SString& strSerial); - bool IsValidSerial(const std::string& serial) noexcept; + 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); From 63baddc8ab9977eb3e5b00c716d8b66b26f6a30a Mon Sep 17 00:00:00 2001 From: Gabriel Camargo Date: Sun, 21 Jul 2024 15:42:45 -0300 Subject: [PATCH 11/12] :adhesive_bandage: fix: add setAccountSerial in acl.xml --- Server/mods/deathmatch/acl.xml | 2 ++ Server/mods/deathmatch/logic/CAccount.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/acl.xml b/Server/mods/deathmatch/acl.xml index 5e4d1292c3..bc89bac29e 100644 --- a/Server/mods/deathmatch/acl.xml +++ b/Server/mods/deathmatch/acl.xml @@ -103,6 +103,7 @@ + @@ -244,6 +245,7 @@ + diff --git a/Server/mods/deathmatch/logic/CAccount.cpp b/Server/mods/deathmatch/logic/CAccount.cpp index dd7dbe3cf3..87584b8e0d 100644 --- a/Server/mods/deathmatch/logic/CAccount.cpp +++ b/Server/mods/deathmatch/logic/CAccount.cpp @@ -9,12 +9,12 @@ * *****************************************************************************/ -#include #include "StdInc.h" #include "CAccount.h" #include "CAccountManager.h" #include "CIdArray.h" #include "CClient.h" +#include 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) From e3b889748680f30f3aed3061bc8e6c4e54994d3b Mon Sep 17 00:00:00 2001 From: Gabriel Camargo <44949646+camargo2019@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:44:15 -0300 Subject: [PATCH 12/12] :adhesive_bandage: fix: moving setAccountSerial to SuperModerator --- Server/mods/deathmatch/acl.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/acl.xml b/Server/mods/deathmatch/acl.xml index bc89bac29e..c6c0f4e8c9 100644 --- a/Server/mods/deathmatch/acl.xml +++ b/Server/mods/deathmatch/acl.xml @@ -189,6 +189,7 @@ + @@ -245,7 +246,6 @@ -