[Friends] Query friends from the worker
This commit is contained in:
parent
46d3045d6f
commit
20139d4a52
@ -55,33 +55,11 @@ namespace Components
|
|||||||
|
|
||||||
void Friends::UpdateFriends()
|
void Friends::UpdateFriends()
|
||||||
{
|
{
|
||||||
if (!Steam::Proxy::SteamFriends) return;
|
Proto::IPC::Function function;
|
||||||
std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
|
function.set_name("getFriends");
|
||||||
|
*function.add_params() = Utils::String::VA("%d", 4);
|
||||||
|
|
||||||
auto listCopy = Friends::FriendsList;
|
IPCHandler::SendWorker("friends", function.SerializeAsString());
|
||||||
Friends::FriendsList.clear();
|
|
||||||
|
|
||||||
int count = Steam::Proxy::SteamFriends->GetFriendCount(4);
|
|
||||||
Friends::FriendsList.reserve(count);
|
|
||||||
|
|
||||||
for(int i = 0; i < count; ++i)
|
|
||||||
{
|
|
||||||
SteamID friendId = Steam::Proxy::SteamFriends->GetFriendByIndex(i, 4);
|
|
||||||
//if(!Steam::Proxy::SteamFriends->GetFriendPersonaState(friendId)) continue; // Offline
|
|
||||||
|
|
||||||
auto entry = std::find_if(listCopy.begin(), listCopy.end(), [friendId](Friends::Friend entry)
|
|
||||||
{
|
|
||||||
return (entry.userId.Bits == friendId.Bits);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (entry != listCopy.end())
|
|
||||||
{
|
|
||||||
Friends::FriendsList.push_back(*entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
Friends::UpdateUserInfo(friendId);
|
|
||||||
Steam::Proxy::SteamFriends->RequestFriendRichPresence(friendId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Friends::GetFriendCount()
|
unsigned int Friends::GetFriendCount()
|
||||||
@ -145,6 +123,71 @@ namespace Components
|
|||||||
Friends::CurrentFriend = index;
|
Friends::CurrentFriend = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Friends::NameResponse(std::vector<std::string> params)
|
||||||
|
{
|
||||||
|
if (params.size() >= 2)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
|
||||||
|
|
||||||
|
SteamID id;
|
||||||
|
id.Bits = strtoull(params[0].data(), nullptr, 16);
|
||||||
|
|
||||||
|
for(auto& entry : Friends::FriendsList)
|
||||||
|
{
|
||||||
|
if(entry.userId.Bits == id.Bits)
|
||||||
|
{
|
||||||
|
entry.name = params[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Friends::FriendsResponse(std::vector<std::string> params)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
|
||||||
|
|
||||||
|
auto oldFriends = Friends::FriendsList;
|
||||||
|
Friends::FriendsList.clear();
|
||||||
|
|
||||||
|
for (auto param : params)
|
||||||
|
{
|
||||||
|
SteamID id;
|
||||||
|
id.Bits = strtoull(param.data(), nullptr, 16);
|
||||||
|
|
||||||
|
Friends::Friend entry;
|
||||||
|
entry.userId = id;
|
||||||
|
entry.online = false;
|
||||||
|
entry.prestige = 0;
|
||||||
|
entry.experience = 0;
|
||||||
|
|
||||||
|
auto oldEntry = std::find_if(oldFriends.begin(), oldFriends.end(), [id](Friends::Friend entry)
|
||||||
|
{
|
||||||
|
return (entry.userId.Bits == id.Bits);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (oldEntry != oldFriends.end()) entry = *oldEntry;
|
||||||
|
|
||||||
|
Friends::FriendsList.push_back(entry);
|
||||||
|
|
||||||
|
Proto::IPC::Function function;
|
||||||
|
function.set_name("getName");
|
||||||
|
*function.add_params() = Utils::String::VA("%llx", id.Bits);
|
||||||
|
IPCHandler::SendWorker("friends", function.SerializeAsString());
|
||||||
|
|
||||||
|
function.Clear();
|
||||||
|
function.set_name("getPresence");
|
||||||
|
*function.add_params() = Utils::String::VA("%llx", id.Bits);
|
||||||
|
*function.add_params() = "iw4x_status";
|
||||||
|
IPCHandler::SendWorker("friends", function.SerializeAsString());
|
||||||
|
|
||||||
|
function.Clear();
|
||||||
|
function.set_name("requestPresence");
|
||||||
|
*function.add_params() = Utils::String::VA("%llx", id.Bits);
|
||||||
|
IPCHandler::SendWorker("friends", function.SerializeAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Friends::Friends()
|
Friends::Friends()
|
||||||
{
|
{
|
||||||
// Callback to update user information
|
// Callback to update user information
|
||||||
@ -168,33 +211,9 @@ namespace Components
|
|||||||
|
|
||||||
UIFeeder::Add(6.0f, Friends::GetFriendCount, Friends::GetFriendText, Friends::SelectFriend);
|
UIFeeder::Add(6.0f, Friends::GetFriendCount, Friends::GetFriendText, Friends::SelectFriend);
|
||||||
|
|
||||||
IPCHandler::OnWorker("friends", [](std::string data)
|
auto fInterface = IPCHandler::NewInterface("friends");
|
||||||
{
|
fInterface->map("friendsResponse", Friends::FriendsResponse);
|
||||||
Proto::IPC::Function function;
|
fInterface->map("nameResponse", Friends::NameResponse);
|
||||||
if(function.ParseFromString(data))
|
|
||||||
{
|
|
||||||
if(function.name() == "friendsResponse")
|
|
||||||
{
|
|
||||||
auto params = function.params();
|
|
||||||
|
|
||||||
Logger::Print("Received friendslist: %d\n", params.size());
|
|
||||||
|
|
||||||
for(auto param : params)
|
|
||||||
{
|
|
||||||
Logger::Print("%s\n", param.data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Command::Add("getFriends", [](Command::Params*)
|
|
||||||
{
|
|
||||||
Proto::IPC::Function function;
|
|
||||||
function.set_name("getFriends");
|
|
||||||
function.add_params()->append(Utils::String::VA("%d", 4));
|
|
||||||
|
|
||||||
IPCHandler::SendWorker("friends", function.SerializeAsString());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Friends::~Friends()
|
Friends::~Friends()
|
||||||
@ -202,11 +221,6 @@ namespace Components
|
|||||||
Steam::Proxy::UnregisterCallback(304);
|
Steam::Proxy::UnregisterCallback(304);
|
||||||
Steam::Proxy::UnregisterCallback(336);
|
Steam::Proxy::UnregisterCallback(336);
|
||||||
|
|
||||||
if (Steam::Proxy::SteamFriends)
|
|
||||||
{
|
|
||||||
Steam::Proxy::SteamFriends->SetRichPresence("iw4x_status", nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
|
std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
|
||||||
Friends::FriendsList.clear();
|
Friends::FriendsList.clear();
|
||||||
|
@ -48,5 +48,8 @@ namespace Components
|
|||||||
static unsigned int GetFriendCount();
|
static unsigned int GetFriendCount();
|
||||||
static const char* GetFriendText(unsigned int index, int column);
|
static const char* GetFriendText(unsigned int index, int column);
|
||||||
static void SelectFriend(unsigned int index);
|
static void SelectFriend(unsigned int index);
|
||||||
|
|
||||||
|
static void FriendsResponse(std::vector<std::string> params);
|
||||||
|
static void NameResponse(std::vector<std::string> params);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,15 @@ namespace Components
|
|||||||
std::unique_ptr<Utils::IPC::BidirectionalChannel> IPCHandler::WorkerChannel;
|
std::unique_ptr<Utils::IPC::BidirectionalChannel> IPCHandler::WorkerChannel;
|
||||||
std::unique_ptr<Utils::IPC::BidirectionalChannel> IPCHandler::ClientChannel;
|
std::unique_ptr<Utils::IPC::BidirectionalChannel> IPCHandler::ClientChannel;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<IPCHandler::FunctionInterface>> IPCHandler::FunctionInterfaces;
|
||||||
|
|
||||||
|
std::shared_ptr<IPCHandler::FunctionInterface> IPCHandler::NewInterface(std::string command)
|
||||||
|
{
|
||||||
|
std::shared_ptr<IPCHandler::FunctionInterface> fInterface(new IPCHandler::FunctionInterface());
|
||||||
|
IPCHandler::FunctionInterfaces[command] = fInterface;
|
||||||
|
return fInterface;
|
||||||
|
}
|
||||||
|
|
||||||
void IPCHandler::SendWorker(std::string message, std::string data)
|
void IPCHandler::SendWorker(std::string message, std::string data)
|
||||||
{
|
{
|
||||||
IPCHandler::InitChannels();
|
IPCHandler::InitChannels();
|
||||||
@ -98,10 +107,15 @@ namespace Components
|
|||||||
if (command.ParseFromString(packet))
|
if (command.ParseFromString(packet))
|
||||||
{
|
{
|
||||||
auto callback = IPCHandler::WorkerCallbacks.find(command.name());
|
auto callback = IPCHandler::WorkerCallbacks.find(command.name());
|
||||||
|
auto fInterface = IPCHandler::FunctionInterfaces.find(command.name());
|
||||||
if (callback != IPCHandler::WorkerCallbacks.end())
|
if (callback != IPCHandler::WorkerCallbacks.end())
|
||||||
{
|
{
|
||||||
callback->second(command.data());
|
callback->second(command.data());
|
||||||
}
|
}
|
||||||
|
else if(fInterface != IPCHandler::FunctionInterfaces.end())
|
||||||
|
{
|
||||||
|
fInterface->second->handle(command.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +136,12 @@ namespace Components
|
|||||||
|
|
||||||
IPCHandler::~IPCHandler()
|
IPCHandler::~IPCHandler()
|
||||||
{
|
{
|
||||||
|
IPCHandler::FunctionInterfaces.clear();
|
||||||
|
|
||||||
IPCHandler::WorkerCallbacks.clear();
|
IPCHandler::WorkerCallbacks.clear();
|
||||||
IPCHandler::ClientCallbacks.clear();
|
IPCHandler::ClientCallbacks.clear();
|
||||||
|
|
||||||
|
IPCHandler::WorkerChannel.release();
|
||||||
|
IPCHandler::ClientChannel.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,34 @@ namespace Components
|
|||||||
class IPCHandler : public Component
|
class IPCHandler : public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
class FunctionInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::function<void(std::vector<std::string>)> Callback;
|
||||||
|
|
||||||
|
void map(std::string name, Callback function)
|
||||||
|
{
|
||||||
|
this->functions[name] = function;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle(std::string data)
|
||||||
|
{
|
||||||
|
Proto::IPC::Function function;
|
||||||
|
if (function.ParseFromString(data))
|
||||||
|
{
|
||||||
|
auto handler = this->functions.find(function.name());
|
||||||
|
if (handler != this->functions.end())
|
||||||
|
{
|
||||||
|
auto params = function.params();
|
||||||
|
handler->second(std::vector<std::string>(params.begin(), params.end()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string, Callback> functions;
|
||||||
|
};
|
||||||
|
|
||||||
typedef Utils::Slot<void(std::string)> Callback;
|
typedef Utils::Slot<void(std::string)> Callback;
|
||||||
|
|
||||||
IPCHandler();
|
IPCHandler();
|
||||||
@ -20,6 +48,8 @@ namespace Components
|
|||||||
static void OnWorker(std::string message, Callback callback);
|
static void OnWorker(std::string message, Callback callback);
|
||||||
static void OnClient(std::string message, Callback callback);
|
static void OnClient(std::string message, Callback callback);
|
||||||
|
|
||||||
|
static std::shared_ptr<FunctionInterface> NewInterface(std::string command);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::unique_ptr<Utils::IPC::BidirectionalChannel> WorkerChannel;
|
static std::unique_ptr<Utils::IPC::BidirectionalChannel> WorkerChannel;
|
||||||
static std::unique_ptr<Utils::IPC::BidirectionalChannel> ClientChannel;
|
static std::unique_ptr<Utils::IPC::BidirectionalChannel> ClientChannel;
|
||||||
@ -27,6 +57,8 @@ namespace Components
|
|||||||
static std::unordered_map<std::string, Callback> WorkerCallbacks;
|
static std::unordered_map<std::string, Callback> WorkerCallbacks;
|
||||||
static std::unordered_map<std::string, Callback> ClientCallbacks;
|
static std::unordered_map<std::string, Callback> ClientCallbacks;
|
||||||
|
|
||||||
|
static std::unordered_map<std::string, std::shared_ptr<FunctionInterface>> FunctionInterfaces;
|
||||||
|
|
||||||
static void InitChannels();
|
static void InitChannels();
|
||||||
static void StartWorker();
|
static void StartWorker();
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <future>
|
#include <future>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
// Experimental C++17 features
|
// Experimental C++17 features
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -4,14 +4,24 @@ namespace Utils
|
|||||||
{
|
{
|
||||||
namespace IPC
|
namespace IPC
|
||||||
{
|
{
|
||||||
Channel::Channel(std::string _name, int _queueSize, int _bufferSize, bool _remove) : name(_name), remove(_remove)
|
Channel::Channel(std::string _name, int _queueSize, int _bufferSize, bool _remove) : terminateQueue(false), remove(_remove), name(_name)
|
||||||
{
|
{
|
||||||
if(this->remove) boost::interprocess::message_queue::remove(this->name.data());
|
if(this->remove) boost::interprocess::message_queue::remove(this->name.data());
|
||||||
queue.reset(new boost::interprocess::message_queue(boost::interprocess::open_or_create, this->name.data(), _queueSize, _bufferSize + sizeof(Channel::Header)));
|
queue.reset(new boost::interprocess::message_queue(boost::interprocess::open_or_create, this->name.data(), _queueSize, _bufferSize + sizeof(Channel::Header)));
|
||||||
|
|
||||||
|
this->queueThread = std::thread(&Channel::queueWorker, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel::~Channel()
|
Channel::~Channel()
|
||||||
{
|
{
|
||||||
|
this->terminateQueue = true;
|
||||||
|
this->queueEvent.notify_all();
|
||||||
|
|
||||||
|
if(this->queueThread.joinable())
|
||||||
|
{
|
||||||
|
this->queueThread.join();
|
||||||
|
}
|
||||||
|
|
||||||
if (this->remove) boost::interprocess::message_queue::remove(this->name.data());
|
if (this->remove) boost::interprocess::message_queue::remove(this->name.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,19 +94,47 @@ namespace Utils
|
|||||||
std::string buffer;
|
std::string buffer;
|
||||||
buffer.append(reinterpret_cast<char*>(&header), sizeof(Channel::Header));
|
buffer.append(reinterpret_cast<char*>(&header), sizeof(Channel::Header));
|
||||||
buffer.append(data.data() + sentSize, header.fragmentSize);
|
buffer.append(data.data() + sentSize, header.fragmentSize);
|
||||||
Channel::sendMessage(buffer);
|
Channel::enqueueMessage(buffer);
|
||||||
|
|
||||||
sentSize += header.fragmentSize;
|
sentSize += header.fragmentSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::sendMessage(std::string data)
|
void Channel::enqueueMessage(std::string data)
|
||||||
{
|
{
|
||||||
if (data.size() <= this->queue->get_max_msg_size())
|
if (data.size() <= this->queue->get_max_msg_size())
|
||||||
{
|
{
|
||||||
while (!this->queue->try_send(data.data(), data.size(), 0))
|
std::lock_guard<std::mutex> _(this->queueMutex);
|
||||||
|
this->internalQueue.push(data);
|
||||||
|
this->queueEvent.notify_all();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Channel::queueWorker()
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(100us);
|
while (!this->terminateQueue)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(this->queueMutex);
|
||||||
|
|
||||||
|
while(!this->terminateQueue && this->internalQueue.empty())
|
||||||
|
{
|
||||||
|
this->queueEvent.wait(lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!this->terminateQueue && !this->internalQueue.empty())
|
||||||
|
{
|
||||||
|
std::string data = this->internalQueue.front();
|
||||||
|
this->internalQueue.pop();
|
||||||
|
|
||||||
|
if (data.size() <= this->queue->get_max_msg_size())
|
||||||
|
{
|
||||||
|
while (!this->terminateQueue && !this->queue->try_send(data.data(), data.size(), 0))
|
||||||
|
{
|
||||||
|
lock.unlock();
|
||||||
|
std::this_thread::sleep_for(1000us);
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,14 @@ namespace Utils
|
|||||||
unsigned int fragmentPart;
|
unsigned int fragmentPart;
|
||||||
};
|
};
|
||||||
|
|
||||||
void sendMessage(std::string data);
|
void enqueueMessage(std::string data);
|
||||||
|
void queueWorker();
|
||||||
|
|
||||||
|
bool terminateQueue;
|
||||||
|
std::condition_variable queueEvent;
|
||||||
|
std::mutex queueMutex;
|
||||||
|
std::thread queueThread;
|
||||||
|
std::queue<std::string> internalQueue;
|
||||||
|
|
||||||
bool remove;
|
bool remove;
|
||||||
std::unique_ptr<boost::interprocess::message_queue> queue;
|
std::unique_ptr<boost::interprocess::message_queue> queue;
|
||||||
|
@ -27,9 +27,7 @@ namespace Handlers
|
|||||||
this->functions[function] = callback;
|
this->functions[function] = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
Friends::Friends()
|
void Friends::getFriends(Worker::Endpoint endpoint, std::vector<std::string> params)
|
||||||
{
|
|
||||||
this->addFunction("getFriends", [&](Worker::Endpoint endpoint, std::vector<std::string> params)
|
|
||||||
{
|
{
|
||||||
if (params.size() >= 1 && Steam::Proxy::SteamFriends)
|
if (params.size() >= 1 && Steam::Proxy::SteamFriends)
|
||||||
{
|
{
|
||||||
@ -41,15 +39,91 @@ namespace Handlers
|
|||||||
|
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
std::string* param = response.add_params();
|
|
||||||
SteamID id = Steam::Proxy::SteamFriends->GetFriendByIndex(i, flag);
|
SteamID id = Steam::Proxy::SteamFriends->GetFriendByIndex(i, flag);
|
||||||
|
*response.add_params() = Utils::String::VA("%llX", id.Bits);
|
||||||
param->clear();
|
|
||||||
param->append(Utils::String::VA("%llX", id.Bits));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint.send(this->getCommand(), response.SerializeAsString());
|
endpoint.send(this->getCommand(), response.SerializeAsString());
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
void Friends::getName(Worker::Endpoint endpoint, std::vector<std::string> params)
|
||||||
|
{
|
||||||
|
if(Steam::Proxy::SteamFriends)
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
SteamID id;
|
||||||
|
|
||||||
|
if(params.size() >= 1)
|
||||||
|
{
|
||||||
|
id.Bits = strtoull(params[0].data(), nullptr, 16);
|
||||||
|
name = Steam::Proxy::SteamFriends->GetFriendPersonaName(id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
id.Bits = 0;
|
||||||
|
name = Steam::Proxy::SteamFriends->GetPersonaName();
|
||||||
|
}
|
||||||
|
|
||||||
|
Proto::IPC::Function response;
|
||||||
|
response.set_name("nameResponse");
|
||||||
|
*response.add_params() = Utils::String::VA("%llX", id.Bits);
|
||||||
|
*response.add_params() = name;
|
||||||
|
|
||||||
|
endpoint.send(this->getCommand(), response.SerializeAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Friends::setPresence(Worker::Endpoint /*endpoint*/, std::vector<std::string> params)
|
||||||
|
{
|
||||||
|
if (params.size() >= 2 && Steam::Proxy::SteamFriends)
|
||||||
|
{
|
||||||
|
Steam::Proxy::SteamFriends->SetRichPresence(params[0].data(), params[1].data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Friends::getPresence(Worker::Endpoint endpoint, std::vector<std::string> params)
|
||||||
|
{
|
||||||
|
if (params.size() >= 2 && Steam::Proxy::SteamFriends)
|
||||||
|
{
|
||||||
|
SteamID id;
|
||||||
|
id.Bits = strtoull(params[0].data(), nullptr, 16);
|
||||||
|
|
||||||
|
Proto::IPC::Function response;
|
||||||
|
response.set_name("presenceResponse");
|
||||||
|
*response.add_params() = Utils::String::VA("%llX", id.Bits);
|
||||||
|
*response.add_params() = Steam::Proxy::SteamFriends->GetFriendRichPresence(id, params[1].data());
|
||||||
|
|
||||||
|
endpoint.send(this->getCommand(), response.SerializeAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Friends::requestPresence(Worker::Endpoint /*endpoint*/, std::vector<std::string> params)
|
||||||
|
{
|
||||||
|
if (params.size() >= 1 && Steam::Proxy::SteamFriends)
|
||||||
|
{
|
||||||
|
SteamID id;
|
||||||
|
id.Bits = strtoull(params[0].data(), nullptr, 16);
|
||||||
|
|
||||||
|
Steam::Proxy::SteamFriends->RequestFriendRichPresence(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Friends::Friends()
|
||||||
|
{
|
||||||
|
using namespace std::placeholders;
|
||||||
|
this->addFunction("getFriends", std::bind(&Friends::getFriends, this, _1, _2));
|
||||||
|
this->addFunction("getName", std::bind(&Friends::getName, this, _1, _2));
|
||||||
|
this->addFunction("setPresence", std::bind(&Friends::setPresence, this, _1, _2));
|
||||||
|
this->addFunction("getPresence", std::bind(&Friends::getPresence, this, _1, _2));
|
||||||
|
this->addFunction("requestPresence", std::bind(&Friends::requestPresence, this, _1, _2));
|
||||||
|
}
|
||||||
|
|
||||||
|
Friends::~Friends()
|
||||||
|
{
|
||||||
|
if(Steam::Proxy::SteamFriends)
|
||||||
|
{
|
||||||
|
Steam::Proxy::SteamFriends->ClearRichPresence();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,19 @@ namespace Handlers
|
|||||||
typedef std::function<void(Worker::Endpoint, std::vector<std::string>)> Callback;
|
typedef std::function<void(Worker::Endpoint, std::vector<std::string>)> Callback;
|
||||||
|
|
||||||
Friends();
|
Friends();
|
||||||
|
~Friends();
|
||||||
|
|
||||||
std::string getCommand() override { return "friends"; };
|
std::string getCommand() override { return "friends"; };
|
||||||
void handle(Worker::Endpoint endpoint, std::string data) override;
|
void handle(Worker::Endpoint endpoint, std::string data) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addFunction(std::string function, Callback callback);
|
|
||||||
std::unordered_map<std::string, Callback> functions;
|
std::unordered_map<std::string, Callback> functions;
|
||||||
|
void addFunction(std::string function, Callback callback);
|
||||||
|
|
||||||
|
void getFriends(Worker::Endpoint endpoint, std::vector<std::string> params);
|
||||||
|
void getName(Worker::Endpoint endpoint, std::vector<std::string> params);
|
||||||
|
void setPresence(Worker::Endpoint endpoint, std::vector<std::string> params);
|
||||||
|
void getPresence(Worker::Endpoint endpoint, std::vector<std::string> params);
|
||||||
|
void requestPresence(Worker::Endpoint endpoint, std::vector<std::string> params);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ namespace Worker
|
|||||||
auto handler = this->handlers.find(command.name());
|
auto handler = this->handlers.find(command.name());
|
||||||
if (handler != this->handlers.end())
|
if (handler != this->handlers.end())
|
||||||
{
|
{
|
||||||
printf("Dispathcing command %s to handler\n", command.name().data());
|
printf("Dispatching command %s to handler\n", command.name().data());
|
||||||
handler->second->handle(&channel, command.data());
|
handler->second->handle(&channel, command.data());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user