This commit is contained in:
mrbesen 2022-07-01 00:13:38 +02:00
parent 500b12f756
commit 69cc172f12
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
4 changed files with 88 additions and 13 deletions

View File

@ -30,16 +30,43 @@ public:
TERMINATEDINERROR,
};
enum class ChampSelectPhase : uint32_t {
INVALID = 0,
PLANNING,
BAN_PICK,
FINALIZATION
};
enum class Position : uint32_t {
INVALID = 0,
TOP,
MIDDLE,
BOTTOM,
JUNGLE,
UTILITY
};
struct TimerInfo {
int64_t adjustedTimeLeftInPhase;
int64_t internalNowInEpochMs;
bool isefinite;
std::string phase;
ChampSelectPhase phase;
int64_t totalTimeInPhase;
bool valid = false;
};
struct PlayerInfo {
int64_t summonerid = 0; // to test validity -> test if this is not null
std::string gameName;
std::string name;
std::string statusMessage;
// lol specific
std::string puuid;
uint32_t level = 0;
};
ClientAPI(const ClientAccess& access);
~ClientAPI();
@ -47,6 +74,8 @@ public:
GameflowPhase getGameflowPhase();
void acceptMatch();
void declineMatch();
void getChampSelectSession();
PlayerInfo getSelf();
std::vector<int32_t> getBannableChampIDs();
std::vector<int32_t> getPickableChampIDs();
@ -63,3 +92,5 @@ private:
std::ostream& operator<<(std::ostream&, const ClientAPI::ReadyCheckState&);
std::ostream& operator<<(std::ostream&, const ClientAPI::GameflowPhase&);
std::ostream& operator<<(std::ostream&, const ClientAPI::ChampSelectPhase&);
std::ostream& operator<<(std::ostream&, const ClientAPI::Position&);

View File

@ -23,6 +23,8 @@ protected:
std::shared_ptr<ClientAPI> clientapi;
int64_t summonerid = -1;
public:
enum class State {
LOBBY = 0,

View File

@ -1,5 +1,6 @@
#include "clientapi.h"
#include <cassert>
#include <iomanip>
#include <QJsonArray>
#include <QJsonObject>
@ -10,12 +11,13 @@
// calculate the size of a constant sized array
#define ARRSIZE(ARRNAME) (sizeof(ARRNAME) / sizeof(ARRNAME[0]))
#define ARR(NAME, ...) static const std::string NAME ## Names[] = {__VA_ARGS__}; \
static const uint32_t NAME ## NamesCount = ARRSIZE(NAME ## Names);
static const std::string ReadyCheckStateNames[] = { "Invalid", "None", "InProgress", "Accepted", "Declined" };
static const uint32_t ReadyCheckStateNamesCount = ARRSIZE(ReadyCheckStateNames);
static const std::string GameflowPhaseNames[] = {"None", "Lobby", "Matchmaking", "CheckedIntoTournament", "ReadyCheck", "ChampSelect", "GameStart", "FailedToLaunch", "InProgress", "Reconnect", "WaitingForStats", "PreEndOfGame", "EndOfGame", "TerminatedInError"};
static const uint32_t GameflowPhaseNamesCount = ARRSIZE(GameflowPhaseNames);
ARR(ReadyCheckState, "Invalid", "None", "InProgress", "Accepted", "Declined");
ARR(GameflowPhase, "None", "Lobby", "Matchmaking", "CheckedIntoTournament", "ReadyCheck", "ChampSelect", "GameStart", "FailedToLaunch", "InProgress", "Reconnect", "WaitingForStats", "PreEndOfGame", "EndOfGame", "TerminatedInError");
ARR(ChampSelectPhase, "Invalid", "PLANNING", "BAN_PICK", "FINALIZATION");
ARR(Position, "Invalid", "TOP", "MIDDLE", "BOTTOM", "JUNGLE", "UTILITY");
template<typename T>
static T mapEnum(const std::string& input, const std::string* names, uint32_t count, T defaul) {
@ -29,6 +31,9 @@ static T mapEnum(const std::string& input, const std::string* names, uint32_t co
return defaul;
}
#define MAPENUM(VAR, ENUM, DEFAULT) \
mapEnum(VAR, ENUM ## Names, ENUM ## NamesCount, ClientAPI:: ENUM :: DEFAULT)
ClientAPI::ClientAPI(const ClientAccess& ca) : RestClient(ca.getURL()), access(ca) {
basicauth = ca.getBasicAuth();
disableCertCheck = true;
@ -45,10 +50,10 @@ ClientAPI::ReadyCheckState ClientAPI::getReadyCheckState() {
std::string searchState = getValue<std::string>(obj, "state", "Invalid");
std::string playerresponse = getValue<std::string>(obj, "playerResponse", "None");
ClientAPI::ReadyCheckState response = mapEnum(playerresponse, ReadyCheckStateNames, ReadyCheckStateNamesCount, ClientAPI::ReadyCheckState::NONE);
ClientAPI::ReadyCheckState response = MAPENUM(playerresponse, ReadyCheckState, NONE);
if(response == ClientAPI::ReadyCheckState::NONE) {
auto sstate = mapEnum(searchState, ReadyCheckStateNames, ReadyCheckStateNamesCount, ClientAPI::ReadyCheckState::INVALID);
auto sstate = MAPENUM(searchState, ReadyCheckState, INVALID);
if(sstate == ClientAPI::ReadyCheckState::INPROGRESS) {
return sstate;
}
@ -68,7 +73,7 @@ ClientAPI::GameflowPhase ClientAPI::getGameflowPhase() {
if (data.size() > 2) {
datastr = datastr.substr(1, datastr.size() -2);
return mapEnum(datastr, GameflowPhaseNames, GameflowPhaseNamesCount, ClientAPI::GameflowPhase::NONE);
return MAPENUM(datastr, GameflowPhase, NONE);
}
return ClientAPI::GameflowPhase::NONE;
@ -82,6 +87,35 @@ void ClientAPI::declineMatch() {
request("lol-matchmaking/v1/ready-check/decline", Method::POST);
}
void ClientAPI::getChampSelectSession() {
QJsonDocument doc = request("lol-champ-select/v1/session");
Log::info << "lol-champ-select session: " << doc.toJson().toStdString();
}
ClientAPI::PlayerInfo ClientAPI::getSelf() {
QJsonDocument doc = request("lol-chat/v1/me");
if(doc.isObject()) {
QJsonObject obj = doc.object();
PlayerInfo info;
info.gameName = getValue<std::string>(obj, "gameName");
info.name = getValue<std::string>(obj, "name");
info.statusMessage = getValue<std::string>(obj, "statusMessage", "");
auto lolref = obj["lol"];
if(lolref.isObject()) {
QJsonObject lol = lolref.toObject();
info.puuid = getValue<std::string>(lol, "puuid");
info.level = getValue<int32_t>(lol, "level");
}
return info;
}
return {};
}
static std::vector<int32_t> fromArrayToVector(const QJsonArray& arr) {
std::vector<int32_t> out;
out.reserve(arr.size());
@ -123,7 +157,9 @@ ClientAPI::TimerInfo ClientAPI::getTimerInfo() {
ti.adjustedTimeLeftInPhase = getValue<int64_t>(obj, "adjustedTimeLeftInPhase", 0);
ti.internalNowInEpochMs = getValue<int64_t>(obj, "internalNowInEpochMs", 0);
ti.isefinite = getValue<bool>(obj, "isefinite", 0);
ti.phase = getValue<std::string>(obj, "phase", "");
ti.phase = MAPENUM(getValue<std::string>(obj, "phase", "Invalid"), ChampSelectPhase, INVALID);
ti.totalTimeInPhase = getValue<int64_t>(obj, "totalTimeInPhase", 0);
return ti;
@ -131,9 +167,12 @@ ClientAPI::TimerInfo ClientAPI::getTimerInfo() {
#define PRINTENUM(ENUMNAME) \
std::ostream& operator<<(std::ostream& str, const ClientAPI:: ENUMNAME & state) { \
assert(((int) state) < ENUMNAME ## NamesCount); \
return str << ENUMNAME ## Names[(int) state] << " (" << (int) state << ')'; \
}
PRINTENUM(ReadyCheckState)
PRINTENUM(GameflowPhase)
PRINTENUM(ChampSelectPhase)
PRINTENUM(Position)

View File

@ -49,6 +49,9 @@ bool LolAutoAccept::init() {
auto ca = ClientAccess::find();
if(ca) {
clientapi = std::make_shared<ClientAPI>(*ca.get());
auto selfinfo = clientapi->getSelf();
summonerid = selfinfo.summonerid;
Log::info << "selfinfo: gameName: " << selfinfo.gameName << " name: " << selfinfo.name << " summonerid: " << selfinfo.summonerid << " statusMessage: " << selfinfo.statusMessage << " puuid: " << selfinfo.puuid << " level: " << selfinfo.level;
}
return (bool) clientapi;
@ -84,7 +87,7 @@ void LolAutoAccept::innerRun() {
auto phase = clientapi->getGameflowPhase();
Log::debug << "current Gameflowphase: " << phase;
// TODO: do processing
// do processing
if(phase == ClientAPI::GameflowPhase::READYCHECK) {
if(stages.at(0)->enabled) { // auto accept enabled
auto state = clientapi->getReadyCheckState();
@ -94,9 +97,9 @@ void LolAutoAccept::innerRun() {
Log::info << "auto accepting";
clientapi->acceptMatch();
}
} else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) {
}
} else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) {
clientapi->getChampSelectSession();
}
auto end = std::chrono::high_resolution_clock::now();