From e5f6abcd8ea024e3c6e89e67f284698a25da54e7 Mon Sep 17 00:00:00 2001 From: Unnamed Date: Fri, 22 Feb 2019 17:33:30 +0000 Subject: [PATCH] playerlist.cpp: add player list cleanup command Removes useless entries from player list to save some RAM TO DO: Automatically cleanup list --- src/playerlist.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/playerlist.cpp b/src/playerlist.cpp index 3c6f4957..50c7f2b5 100644 --- a/src/playerlist.cpp +++ b/src/playerlist.cpp @@ -211,6 +211,25 @@ CatCommand pl_add_id("pl_add_id", "Sets state for steamid", [](const CCommand &a logging::Info("Unknown State"); }); +static void pl_cleanup() +{ + userdata empty{}; + size_t counter = 0; + for (auto it = data.begin(); it != data.end(); ++it) + { + if (std::memcmp(&it->second, &empty, sizeof(empty))) + continue; + + ++counter; + data.erase(it); + /* Start all over again. Iterator is invalidated once erased. */ + it = data.begin(); + } + logging::InfoConsole("%lu elements were removed", counter); +} + +CatCommand pl_clean("pl_clean", "Removes empty entries to reduce RAM usage", pl_cleanup); + CatCommand pl_set_state("pl_set_state", "cat_pl_set_state [playername] [state] (Tab to autocomplete)", [](const CCommand &args) { if (args.ArgC() != 3) {