diff --git a/Server/mods/deathmatch/logic/CConsoleCommands.cpp b/Server/mods/deathmatch/logic/CConsoleCommands.cpp index a22c872eeb..c6fddcf152 100644 --- a/Server/mods/deathmatch/logic/CConsoleCommands.cpp +++ b/Server/mods/deathmatch/logic/CConsoleCommands.cpp @@ -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 ..."); + 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 "; - 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 ..."); + 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 "); - return false; + + return true; } bool CConsoleCommands::RefreshResources(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient) @@ -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 ..."); + 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 "); - return false; + return true; } bool CConsoleCommands::StopAllResources(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 3305923b5a..ec5bf9b9d9 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -768,10 +768,10 @@ bool CMainConfig::LoadExtended() CLogger::SetMinLogLevel(LOGLEVEL_LOW); // Register the commands - RegisterCommand("start", CConsoleCommands::StartResource, false, "Usage: start \nStart a loaded resource eg: start admin"); - RegisterCommand("stop", CConsoleCommands::StopResource, false, "Usage: stop \nStop a resource eg: stop admin"); + RegisterCommand("start", CConsoleCommands::StartResource, false, "Usage: start ...\nStart a loaded resource eg: start admin"); + RegisterCommand("stop", CConsoleCommands::StopResource, false, "Usage: stop ...\nStop a resource eg: stop admin"); RegisterCommand("stopall", CConsoleCommands::StopAllResources, false, "Stop all running resources"); - RegisterCommand("restart", CConsoleCommands::RestartResource, false, "Usage: restart \nRestarts a running resource eg: restart admin"); + RegisterCommand("restart", CConsoleCommands::RestartResource, false, "Usage: restart ...\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"); diff --git a/Shared/sdk/SString.h b/Shared/sdk/SString.h index 00c57d0c1e..4874073652 100644 --- a/Shared/sdk/SString.h +++ b/Shared/sdk/SString.h @@ -124,6 +124,8 @@ struct SCharStringRef template class TSplitString : public std::vector { + using std::vector::push_back; + public: TSplitString() {} TSplitString(const STRING_TYPE& strInput, const STRING_TYPE& strDelim, unsigned int uiMaxAmount = 0, unsigned int uiMinAmount = 0)