forked from MrBesen/lolautoaccept
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include "clientapi.h"
|
|
|
|
#include <iomanip>
|
|
#include <QJsonObject>
|
|
|
|
#include <Log.h>
|
|
|
|
#include "json.h"
|
|
|
|
static const std::string SearchStateNames[] = {"Invalid", "Searching", "Found", "AbandonedLowPriorityQueue", "Canceled", "Error", "ServiceError", "ServiceShutdown"};
|
|
static const uint32_t SearchStateNamesCount = sizeof(SearchStateNames) / sizeof(SearchStateNames[0]);
|
|
|
|
template<typename T>
|
|
static T mapEnum(const std::string& input, const std::string* names, uint32_t count, T defaul) {
|
|
for(uint32_t i = 0; i < count; ++i) {
|
|
if(names[i] == input) {
|
|
return (T) i;
|
|
}
|
|
}
|
|
|
|
Log::warn << "no mapping of enum-string: " << std::quoted(input);
|
|
return defaul;
|
|
}
|
|
|
|
ClientAPI::ClientAPI(const ClientAccess& ca) : RestClient(ca.getURL()), access(ca) {
|
|
basicauth = ca.getBasicAuth();
|
|
disableCertCheck = true;
|
|
}
|
|
ClientAPI::~ClientAPI() {}
|
|
|
|
ClientAPI::SearchState ClientAPI::getSearchState() {
|
|
QJsonDocument doc = request("lol-lobby/v2/lobby/matchmaking/search-state");
|
|
|
|
if(doc.isObject()) {
|
|
QJsonObject obj = doc.object();
|
|
std::string searchState = getValue<std::string>(obj, "searchState", "Invalid");
|
|
|
|
return mapEnum(searchState, SearchStateNames, SearchStateNamesCount, ClientAPI::SearchState::INVALID);
|
|
}
|
|
|
|
return ClientAPI::SearchState::INVALID;
|
|
}
|
|
|
|
void ClientAPI::acceptMatch() {
|
|
|
|
}
|
|
|
|
void ClientAPI::declineMatch() {
|
|
|
|
}
|
|
|