1#include <CS2Kit/Utils/SteamId.hpp>
8std::string SteamId::ToSteamId3(int64_t steamId64)
10 uint32_t accountId = GetAccountId(steamId64);
11 return std::format(
"[U:1:{}]", accountId);
14std::string SteamId::ToSteamId(int64_t steamId64)
16 uint32_t accountId = GetAccountId(steamId64);
17 uint32_t authServer = accountId % 2;
18 uint32_t accountNum = accountId / 2;
19 return std::format(
"STEAM_0:{}:{}", authServer, accountNum);
22std::optional<int64_t> SteamId::FromSteamId3(
const std::string& steamId3)
24 std::regex pattern(R
"(\[U:1:(\d+)\])");
26 if (std::regex_match(steamId3, matches, pattern))
30 uint32_t accountId = std::stoul(matches[1].str());
31 return SteamId64Base + accountId;
41std::optional<int64_t> SteamId::FromSteamId(
const std::string& steamId)
43 std::regex pattern(R
"(STEAM_[0-5]:([01]):(\d+))");
45 if (std::regex_match(steamId, matches, pattern))
49 uint32_t authServer = std::stoul(matches[1].str());
50 uint32_t accountNum = std::stoul(matches[2].str());
51 uint32_t accountId = accountNum * 2 + authServer;
52 return SteamId64Base + accountId;
62bool SteamId::IsValid(int64_t steamId64)
64 return steamId64 >= SteamId64Base && steamId64 < (SteamId64Base + 0x100000000LL);
67uint32_t SteamId::GetAccountId(int64_t steamId64)
69 return static_cast<uint32_t
>(steamId64 - SteamId64Base);