增加pawn名字

This commit is contained in:
Huoji's
2023-10-02 05:03:37 +08:00
parent 1bae80e38d
commit 7d24c5a405
16 changed files with 167 additions and 127 deletions

View File

@@ -1,26 +1,50 @@
#include "player_manager.h"
namespace PlayerManager {
std::shared_mutex mutex_PlayerNameList;
std::unordered_map<uint32_t, std::string> PlayerNameList;
auto AddPlayerNameToPlayerNameList(const CPlayerSlot PlayerSlot,
const char* PlayerName) -> void {
std::unique_lock lock(mutex_PlayerNameList);
PlayerNameList[PlayerSlot.Get()] = PlayerName;
LOG("%s PlayerNameList[%d] = %s \n", __FUNCTION__, PlayerSlot.Get(),
PlayerName);
#include "native_sdk/cgameentitysystem.h"
namespace ExtendPlayerManager {
std::shared_mutex mutex_Table_PlayerSteamIdPlayerSlot;
std::unordered_map<uint64_t, uint64_t> Table_PlayerSteamIdPlayerSlot;
auto SteamIDStringToUInt64(const std::string& steamID) -> uint64_t {
std::istringstream iss(
steamID.substr(3, steamID.size() - 4)); // 去掉"[U:"和"]"
std::string tmp;
uint32_t instance, account_id;
// 读取 Account Instance
std::getline(iss, tmp, ':');
instance = std::stoi(tmp);
// 读取 Account ID
std::getline(iss, tmp);
account_id = std::stoi(tmp);
// 计算并返回结果
return (uint64_t(account_id) << 1 | instance) + 76561197960265728ULL;
}
auto RemovePlayerNameFromPlayerNameList(const CPlayerSlot PlayerSlot,
const char* PlayerName) -> void {
std::unique_lock lock(mutex_PlayerNameList);
PlayerNameList.erase(PlayerSlot.Get());
LOG("%s PlayerNameList[%d] = %s \n", __FUNCTION__, PlayerSlot.Get(),
PlayerName);
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
uint64_t PlayerSlot) -> void {
std::unique_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
LOG("steamid: %llu playername: %ld \n", SteamId, PlayerSlot);
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, PlayerSlot));
}
auto GetPlayerNameByPlayerSlot(const CPlayerSlot PlayerSlot) -> std::string {
std::shared_lock lock(mutex_PlayerNameList);
auto index = PlayerSlot.Get();
auto name = PlayerNameList[index];
LOG("get player name: %d %s \n", index, name.c_str());
return name;
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
std::shared_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
LOG("steamid: %llu \n", SteamId);
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
return it->second;
}
return -1;
}
}; // namespace PlayerManager
auto RemovePlayerSlotBySteamId(uint64_t SteamId) -> void {
std::unique_lock<std::shared_mutex> lock(mutex_Table_PlayerSteamIdPlayerSlot);
LOG("steamid: %llu \n", SteamId);
if (Table_PlayerSteamIdPlayerSlot.find(SteamId) !=
Table_PlayerSteamIdPlayerSlot.end()) {
Table_PlayerSteamIdPlayerSlot.erase(SteamId);
}
}
}; // namespace ExtendPlayerManager