1
Fork 0
steamwrap/main.cpp
Joshua Goins 9e33b2275e Refactor project, use HTTP for IPC
Now Astra can actually fetch Steam tickets from the Steamworks API!
2025-05-04 13:23:59 -04:00

64 lines
1.7 KiB
C++

#include <QHttpServer>
#include <QTcpServer>
#include <QCoreApplication>
#include <cstdlib>
#include <iostream>
#include <steam/steam_api.h>
#include <steam/steamclientpublic.h>
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
QHttpServer server;
server.route("/init", QHttpServerRequest::Method::Post, [] (const QHttpServerRequest &request) {
const bool freeTrial = request.query().queryItemValue(QStringLiteral("ft")) == QStringLiteral("1");
if (freeTrial) {
putenv("SteamAppId=312060");
putenv("SteamGameId=312060");
} else {
putenv("SteamAppId=39210");
putenv("SteamGameId=39210");
}
if (!SteamAPI_Init()) {
qFatal() << "Failed to initialize Steam API!";
}
qInfo() << "Initialized Steam API...";
return "";
});
server.route("/shutdown", QHttpServerRequest::Method::Post, [] () {
SteamAPI_Shutdown();
qInfo() << "Shutting down Steam API!";
return "";
});
server.route("/ticket", QHttpServerRequest::Method::Get, [] () {
auto user = SteamAPI_GetHSteamUser();
const int bufsize = 1024;
char* buf = new char[bufsize];
SteamNetworkingIdentity snid;
snid.SetSteamID(SteamUser()->GetSteamID());
unsigned int length = 0;
HAuthTicket ret = SteamUser()->GetAuthSessionTicket(buf, bufsize, &length, &snid);
return QString::fromUtf8(buf, length);
});
auto tcpserver = new QTcpServer();
if (!tcpserver->listen(QHostAddress::Any, 50481) || !server.bind(tcpserver)) {
delete tcpserver;
return -1;
}
qInfo() << "Listening on port" << tcpserver->serverPort();
return QCoreApplication::exec();
}