finished
This commit is contained in:
@@ -1,32 +1,41 @@
|
||||
#include "player_manager.h"
|
||||
namespace ExtendPlayerManager {
|
||||
std::shared_mutex mutex_Table_PlayerSteamIdPlayerSlot;
|
||||
|
||||
std::unordered_map<uint64_t, uint64_t> Table_PlayerSteamIdPlayerSlot;
|
||||
|
||||
std::unordered_map<uint64_t, _ExtendPlayerSetting> Table_PlayerSteamIdPlayerSlot;
|
||||
//GPT error fixed;
|
||||
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;
|
||||
std::size_t pos = steamID.find_last_of(":");
|
||||
if (pos != std::string::npos) {
|
||||
uint64_t x = std::stoull(steamID.substr(pos + 1));
|
||||
return 76561197960265728 + x;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto AddSteamIdToPlayerSteamIdWithNameTable(uint64_t SteamId,
|
||||
uint64_t PlayerSlot) -> void {
|
||||
std::unique_lock<std::shared_mutex> lock(
|
||||
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, PlayerSlot));
|
||||
Table_PlayerSteamIdPlayerSlot.insert(std::make_pair(SteamId, _ExtendPlayerSetting{.playerSlot = PlayerSlot }));
|
||||
}
|
||||
auto UpdatePlayerSettingBySteamId(uint64_t SteamId, _ExtendPlayerSetting setting) -> void {
|
||||
std::shared_lock<std::shared_mutex> lock(
|
||||
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||
|
||||
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
|
||||
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
|
||||
it->second.bloodSetting = setting.bloodSetting;
|
||||
it->second.weaponSetting = setting.weaponSetting;
|
||||
}
|
||||
}
|
||||
auto GetPlayerSettingBySteamId(uint64_t SteamId) -> std::pair<bool, _ExtendPlayerSetting> {
|
||||
std::shared_lock<std::shared_mutex> lock(
|
||||
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||
|
||||
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
|
||||
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
|
||||
return { true, it->second };
|
||||
}
|
||||
return { false, {} };
|
||||
}
|
||||
auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
|
||||
std::shared_lock<std::shared_mutex> lock(
|
||||
@@ -34,15 +43,15 @@ auto GetPlayerSlotBySteamId(uint64_t SteamId) -> uint64_t {
|
||||
|
||||
auto it = Table_PlayerSteamIdPlayerSlot.find(SteamId);
|
||||
if (it != Table_PlayerSteamIdPlayerSlot.end()) {
|
||||
return it->second;
|
||||
return it->second.playerSlot;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
auto GetPlayerSteamIdByPlayerSlot(uint64_t playerSlot) -> uint64_t {
|
||||
std::shared_lock<std::shared_mutex> lock(
|
||||
mutex_Table_PlayerSteamIdPlayerSlot);
|
||||
for (auto& [SteamId, PlayerSlot] : Table_PlayerSteamIdPlayerSlot) {
|
||||
if (PlayerSlot == playerSlot) {
|
||||
for (auto& [SteamId, PlayerSetting] : Table_PlayerSteamIdPlayerSlot) {
|
||||
if (PlayerSetting.playerSlot == playerSlot) {
|
||||
return SteamId;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +74,7 @@ auto GetPlayerByPlayerSlot(uint64_t playerSlot) -> CCSPlayerController* {
|
||||
if (!pEntitySystem) {
|
||||
return nullptr;
|
||||
}
|
||||
for (int i = 1; i <= global::MaxPlayers; ++i) {
|
||||
for (int i = 0; i <= global::MaxPlayers; ++i) {
|
||||
CBaseEntity* pEntity = pEntitySystem->GetBaseEntity(i);
|
||||
if (!pEntity) continue;
|
||||
if (pEntity->IsBasePlayerController()) {
|
||||
|
||||
Reference in New Issue
Block a user