Skip to content

Commit

Permalink
Merge branch 'master' into feature/panelstates_flyingComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored Jan 2, 2025
2 parents 85dc2e4 + 0f9e18d commit 4710798
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 93 deletions.
209 changes: 119 additions & 90 deletions Server/mods/deathmatch/logic/CConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,85 +62,104 @@ static void EndConsoleOutputCapture(CClient* pClient, const SString& strIfNoOutp

bool CConsoleCommands::StartResource(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)
{
SString strResponse;
if (!szArguments || !szArguments[0])
{
pEchoClient->SendConsole("* Syntax: start <resource1> <resource2> ...");
return false;
}

if (szArguments && szArguments[0])
if (pClient->GetNick())
CLogger::LogPrintf("start: Requested by %s\n", GetAdminNameForLog(pClient).c_str());

CSplitString resourceNames(szArguments, " ");
CResourceManager* resourceManager = g_pGame->GetResourceManager();

for (const std::string& resourceName : resourceNames)
{
CResource* resource = g_pGame->GetResourceManager()->GetResource(szArguments);
if (resource)
CResource* resource = resourceManager->GetResource(resourceName.c_str());

if (!resource)
{
if (pClient->GetNick())
CLogger::LogPrintf("start: Requested by %s\n", GetAdminNameForLog(pClient).c_str());
pEchoClient->SendConsole(SString("start: Resource '%s' could not be found", resourceName.c_str()));
continue;
}

if (resource->IsLoaded())
{
if (!resource->IsActive())
{
if (g_pGame->GetResourceManager()->StartResource(resource, NULL, true))
{
strResponse = SString("start: Resource '%s' started", szArguments);
}
else
{
strResponse = SString("start: Resource '%s' start was requested (%s)", szArguments, resource->GetFailureReason().c_str());
}
}
else
strResponse = "start: Resource is already running";
}
else
strResponse = SString("start: Resource is loaded, but has errors (%s)", resource->GetFailureReason().c_str());
if (!resource->IsLoaded())
{
pEchoClient->SendConsole(SString("start: Resource '%s' is loaded, but has errors (%s)", resourceName.c_str(), resource->GetFailureReason().c_str()));
continue;
}

if (resource->IsActive())
{
pEchoClient->SendConsole(SString("start: Resource '%s' is already running", resourceName.c_str()));
continue;
}

if (resourceManager->StartResource(resource, nullptr, true))
{
pEchoClient->SendConsole(SString("start: Resource '%s' started", resourceName.c_str()));
}
else
strResponse = "start: Resource could not be found";
{
pEchoClient->SendConsole(SString("start: Resource '%s' start was requested (%s)", resourceName.c_str(), resource->GetFailureReason().c_str()));
}
}
else
strResponse = "* Syntax: start <resource-name>";

pEchoClient->SendConsole(strResponse);
return true;
}

bool CConsoleCommands::RestartResource(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)
{
if (szArguments && szArguments[0])
if (!szArguments || !szArguments[0])
{
CResource* resource = g_pGame->GetResourceManager()->GetResource(szArguments);
if (resource)
pEchoClient->SendConsole("* Syntax: restart <resource1> <resource2> ...");
return false;
}

if (pClient->GetNick())
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(pClient).c_str());

CSplitString resourceNames(szArguments, " ");
CResourceManager* resourceManager = g_pGame->GetResourceManager();

for (const std::string& resourceName : resourceNames)
{
CResource* resource = resourceManager->GetResource(resourceName.c_str());

if (!resource)
{
if (pClient->GetNick())
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(pClient).c_str());
pEchoClient->SendConsole(SString("restart: Resource '%s' could not be found", resourceName.c_str()));
continue;
}

if (resource->IsLoaded())
{
if (resource->IsActive())
{
if (resource->IsProtected())
{
if (!g_pGame->GetACLManager()->CanObjectUseRight(pClient->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER,
"restart.protected", CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
{
pEchoClient->SendConsole("restart: Resource could not be restarted as it is protected");
return false;
}
}
if (!resource->IsLoaded())
{
pEchoClient->SendConsole(SString("restart: Resource '%s' is loaded, but has errors (%s)", resourceName.c_str(), resource->GetFailureReason().c_str()));
continue;
}

g_pGame->GetResourceManager()->QueueResource(resource, CResourceManager::QUEUE_RESTART, NULL);
pEchoClient->SendConsole("restart: Resource restarting...");
}
else
pEchoClient->SendConsole("restart: Resource is not running");
if (!resource->IsActive())
{
pEchoClient->SendConsole(SString("restart: Resource '%s' is not running", resourceName.c_str()));
continue;
}

if (resource->IsProtected())
{
if (!g_pGame->GetACLManager()->CanObjectUseRight(pClient->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "restart.protected",
CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
{
pEchoClient->SendConsole(SString("restart: Resource '%s' could not be restarted as it is protected", resourceName.c_str()));
continue;
}
else
pEchoClient->SendConsole(SString("restart: Resource is loaded, but has errors (%s)", resource->GetFailureReason().c_str()));
}
else
pEchoClient->SendConsole("restart: Resource could not be found");
return true;

resourceManager->QueueResource(resource, CResourceManager::QUEUE_RESTART, nullptr);
pEchoClient->SendConsole(SString("restart: Resource '%s' restarting...", resourceName.c_str()));
}
else
pEchoClient->SendConsole("* Syntax: restart <resource-name>");
return false;

return true;
}

bool CConsoleCommands::RefreshResources(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)
Expand Down Expand Up @@ -195,45 +214,55 @@ bool CConsoleCommands::ResourceInfo(CConsole* pConsole, const char* szArguments,

bool CConsoleCommands::StopResource(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)
{
if (szArguments && szArguments[0])
if (!szArguments || !szArguments[0])
{
CResource* resource = g_pGame->GetResourceManager()->GetResource(szArguments);
if (resource)
pEchoClient->SendConsole("* Syntax: stop <resource1> <resource2> ...");
return false;
}

if (pClient->GetNick())
CLogger::LogPrintf("stop: Requested by %s\n", GetAdminNameForLog(pClient).c_str());

CSplitString resourceNames(szArguments, " ");
CResourceManager* resourceManager = g_pGame->GetResourceManager();

for (const std::string& resourceName : resourceNames)
{
CResource* resource = resourceManager->GetResource(resourceName.c_str());

if (!resource)
{
if (pClient->GetNick())
CLogger::LogPrintf("stop: Requested by %s\n", GetAdminNameForLog(pClient).c_str());
pEchoClient->SendConsole(SString("stop: Resource '%s' could not be found", resourceName.c_str()));
continue;
}

if (resource->IsLoaded())
{
if (resource->IsActive())
{
if (resource->IsProtected())
{
if (!g_pGame->GetACLManager()->CanObjectUseRight(pClient->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "stop.protected",
CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
{
pEchoClient->SendConsole("stop: Resource could not be stopped as it is protected");
return false;
}
}
if (!resource->IsLoaded())
{
pEchoClient->SendConsole(SString("stop: Resource '%s' is loaded, but has errors (%s)", resourceName.c_str(), resource->GetFailureReason().c_str()));
continue;
}

g_pGame->GetResourceManager()->QueueResource(resource, CResourceManager::QUEUE_STOP, NULL);
pEchoClient->SendConsole("stop: Resource stopping");
}
else
pEchoClient->SendConsole("stop: Resource is not running");
if (!resource->IsActive())
{
pEchoClient->SendConsole(SString("stop: Resource '%s' is not running", resourceName.c_str()));
continue;
}

if (resource->IsProtected())
{
if (!g_pGame->GetACLManager()->CanObjectUseRight(pClient->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "stop.protected",
CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
{
pEchoClient->SendConsole(SString("stop: Resource '%s' could not be stopped as it is protected", resourceName.c_str()));
continue;
}
else
pEchoClient->SendConsole(SString("stop: Resource is loaded, but has errors (%s)", resource->GetFailureReason().c_str()));
}
else
pEchoClient->SendConsole("stop: Resource could not be found");
return true;

resourceManager->QueueResource(resource, CResourceManager::QUEUE_STOP, nullptr);
pEchoClient->SendConsole(SString("stop: Resource '%s' stopping...", resourceName.c_str()));
}
else
pEchoClient->SendConsole("* Syntax: stop <resource-name>");

return false;
return true;
}

bool CConsoleCommands::StopAllResources(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)
Expand Down
6 changes: 3 additions & 3 deletions Server/mods/deathmatch/logic/CMainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,10 @@ bool CMainConfig::LoadExtended()
CLogger::SetMinLogLevel(LOGLEVEL_LOW);

// Register the commands
RegisterCommand("start", CConsoleCommands::StartResource, false, "Usage: start <resource-name>\nStart a loaded resource eg: start admin");
RegisterCommand("stop", CConsoleCommands::StopResource, false, "Usage: stop <resource-name>\nStop a resource eg: stop admin");
RegisterCommand("start", CConsoleCommands::StartResource, false, "Usage: start <resource1> <resource2> ...\nStart a loaded resource eg: start admin");
RegisterCommand("stop", CConsoleCommands::StopResource, false, "Usage: stop <resource1> <resource2> ...\nStop a resource eg: stop admin");
RegisterCommand("stopall", CConsoleCommands::StopAllResources, false, "Stop all running resources");
RegisterCommand("restart", CConsoleCommands::RestartResource, false, "Usage: restart <resource-name>\nRestarts a running resource eg: restart admin");
RegisterCommand("restart", CConsoleCommands::RestartResource, false, "Usage: restart <resource1> <resource2> ...\nRestarts a running resource eg: restart admin");
RegisterCommand("refresh", CConsoleCommands::RefreshResources, false, "Refresh resource list to find new resources");
RegisterCommand("refreshall", CConsoleCommands::RefreshAllResources, false, "Refresh resources and restart any changed resources");
RegisterCommand("list", CConsoleCommands::ListResources, false, "Shows a list of resources");
Expand Down
2 changes: 2 additions & 0 deletions Shared/sdk/SString.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ struct SCharStringRef
template <class STRING_TYPE, class CHAR_TYPE>
class TSplitString : public std::vector<const CHAR_TYPE*>
{
using std::vector<const CHAR_TYPE*>::push_back;

public:
TSplitString() {}
TSplitString(const STRING_TYPE& strInput, const STRING_TYPE& strDelim, unsigned int uiMaxAmount = 0, unsigned int uiMinAmount = 0)
Expand Down

0 comments on commit 4710798

Please sign in to comment.