Update playerlist.cpp
This commit is contained in:
parent
9bffc05cd3
commit
d505af9213
@ -1,35 +1,35 @@
|
||||
/*
|
||||
/*
|
||||
* playerlist.cpp
|
||||
*
|
||||
* Created on: Apr 11, 2017
|
||||
* Author: nullifiedcat
|
||||
*/
|
||||
|
||||
#include "playerlist.hpp"
|
||||
#include "common.hpp"
|
||||
#include "playerlist.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace playerlist
|
||||
{
|
||||
namespace playerlist
|
||||
{
|
||||
|
||||
std::unordered_map<unsigned, userdata> data{};
|
||||
std::unordered_map<unsigned, userdata> data{};
|
||||
|
||||
const userdata null_data{};
|
||||
const userdata null_data{};
|
||||
|
||||
rgba_t k_Colors[] = { colors::empty, colors::FromRGBA8(99, 226, 161, 255),
|
||||
rgba_t k_Colors[] = { colors::empty, colors::FromRGBA8(99, 226, 161, 255),
|
||||
colors::FromRGBA8(226, 204, 99, 255),
|
||||
colors::FromRGBA8(232, 134, 6, 255), colors::empty };
|
||||
|
||||
bool ShouldSave(const userdata &data)
|
||||
{
|
||||
bool ShouldSave(const userdata &data)
|
||||
{
|
||||
return data.color || (data.state != k_EState::DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
void Save()
|
||||
{
|
||||
void Save()
|
||||
{
|
||||
DIR *cathook_directory = opendir(DATA_PATH);
|
||||
if (!cathook_directory)
|
||||
{
|
||||
@ -68,10 +68,10 @@ void Save()
|
||||
{
|
||||
logging::Info("Writing unsuccessful: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Load()
|
||||
{
|
||||
void Load()
|
||||
{
|
||||
data.clear();
|
||||
DIR *cathook_directory = opendir(DATA_PATH);
|
||||
if (!cathook_directory)
|
||||
@ -113,12 +113,14 @@ void Load()
|
||||
{
|
||||
logging::Info("Reading unsuccessful: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rgba_t Color(unsigned steamid)
|
||||
{
|
||||
rgba_t Color(unsigned steamid)
|
||||
{
|
||||
if (AccessData(steamid).state == k_EState::DEVELOPER)
|
||||
return colors::RainbowCurrent();
|
||||
if (AccessData(steamid).state == k_EState::CAT)
|
||||
return colors::RainbowCurrent();
|
||||
if (AccessData(steamid).color.a)
|
||||
{
|
||||
return AccessData(steamid).color;
|
||||
@ -127,17 +129,17 @@ rgba_t Color(unsigned steamid)
|
||||
{
|
||||
return k_Colors[static_cast<int>(AccessData(steamid).state)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rgba_t Color(CachedEntity *player)
|
||||
{
|
||||
rgba_t Color(CachedEntity *player)
|
||||
{
|
||||
if (CE_GOOD(player))
|
||||
return Color(player->player_info.friendsID);
|
||||
return colors::empty;
|
||||
}
|
||||
}
|
||||
|
||||
userdata &AccessData(unsigned steamid)
|
||||
{
|
||||
userdata &AccessData(unsigned steamid)
|
||||
{
|
||||
try
|
||||
{
|
||||
return data.at(steamid);
|
||||
@ -147,33 +149,33 @@ userdata &AccessData(unsigned steamid)
|
||||
data.emplace(steamid, userdata{});
|
||||
return data.at(steamid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assume player is non-null
|
||||
userdata &AccessData(CachedEntity *player)
|
||||
{
|
||||
// Assume player is non-null
|
||||
userdata &AccessData(CachedEntity *player)
|
||||
{
|
||||
if (CE_GOOD(player))
|
||||
return AccessData(player->player_info.friendsID);
|
||||
return AccessData(0U);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsDefault(unsigned steamid)
|
||||
{
|
||||
bool IsDefault(unsigned steamid)
|
||||
{
|
||||
const userdata &data = AccessData(steamid);
|
||||
return data.state == k_EState::DEFAULT && !data.color.a;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsDefault(CachedEntity *entity)
|
||||
{
|
||||
bool IsDefault(CachedEntity *entity)
|
||||
{
|
||||
if (CE_GOOD(entity))
|
||||
return IsDefault(entity->player_info.friendsID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
CatCommand pl_save("pl_save", "Save playerlist", Save);
|
||||
CatCommand pl_load("pl_load", "Load playerlist", Load);
|
||||
CatCommand pl_save("pl_save", "Save playerlist", Save);
|
||||
CatCommand pl_load("pl_load", "Load playerlist", Load);
|
||||
|
||||
CatCommand pl_set_state(
|
||||
CatCommand pl_set_state(
|
||||
"pl_set_state",
|
||||
"pl_set_state uniqueid state\nfor example pl_set_state 306902159 0",
|
||||
[](const CCommand &args) {
|
||||
@ -191,7 +193,7 @@ CatCommand pl_set_state(
|
||||
logging::Info("Set %d to %d", steamid, state);
|
||||
});
|
||||
|
||||
CatCommand pl_set_color("pl_set_color", "pl_set_color uniqueid r g b",
|
||||
CatCommand pl_set_color("pl_set_color", "pl_set_color uniqueid r g b",
|
||||
[](const CCommand &args) {
|
||||
if (args.ArgC() < 5)
|
||||
{
|
||||
@ -208,7 +210,7 @@ CatCommand pl_set_color("pl_set_color", "pl_set_color uniqueid r g b",
|
||||
logging::Info("Changed %d's color", steamid);
|
||||
});
|
||||
|
||||
CatCommand pl_info("pl_info", "pl_info uniqueid", [](const CCommand &args) {
|
||||
CatCommand pl_info("pl_info", "pl_info uniqueid", [](const CCommand &args) {
|
||||
if (args.ArgC() < 2)
|
||||
{
|
||||
logging::Info("Invalid call");
|
||||
@ -221,5 +223,5 @@ CatCommand pl_info("pl_info", "pl_info uniqueid", [](const CCommand &args) {
|
||||
if (clr) {
|
||||
ConColorMsg(*reinterpret_cast<::Color*>(&clr), "[CUSTOM COLOR]\n");
|
||||
}*/
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user