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