Skip to content

Commit

Permalink
Merge branch 'master' into TheNormalnij/fix_crash_again
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutchman101 authored Aug 14, 2024
2 parents 39fbce3 + 1532130 commit 67bee38
Show file tree
Hide file tree
Showing 16 changed files with 1,980 additions and 2,206 deletions.
11 changes: 9 additions & 2 deletions Client/core/CCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool

// Grab the command
tagCOMMANDENTRY* pEntry = Get(szCommand);
bool wasHandled = false;
if (pEntry)
{
// If its a core command, or if its enabled
Expand All @@ -133,13 +134,16 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
// Execute it
if (!bIsScriptedBind || pEntry->bAllowScriptedBind)
ExecuteHandler(pEntry->pfnCmdFunc, szParameters);

wasHandled = true;
}
}

// Recompose the original command text
std::string val = std::string(szCommand) + " " + std::string(szParameters ? szParameters : "");

// Is it a cvar? (syntax: cvar[ = value])
if (!wasHandled)
{
// Check to see if '=' exists
unsigned int nOpIndex = val.find('=');
Expand Down Expand Up @@ -187,7 +191,7 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool

// HACK: if its a 'nick' command, save it here
bool bIsNickCommand = !stricmp(szCommand, "nick");
if (bIsNickCommand && szParameters && !bIsScriptedBind)
if (!wasHandled && bIsNickCommand && szParameters && !bIsScriptedBind)
{
if (CCore::GetSingleton().IsValidNick(szParameters))
{
Expand All @@ -208,10 +212,13 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
if (m_pfnExecuteHandler)
{
bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind);
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind))
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, wasHandled, bIsScriptedBind, bAllowScriptedBind))
return true;
}

if (wasHandled)
return true;

// Unknown command
val = _("Unknown command or cvar: ") + szCommand;
if (!bIsScriptedBind && !bIsNickCommand && pEntry == nullptr)
Expand Down
8 changes: 3 additions & 5 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5590,7 +5590,7 @@ void CClientGame::ResetMapInfo()
if (pPlayerInfo)
pPlayerInfo->SetCamDrunkLevel(static_cast<byte>(0));

RestreamWorld(true);
RestreamWorld();

ReinitMarkers();
}
Expand Down Expand Up @@ -6813,7 +6813,7 @@ void CClientGame::RestreamModel(unsigned short usModel)
m_pManager->GetVehicleManager()->RestreamVehicleUpgrades(usModel);
}

void CClientGame::RestreamWorld(bool removeBigBuildings)
void CClientGame::RestreamWorld()
{
unsigned int numberOfFileIDs = g_pGame->GetCountOfAllFileIDs();

Expand All @@ -6826,9 +6826,7 @@ void CClientGame::RestreamWorld(bool removeBigBuildings)
m_pManager->GetPedManager()->RestreamAllPeds();
m_pManager->GetPickupManager()->RestreamAllPickups();

if (removeBigBuildings)
g_pGame->GetStreaming()->RemoveBigBuildings();

g_pGame->GetStreaming()->RemoveBigBuildings();
g_pGame->GetStreaming()->ReinitStreaming();
}

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class CClientGame

bool TriggerBrowserRequestResultEvent(const std::unordered_set<SString>& newPages);
void RestreamModel(unsigned short usModel);
void RestreamWorld(bool removeBigBuildings);
void RestreamWorld();
void ReinitMarkers();

void OnWindowFocusChange(bool state);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientIMG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ bool CClientIMG::StreamDisable()

m_pImgManager->UpdateStreamerBufferSize();

g_pClientGame->RestreamWorld(true);
g_pClientGame->RestreamWorld();
return true;
}

Expand Down
16 changes: 2 additions & 14 deletions Client/mods/deathmatch/logic/CScriptFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
DoResourceFileCheck();

// If read size is large, limit it to how many bytes can be read (avoid memory problems with over allocation)
// large : >10KB
if (ulSize > 10240)
if (ulSize > 10000)
{
long lCurrentPos = m_pFile->FTell();
m_pFile->FSeek(0, SEEK_END);
Expand All @@ -178,18 +177,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
return -2;
}

auto bytesRead = m_pFile->FRead(outBuffer.data(), ulSize);

// EOF reached?
// Cant check for error as binary interface
// is pure virtual class with no definitions
// available (CNetServer)
if (m_pFile->FEof())
{
// if so, truncate the data to the amount of bytes read
outBuffer.resize(bytesRead + 1);
}
return bytesRead;
return m_pFile->FRead(outBuffer.data(), ulSize);
}

long CScriptFile::Write(unsigned long ulSize, const char* pData)
Expand Down
15 changes: 0 additions & 15 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,11 +1268,6 @@ void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisRe
// No operation on the client
}

std::pair<bool, std::string> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept
{
return {true, ""};
}

//
// Set error if pThisResource does not have permission to modify every resource in resourceList
//
Expand All @@ -1281,11 +1276,6 @@ void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisR
// No operation on the client
}

std::pair<bool, std::string> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept
{
return {true, ""};
}

//
// Set error if resource file access is blocked due to reasons
//
Expand All @@ -1294,8 +1284,3 @@ void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pTh
{
// No operation on the client
}

std::pair<bool, std::string> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly) noexcept
{
return {true, ""};
}
6 changes: 1 addition & 5 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,9 @@ void ReadPregFlags(CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions);
// Resource access helpers
//
void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource);
std::pair<bool, std::string> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept;
void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisResource, std::initializer_list<CResource*> resourceList);
std::pair<bool, std::string> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept;
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
bool* pbReadOnly = nullptr);
std::pair<bool, std::string> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
bool* pbReadOnly = nullptr) noexcept;

//
// Other misc helpers
Expand Down
9 changes: 2 additions & 7 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,14 +2428,9 @@ bool CLuaEngineDefs::EngineResetModelFlags(uint uiModelID)
return false;
}

bool CLuaEngineDefs::EngineRestreamWorld(lua_State* const luaVM)
bool CLuaEngineDefs::EngineRestreamWorld()
{
bool restreamLODs{};

CScriptArgReader argStream(luaVM);
argStream.ReadBool(restreamLODs, false);

g_pClientGame->RestreamWorld(restreamLODs);
g_pClientGame->RestreamWorld();
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CLuaEngineDefs : public CLuaDefs
static bool EngineRestoreTXDImage(uint uiModelID);
static std::vector<std::string_view> EngineImageGetFileList(CClientIMG* pImg);
static std::string EngineImageGetFile(CClientIMG* pImg, std::variant<size_t, std::string_view> file);
static bool EngineRestreamWorld(lua_State* const luaVM);
static bool EngineRestreamWorld();
static bool EngineSetModelVisibleTime(std::string strModelId, char cHourOn, char cHourOff);
static std::variant<bool, CLuaMultiReturn<char, char>> EngineGetModelVisibleTime(std::string strModelId);

Expand Down
13 changes: 2 additions & 11 deletions Server/mods/deathmatch/logic/CScriptFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
return -1;

// If read size is large, limit it to how many bytes can be read (avoid memory problems with over allocation)
// large : >10KB
if (ulSize > 10240)
if (ulSize > 10000)
{
long lCurrentPos = ftell(m_pFile);
fseek(m_pFile, 0, SEEK_END);
Expand All @@ -198,15 +197,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
return -2;
}

auto bytesRead = fread(outBuffer.data(), 1, ulSize, m_pFile);

// EOF reached or error was thrown?
if (feof(m_pFile) || ferror(m_pFile))
{
// if so, truncate the data to the amount of bytes read
outBuffer.resize(bytesRead + 1);
}
return bytesRead;
return fread(outBuffer.data(), 1, ulSize, m_pFile);
}

long CScriptFile::Write(unsigned long ulSize, const char* pData)
Expand Down
76 changes: 0 additions & 76 deletions Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,17 +746,6 @@ void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisRe
"Access denied");
}

std::pair<bool, SString> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept
{
if (GetResourceModifyScope(pThisResource, pOtherResource) != eResourceModifyScope::NONE)
return {true, ""};

SString str("ModifyOtherObjects in ACL denied resource %s to access %s",
pThisResource->GetName().c_str(), pOtherResource->GetName().c_str()
);
return {false, str};
}

//
// Set error if pThisResource does not have permission to modify every resource in resourceList
//
Expand Down Expand Up @@ -798,46 +787,6 @@ void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisR
SString("ModifyOtherObjects in ACL denied resource %s to access %s", pThisResource->GetName().c_str(), ssResourceNames.str().c_str()), "Access denied");
}

std::pair<bool, SString> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept
{
// std::unordered_set only allows unique values and resourceList can contain duplicates
std::unordered_set<CResource*> setNoPermissionResources;

for (const auto& pOtherResource : resourceList)
{
eResourceModifyScope modifyScope = GetResourceModifyScope(pThisResource, pOtherResource);

if (modifyScope == eResourceModifyScope::SINGLE_RESOURCE)
continue;

if (modifyScope == eResourceModifyScope::EVERY_RESOURCE)
return {true, ""};

setNoPermissionResources.emplace(pOtherResource);
}

if (setNoPermissionResources.empty())
return {true, ""};

std::stringstream ssResourceNames;
std::size_t remainingElements = setNoPermissionResources.size();

for (const auto& pResource : setNoPermissionResources)
{
ssResourceNames << pResource->GetName();

if (remainingElements > 1)
ssResourceNames << ", ";

--remainingElements;
}

SString str("ModifyOtherObjects in ACL denied resource %s to access %s",
pThisResource->GetName().c_str(), ssResourceNames.str().c_str()
);
return {false, str};
}

//
// Set error if resource file access is blocked due to reasons
//
Expand All @@ -864,28 +813,3 @@ void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pTh
SString("Database credentials protection denied resource %s to access %s", *pThisResource->GetName(), *pOtherResource->GetName()), "Access denied");
}
}

std::pair<bool, SString> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly) noexcept
{
if (!g_pGame->GetConfig()->IsDatabaseCredentialsProtectionEnabled())
return {true, ""};

// Is other resource different and requested access denied
if (pThisResource == pOtherResource)
return {true, ""};

if (!pOtherResource->IsFileDbConnectMysqlProtected(strAbsPath, pbReadOnly ? *pbReadOnly : false))
return {true, ""};

// No access - See if we can change to readonly
if (pbReadOnly && !(*pbReadOnly) && !pOtherResource->IsFileDbConnectMysqlProtected(strAbsPath, true)) {
// Yes readonly access
*pbReadOnly = true;
return {true, ""};
}

SString str("Database credentials protection denied resource %s to access %s",
*pThisResource->GetName(), *pOtherResource->GetName()
);
return {false, str};
}
5 changes: 1 addition & 4 deletions Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,9 @@ enum class eResourceModifyScope

eResourceModifyScope GetResourceModifyScope(CResource* pThisResource, CResource* pOtherResource);
void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource);
std::pair<bool, SString> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept;
void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisResource, std::initializer_list<CResource*> resourceList);
std::pair<bool, SString> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept;
void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisResource, std::initializer_list<CResource*> resourceList);
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
bool* pbReadOnly = nullptr);
std::pair<bool, SString> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly = nullptr) noexcept;

//
// Other misc helpers
Expand Down
Loading

0 comments on commit 67bee38

Please sign in to comment.