forked from MrBesen/lolautoaccept
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
#include "clientaccess.h"
|
|
|
|
#include <fstream>
|
|
#include <iomanip>
|
|
|
|
#include <QDebug>
|
|
#include <QStringList>
|
|
|
|
ClientAccess::ClientAccess() {}
|
|
|
|
ClientAccess::ClientAccess(const QString& token, uint16_t port) : authcode(token), port(port) {}
|
|
|
|
std::shared_ptr<ClientAccess> createFromLockfile(std::istream& lockfile) {
|
|
|
|
std::string content;
|
|
std::getline(lockfile, content);
|
|
QStringList parts = QString::fromStdString(content).split(':');
|
|
|
|
if(parts.size() != 5) {
|
|
qCritical() << "lockfile contained " << parts.size() << " parts, expected 5";
|
|
return {};
|
|
}
|
|
|
|
const QString portstr = parts.at(2);
|
|
const QString token = parts.at(3);
|
|
|
|
// try to parse port
|
|
bool success = false;
|
|
uint16_t port = portstr.toUInt(&success);
|
|
if(!success) {
|
|
qCritical() << "could not parse port: " << portstr;
|
|
return nullptr;
|
|
}
|
|
return std::shared_ptr<ClientAccess>(new ClientAccess(token, port));
|
|
}
|
|
|
|
QString ClientAccess::getBasicAuth() const {
|
|
return "riot:" + authcode;
|
|
}
|
|
|
|
uint16_t ClientAccess::getPort() const {
|
|
return port;
|
|
}
|
|
|
|
QString ClientAccess::getURL() const {
|
|
return "https://127.0.0.1:" + QString::number(port) + "/";
|
|
}
|