2025-05-04 13:23:59 -04:00
|
|
|
#include <QHttpServer>
|
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QCoreApplication>
|
2025-05-04 16:38:49 -04:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonDocument>
|
2025-05-04 13:23:59 -04:00
|
|
|
#include <cstdlib>
|
2023-12-21 20:18:42 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <steam/steam_api.h>
|
2025-05-04 13:23:59 -04:00
|
|
|
#include <steam/steamclientpublic.h>
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 16:38:49 -04:00
|
|
|
static bool isInitialized = false;
|
|
|
|
|
2023-12-21 20:18:42 -05:00
|
|
|
int main(int argc, char *argv[]) {
|
2025-05-04 13:23:59 -04:00
|
|
|
QCoreApplication app(argc, argv);
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
QHttpServer server;
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
server.route("/init", QHttpServerRequest::Method::Post, [] (const QHttpServerRequest &request) {
|
2025-05-04 16:38:49 -04:00
|
|
|
if (isInitialized) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
const bool freeTrial = request.query().queryItemValue(QStringLiteral("ft")) == QStringLiteral("1");
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
if (freeTrial) {
|
|
|
|
putenv("SteamAppId=312060");
|
|
|
|
putenv("SteamGameId=312060");
|
|
|
|
} else {
|
|
|
|
putenv("SteamAppId=39210");
|
|
|
|
putenv("SteamGameId=39210");
|
|
|
|
}
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
if (!SteamAPI_Init()) {
|
|
|
|
qFatal() << "Failed to initialize Steam API!";
|
|
|
|
}
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
qInfo() << "Initialized Steam API...";
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 16:38:49 -04:00
|
|
|
isInitialized = true;
|
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
return "";
|
|
|
|
});
|
|
|
|
server.route("/shutdown", QHttpServerRequest::Method::Post, [] () {
|
2025-05-04 16:38:49 -04:00
|
|
|
if (!isInitialized) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
SteamAPI_Shutdown();
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
qInfo() << "Shutting down Steam API!";
|
|
|
|
|
|
|
|
return "";
|
|
|
|
});
|
|
|
|
server.route("/ticket", QHttpServerRequest::Method::Get, [] () {
|
2025-05-04 16:38:49 -04:00
|
|
|
auto user = SteamAPI_GetHSteamUser();
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 16:38:49 -04:00
|
|
|
const int bufsize = 1024;
|
|
|
|
char* buf = new char[bufsize];
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 16:38:49 -04:00
|
|
|
unsigned int length = 0;
|
|
|
|
HAuthTicket ret = SteamUser()->GetAuthSessionTicket(buf, bufsize, &length, nullptr);
|
2025-05-04 13:23:59 -04:00
|
|
|
|
2025-05-04 16:38:49 -04:00
|
|
|
QJsonObject response
|
|
|
|
{
|
|
|
|
{QStringLiteral("ticket"), QString::fromLatin1(QByteArray::fromRawData(buf, length).toHex())},
|
2025-05-04 16:42:09 -04:00
|
|
|
{QStringLiteral("time"), static_cast<qint64>(SteamUtils()->GetServerRealTime())}
|
2025-05-04 16:38:49 -04:00
|
|
|
};
|
2025-05-04 13:23:59 -04:00
|
|
|
|
2025-05-04 16:38:49 -04:00
|
|
|
return QJsonDocument(response).toJson(QJsonDocument::Compact);
|
2025-05-04 13:23:59 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
auto tcpserver = new QTcpServer();
|
|
|
|
if (!tcpserver->listen(QHostAddress::Any, 50481) || !server.bind(tcpserver)) {
|
|
|
|
delete tcpserver;
|
|
|
|
return -1;
|
|
|
|
}
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
qInfo() << "Listening on port" << tcpserver->serverPort();
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 13:23:59 -04:00
|
|
|
return QCoreApplication::exec();
|
2023-12-21 20:18:42 -05:00
|
|
|
}
|