Skip to content

Commit ff5608d

Browse files
committed
Remove the ensure command, change the behavior of the restart command
1 parent 8110d5a commit ff5608d

File tree

3 files changed

+22
-175
lines changed

3 files changed

+22
-175
lines changed

Server/mods/deathmatch/logic/CConsoleCommands.cpp

Lines changed: 22 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ bool CConsoleCommands::StartResource(CConsole* const console, const char* argume
212212
return true;
213213
}
214214

215-
bool CConsoleCommands::EnsureResource(CConsole* const console, const char* arguments, CClient* const client, CClient* const echo)
215+
bool CConsoleCommands::RestartResource(CConsole* const console, const char* arguments, CClient* const client, CClient* const echo)
216216
{
217217
if (!arguments || !arguments[0])
218218
{
219-
echo->SendConsole("* Syntax: ensure <resource> [<resource> ...] or ensure <directory> [<directory> ...]");
219+
echo->SendConsole("* Syntax: restart <resource> [<resource> ...] or restart <directory> [<directory> ...]");
220220
return false;
221221
}
222222

@@ -238,7 +238,7 @@ bool CConsoleCommands::EnsureResource(CConsole* const console, const char* argum
238238

239239
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir))
240240
{
241-
response = "ensure: Directory '" + name + "' does not exist or is not a valid directory";
241+
response = "restart: Directory '" + name + "' does not exist or is not a valid directory";
242242
echo->SendConsole(response.c_str());
243243
continue;
244244
}
@@ -256,42 +256,42 @@ bool CConsoleCommands::EnsureResource(CConsole* const console, const char* argum
256256
continue;
257257

258258
if (client->GetNick())
259-
CLogger::LogPrintf("ensure: Requested by %s\n", GetAdminNameForLog(client).c_str());
259+
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(client).c_str());
260260

261261
if (!resource->IsLoaded())
262262
{
263-
response = "ensure: Resource '" + filename + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
263+
response = "restart: Resource '" + filename + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
264264
echo->SendConsole(response.c_str());
265265
continue;
266266
}
267267

268268
if (!resource->IsActive())
269269
{
270-
response = "ensure: Resource '" + filename + "' is not running, starting now...";
270+
response = "restart: Resource '" + filename + "' is not running, starting now...";
271271
echo->SendConsole(response.c_str());
272272

273273
if (g_pGame->GetResourceManager()->StartResource(resource, nullptr, true))
274274
{
275-
response = "ensure: Resource '" + filename + "' started";
275+
response = "restart: Resource '" + filename + "' started";
276276
echo->SendConsole(response.c_str());
277277
}
278278
else
279279
{
280-
response = "ensure: Resource '" + filename + "' start was requested (" + resource->GetFailureReason() + ")";
280+
response = "restart: Resource '" + filename + "' start was requested (" + resource->GetFailureReason() + ")";
281281
echo->SendConsole(response.c_str());
282282
}
283283
continue;
284284
}
285285

286286
if (resource->IsProtected() && !g_pGame->GetACLManager()->CanObjectUseRight(client->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "restart.protected", CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
287287
{
288-
response = "ensure: Resource '" + filename + "' could not be ensured as it is protected";
288+
response = "restart: Resource '" + filename + "' could not be restarted as it is protected";
289289
echo->SendConsole(response.c_str());
290290
continue;
291291
}
292292

293293
g_pGame->GetResourceManager()->QueueResource(resource, CResourceManager::QUEUE_RESTART, nullptr);
294-
response = "ensure: Resource '" + filename + "' restarting...";
294+
response = "restart: Resource '" + filename + "' restarting...";
295295
echo->SendConsole(response.c_str());
296296
}
297297
else if (entry.is_regular_file() && path.extension() == ".zip")
@@ -302,42 +302,42 @@ bool CConsoleCommands::EnsureResource(CConsole* const console, const char* argum
302302
continue;
303303

304304
if (client->GetNick())
305-
CLogger::LogPrintf("ensure: Requested by %s\n", GetAdminNameForLog(client).c_str());
305+
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(client).c_str());
306306

307307
if (!resource->IsLoaded())
308308
{
309-
response = "ensure: Resource '" + filename + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
309+
response = "restart: Resource '" + filename + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
310310
echo->SendConsole(response.c_str());
311311
continue;
312312
}
313313

314314
if (!resource->IsActive())
315315
{
316-
response = "ensure: Resource '" + filename + "' is not running, starting now...";
316+
response = "restart: Resource '" + filename + "' is not running, starting now...";
317317
echo->SendConsole(response.c_str());
318318

319319
if (g_pGame->GetResourceManager()->StartResource(resource, nullptr, true))
320320
{
321-
response = "ensure: Resource '" + filename + "' started";
321+
response = "restart: Resource '" + filename + "' started";
322322
echo->SendConsole(response.c_str());
323323
}
324324
else
325325
{
326-
response = "ensure: Resource '" + filename + "' start was requested (" + resource->GetFailureReason() + ")";
326+
response = "restart: Resource '" + filename + "' start was requested (" + resource->GetFailureReason() + ")";
327327
echo->SendConsole(response.c_str());
328328
}
329329
continue;
330330
}
331331

332332
if (resource->IsProtected() && !g_pGame->GetACLManager()->CanObjectUseRight(client->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "restart.protected", CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
333333
{
334-
response = "ensure: Resource '" + filename + "' could not be ensured as it is protected";
334+
response = "restart: Resource '" + filename + "' could not be restarted as it is protected";
335335
echo->SendConsole(response.c_str());
336336
continue;
337337
}
338338

339339
g_pGame->GetResourceManager()->QueueResource(resource, CResourceManager::QUEUE_RESTART, nullptr);
340-
response = "ensure: Resource '" + filename + "' restarting...";
340+
response = "restart: Resource '" + filename + "' restarting...";
341341
echo->SendConsole(response.c_str());
342342
}
343343
}
@@ -350,184 +350,33 @@ bool CConsoleCommands::EnsureResource(CConsole* const console, const char* argum
350350
continue;
351351

352352
if (client->GetNick())
353-
CLogger::LogPrintf("ensure: Requested by %s\n", GetAdminNameForLog(client).c_str());
353+
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(client).c_str());
354354

355355
if (!resource->IsLoaded())
356356
{
357-
response = "ensure: Resource '" + name + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
357+
response = "restart: Resource '" + name + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
358358
echo->SendConsole(response.c_str());
359359
continue;
360360
}
361361

362362
if (!resource->IsActive())
363363
{
364-
response = "ensure: Resource '" + name + "' is not running, starting now...";
364+
response = "restart: Resource '" + name + "' is not running, starting now...";
365365
echo->SendConsole(response.c_str());
366366

367367
if (g_pGame->GetResourceManager()->StartResource(resource, nullptr, true))
368368
{
369-
response = "ensure: Resource '" + name + "' started";
369+
response = "restart: Resource '" + name + "' started";
370370
echo->SendConsole(response.c_str());
371371
}
372372
else
373373
{
374-
response = "ensure: Resource '" + name + "' start was requested (" + resource->GetFailureReason() + ")";
374+
response = "restart: Resource '" + name + "' start was requested (" + resource->GetFailureReason() + ")";
375375
echo->SendConsole(response.c_str());
376376
}
377377
continue;
378378
}
379379

380-
if (resource->IsProtected() && !g_pGame->GetACLManager()->CanObjectUseRight(client->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "restart.protected", CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
381-
{
382-
response = "ensure: Resource '" + name + "' could not be ensured as it is protected";
383-
echo->SendConsole(response.c_str());
384-
continue;
385-
}
386-
387-
g_pGame->GetResourceManager()->QueueResource(resource, CResourceManager::QUEUE_RESTART, nullptr);
388-
response = "ensure: Resource '" + name + "' restarting...";
389-
echo->SendConsole(response.c_str());
390-
}
391-
392-
return true;
393-
}
394-
395-
bool CConsoleCommands::RestartResource(CConsole* const console, const char* arguments, CClient* const client, CClient* const echo)
396-
{
397-
if (!arguments || !arguments[0])
398-
{
399-
echo->SendConsole("* Syntax: restart <resource> [<resource> ...] or restart <directory> [<directory> ...]");
400-
return false;
401-
}
402-
403-
std::istringstream iss(arguments);
404-
std::vector<std::string> names((std::istream_iterator<std::string>(iss)), std::istream_iterator<std::string>());
405-
406-
for (const auto& name : names)
407-
{
408-
std::string str = name;
409-
std::string response;
410-
411-
if (str.front() == '[' && str.back() == ']')
412-
{
413-
str = str.substr(1, str.length() - 2);
414-
415-
std::filesystem::path mods(g_pServerInterface->GetModManager()->GetModPath());
416-
std::filesystem::path resources("resources");
417-
std::filesystem::path dir = mods / resources / name;
418-
419-
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir))
420-
{
421-
response = "restart: Directory '" + name + "' does not exist or is not a valid directory";
422-
echo->SendConsole(response.c_str());
423-
continue;
424-
}
425-
426-
for (const auto& entry : std::filesystem::directory_iterator(dir))
427-
{
428-
const auto& path = entry.path();
429-
const auto filename = path.filename().string();
430-
431-
if (entry.is_directory() && std::filesystem::exists(path / "meta.xml"))
432-
{
433-
CResource* resource = g_pGame->GetResourceManager()->GetResource(filename.c_str());
434-
435-
if (!resource)
436-
continue;
437-
438-
if (client->GetNick())
439-
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(client).c_str());
440-
441-
if (!resource->IsLoaded())
442-
{
443-
response = "restart: Resource '" + filename + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
444-
echo->SendConsole(response.c_str());
445-
continue;
446-
}
447-
448-
if (!resource->IsActive())
449-
{
450-
response = "restart: Resource '" + filename + "' is not running";
451-
echo->SendConsole(response.c_str());
452-
continue;
453-
}
454-
455-
if (resource->IsProtected() && !g_pGame->GetACLManager()->CanObjectUseRight(client->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "restart.protected", CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
456-
{
457-
response = "restart: Resource '" + filename + "' could not be restarted as it is protected";
458-
echo->SendConsole(response.c_str());
459-
continue;
460-
}
461-
462-
g_pGame->GetResourceManager()->QueueResource(resource, CResourceManager::QUEUE_RESTART, nullptr);
463-
response = "restart: Resource '" + filename + "' restarting...";
464-
echo->SendConsole(response.c_str());
465-
}
466-
else if (entry.is_regular_file() && path.extension() == ".zip")
467-
{
468-
CResource* resource = g_pGame->GetResourceManager()->GetResource(filename.c_str());
469-
470-
if (!resource)
471-
continue;
472-
473-
if (client->GetNick())
474-
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(client).c_str());
475-
476-
if (!resource->IsLoaded())
477-
{
478-
response = "restart: Resource '" + filename + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
479-
echo->SendConsole(response.c_str());
480-
continue;
481-
}
482-
483-
if (!resource->IsActive())
484-
{
485-
response = "restart: Resource '" + filename + "' is not running";
486-
echo->SendConsole(response.c_str());
487-
continue;
488-
}
489-
490-
if (resource->IsProtected() && !g_pGame->GetACLManager()->CanObjectUseRight(client->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "restart.protected", CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
491-
{
492-
response = "restart: Resource '" + filename + "' could not be restarted as it is protected";
493-
echo->SendConsole(response.c_str());
494-
continue;
495-
}
496-
497-
g_pGame->GetResourceManager()->QueueResource(resource, CResourceManager::QUEUE_RESTART, nullptr);
498-
response = "restart: Resource '" + filename + "' restarting...";
499-
echo->SendConsole(response.c_str());
500-
}
501-
}
502-
continue;
503-
}
504-
505-
CResource* resource = g_pGame->GetResourceManager()->GetResource(name.c_str());
506-
507-
if (!resource)
508-
{
509-
response = "restart: Resource '" + name + "' could not be found";
510-
echo->SendConsole(response.c_str());
511-
continue;
512-
}
513-
514-
if (client->GetNick())
515-
CLogger::LogPrintf("restart: Requested by %s\n", GetAdminNameForLog(client).c_str());
516-
517-
if (!resource->IsLoaded())
518-
{
519-
response = "restart: Resource '" + name + "' is loaded, but has errors (" + resource->GetFailureReason() + ")";
520-
echo->SendConsole(response.c_str());
521-
continue;
522-
}
523-
524-
if (!resource->IsActive())
525-
{
526-
response = "restart: Resource '" + name + "' is not running";
527-
echo->SendConsole(response.c_str());
528-
continue;
529-
}
530-
531380
if (resource->IsProtected() && !g_pGame->GetACLManager()->CanObjectUseRight(client->GetNick(), CAccessControlListGroupObject::OBJECT_TYPE_USER, "restart.protected", CAccessControlListRight::RIGHT_TYPE_COMMAND, false))
532381
{
533382
response = "restart: Resource '" + name + "' could not be restarted as it is protected";

Server/mods/deathmatch/logic/CConsoleCommands.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class CConsoleCommands
1919
static bool StartResource(class CConsole* const console, const char* arguments, CClient* const client, CClient* const echo);
2020
static bool StopResource(class CConsole* const console, const char* arguments, CClient* const client, CClient* const echo);
2121
static bool StopAllResources(class CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient);
22-
static bool EnsureResource(class CConsole* const console, const char* arguments, CClient* const client, CClient* const echo);
2322
static bool RestartResource(class CConsole* const console, const char* arguments, CClient* const client, CClient* const echo);
2423
static bool RefreshResources(class CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient);
2524
static bool RefreshAllResources(class CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient);

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,6 @@ bool CMainConfig::LoadExtended()
771771
RegisterCommand("start", CConsoleCommands::StartResource, false, "Usage: start <resource> [<resource> ...] or start <directory> [<directory> ...]\nStart one or more resources, or start all resources in a directory");
772772
RegisterCommand("stop", CConsoleCommands::StopResource, false, "Usage: stop <resource> [<resource> ...] or stop <directory> [<directory> ...]\nStop one or more resources, or stop all resources in a directory");
773773
RegisterCommand("stopall", CConsoleCommands::StopAllResources, false, "Stop all running resources");
774-
RegisterCommand("ensure", CConsoleCommands::EnsureResource, false, "Usage: ensure <resource> [<resource> ...] or ensure <directory> [<directory> ...]\nEnsure one or more resources, or ensure all resources in a directory");
775774
RegisterCommand("restart", CConsoleCommands::RestartResource, false, "Usage: restart <resource> [<resource> ...] or restart <directory> [<directory> ...]\nRestart one or more resources, or restart all resources in a directory");
776775
RegisterCommand("refresh", CConsoleCommands::RefreshResources, false, "Refresh resource list to find new resources");
777776
RegisterCommand("refreshall", CConsoleCommands::RefreshAllResources, false, "Refresh resources and restart any changed resources");

0 commit comments

Comments
 (0)