diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index d4845512..e6094454 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -8,11 +8,8 @@ namespace Components void Friends::UpdateUserInfo(SteamID user) { - if (!Steam::Proxy::SteamFriends) return; std::lock_guard _(Friends::Mutex); - Friends::Friend userInfo; - auto i = std::find_if(Friends::FriendsList.begin(), Friends::FriendsList.end(), [user] (Friends::Friend entry) { return (entry.userId.Bits == user.Bits); @@ -20,28 +17,30 @@ namespace Components if(i != Friends::FriendsList.end()) { - userInfo = *i; + Proto::IPC::Function function; + + function.set_name("getPresence"); + *function.add_params() = Utils::String::VA("%llx", user.Bits); + + std::string* key = function.add_params(); + + *key = "iw4x_status"; + IPCHandler::SendWorker("friends", function.SerializeAsString()); + + *key = "iw4x_rank"; + IPCHandler::SendWorker("friends", function.SerializeAsString()); + + *key = "iw4x_server"; + IPCHandler::SendWorker("friends", function.SerializeAsString()); } - userInfo.userId = user; - userInfo.online = Steam::Proxy::SteamFriends->GetFriendPersonaState(user) != 0; + /*userInfo.online = Steam::Proxy::SteamFriends->GetFriendPersonaState(user) != 0; userInfo.name = Steam::Proxy::SteamFriends->GetFriendPersonaName(user); userInfo.statusName = Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_status"); userInfo.prestige = Utils::Cryptography::Rand::GenerateInt() % (10 + 1); - userInfo.experience = Utils::Cryptography::Rand::GenerateInt() % (2516000 + 1); + userInfo.experience = Utils::Cryptography::Rand::GenerateInt() % (2516000 + 1);*/ - //if (!userInfo.online) return; - - if (i != Friends::FriendsList.end()) - { - *i = userInfo; - } - else - { - Friends::FriendsList.push_back(userInfo); - } - - qsort(Friends::FriendsList.data(), Friends::FriendsList.size(), sizeof(Friends::Friend), [](const void* first, const void* second) +/* qsort(Friends::FriendsList.data(), Friends::FriendsList.size(), sizeof(Friends::Friend), [](const void* first, const void* second) { const Friends::Friend* friend1 = static_cast(first); const Friends::Friend* friend2 = static_cast(second); @@ -50,7 +49,7 @@ namespace Components std::string name2 = Utils::String::ToLower(Colors::Strip(friend2->name)); return name1.compare(name2); - }); + });*/ } void Friends::UpdateFriends() @@ -142,6 +141,41 @@ namespace Components } } } + + void Friends::PresenceResponse(std::vector params) + { + if (params.size() >= 3) + { + std::lock_guard _(Friends::Mutex); + + SteamID id; + id.Bits = strtoull(params[0].data(), nullptr, 16); + std::string key = params[1]; + std::string value = params[2]; + + auto entry = std::find_if(Friends::FriendsList.begin(), Friends::FriendsList.end(), [id](Friends::Friend entry) + { + return (entry.userId.Bits == id.Bits); + }); + + if (entry == Friends::FriendsList.end()) return; + + if(key == "iw4x_status") + { + entry->statusName = value; + } + else if(key == "iw4x_rank") + { + if(value.size() == 4) + { + int data = *reinterpret_cast(const_cast(value.data())); + + entry->experience = data & 0xFFFFFF; + entry->prestige = (data >> 24) & 0xFF; + } + } + } + } void Friends::FriendsResponse(std::vector params) { @@ -195,7 +229,7 @@ namespace Components auto fInterface = IPCHandler::NewInterface("steamCallbacks"); // Callback to update user information - fInterface->map("304", [](std::vector params) + fInterface->map("336", [](std::vector params) { if (params.size() >= 1 && params[0].size() == sizeof(Friends::FriendRichPresenceUpdate)) { @@ -228,6 +262,7 @@ namespace Components fInterface = IPCHandler::NewInterface("friends"); fInterface->map("friendsResponse", Friends::FriendsResponse); fInterface->map("nameResponse", Friends::NameResponse); + fInterface->map("presenceResponse", Friends::PresenceResponse); } Friends::~Friends() diff --git a/src/Components/Modules/Friends.hpp b/src/Components/Modules/Friends.hpp index cd08cad6..3e122300 100644 --- a/src/Components/Modules/Friends.hpp +++ b/src/Components/Modules/Friends.hpp @@ -15,11 +15,13 @@ namespace Components static void UpdateFriends(); private: +#pragma pack(push, 4) struct FriendRichPresenceUpdate { SteamID m_steamIDFriend; // friend who's rich presence has changed int32_t m_nAppID; // the appID of the game (should always be the current game) }; +#pragma pack(pop) struct PersonaStateChange { @@ -51,5 +53,6 @@ namespace Components static void FriendsResponse(std::vector params); static void NameResponse(std::vector params); + static void PresenceResponse(std::vector params); }; } diff --git a/src/Worker/Handlers/Friends.cpp b/src/Worker/Handlers/Friends.cpp index fe7ef36e..f6020fdd 100644 --- a/src/Worker/Handlers/Friends.cpp +++ b/src/Worker/Handlers/Friends.cpp @@ -93,7 +93,18 @@ namespace Handlers response.set_name("presenceResponse"); *response.add_params() = Utils::String::VA("%llX", id.Bits); *response.add_params() = params[1].data(); - *response.add_params() = Steam::Proxy::SteamFriends->GetFriendRichPresence(id, params[1].data()); + + std::string* value = response.add_params(); + *value = Steam::Proxy::SteamFriends->GetFriendRichPresence(id, params[1].data()); + + if (params[1] == "iw4x_rank") + { + int experience = Utils::Cryptography::Rand::GenerateInt() % (2516000 + 1); + int prestige = Utils::Cryptography::Rand::GenerateInt() % (10 + 1); + + int data = (experience & 0xFFFFFF) | ((prestige << 24) & 0xFF); + *value = std::string(reinterpret_cast(&data), 4); + } endpoint.send(this->getCommand(), response.SerializeAsString()); } diff --git a/src/Worker/Worker.cpp b/src/Worker/Worker.cpp index fbf9792e..3d85042e 100644 --- a/src/Worker/Worker.cpp +++ b/src/Worker/Worker.cpp @@ -8,6 +8,7 @@ namespace Worker { Runner runner(Worker::ProcessId); runner.attachHandler(new Handlers::Friends()); + runner.attachHandler(new Handlers::SteamCallbacks()); runner.run(); return 0; }