1
Fork 0

Port to httplib, update build instructions

This commit is contained in:
Joshua Goins 2025-05-04 17:40:04 -04:00
parent d0242bd943
commit 619e64159c
4 changed files with 10582 additions and 78 deletions

View file

@ -3,15 +3,13 @@ project(steamwrap)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
find_package(Qt6 REQUIRED HttpServer Network Core)
add_library(Steamworks IMPORTED SHARED) add_library(Steamworks IMPORTED SHARED)
set_target_properties(Steamworks PROPERTIES set_target_properties(Steamworks PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${STEAMWORKS_INCLUDE_DIR} INTERFACE_INCLUDE_DIRECTORIES ${STEAMWORKS_INCLUDE_DIR}
IMPORTED_LOCATION ${STEAMWORKS_LIBRARIES}) IMPORTED_LOCATION ${STEAMWORKS_LIBRARIES})
add_executable(steamwrap main.cpp) add_executable(steamwrap main.cpp)
target_link_libraries(steamwrap PRIVATE Steamworks Qt6::HttpServer Qt6::Network Qt6::Core) target_link_libraries(steamwrap PRIVATE Steamworks pthread)
set_target_properties(steamwrap set_target_properties(steamwrap
PROPERTIES PROPERTIES
BUILD_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN"

View file

@ -9,8 +9,8 @@ Due to restrictions on how the Steamworks SDK is distributed, I have to build it
Remember that newer glibc/++ won't work when it's inside the Steam Linux Runtime, so I recommend using distrobox to build steamwrap: Remember that newer glibc/++ won't work when it's inside the Steam Linux Runtime, so I recommend using distrobox to build steamwrap:
```shell ```shell
$ distrobox create --name test --init --image debian:10 --additional-packages "systemd libpam-systemd" # Debian 10 is the base of Steam Linux Runtime 2.0 $ distrobox create --name steamwrap --init --image debian:10 --additional-packages "systemd libpam-systemd cmake build-essential" # Debian 10 is the base of Steam Linux Runtime 2.0
$ distrobox enter test $ distrobox enter steamwrap
$ mkdir build $ mkdir build
$ cd build $ cd build
$ cmake -DSTEAMWORKS_LIBRARIES=<location of steam sdk>/redistributable_bin/linux64/libsteam_api.so -DSTEAMWORKS_INCLUDE_DIR=<location of steam sdk>/public/ .. $ cmake -DSTEAMWORKS_LIBRARIES=<location of steam sdk>/redistributable_bin/linux64/libsteam_api.so -DSTEAMWORKS_INCLUDE_DIR=<location of steam sdk>/public/ ..

10518
httplib.h Normal file

File diff suppressed because it is too large Load diff

134
main.cpp
View file

@ -1,81 +1,69 @@
#include <QHttpServer>
#include <QTcpServer>
#include <QCoreApplication>
#include <QJsonObject>
#include <QJsonDocument>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <steam/steam_api.h> #include <steam/steam_api.h>
#include <steam/steamclientpublic.h> #include <steam/steamclientpublic.h>
#include "httplib.h"
static bool isInitialized = false; static bool isInitialized = false;
int main(int argc, char *argv[]) { // from https://stackoverflow.com/a/53966346
QCoreApplication app(argc, argv); void btox(char *xp, const char *bb, int n)
{
QHttpServer server; const char xx[]= "0123456789ABCDEF";
while (--n >= 0) xp[n] = xx[(bb[n>>1] >> ((1 - (n&1)) << 2)) & 0xF];
server.route("/init", QHttpServerRequest::Method::Post, [] (const QHttpServerRequest &request) { }
if (isInitialized) {
return ""; int main(int argc, char *argv[]) {
} httplib::Server server;
const bool freeTrial = request.query().queryItemValue(QStringLiteral("ft")) == QStringLiteral("1"); server.Post("/init", [] (const httplib::Request &req, httplib::Response &) {
if (isInitialized) {
if (freeTrial) { return;
putenv("SteamAppId=312060"); }
putenv("SteamGameId=312060");
} else { const bool freeTrial = req.get_param_value_count("ft") == 1;
putenv("SteamAppId=39210");
putenv("SteamGameId=39210"); if (freeTrial) {
} putenv("SteamAppId=312060");
putenv("SteamGameId=312060");
if (!SteamAPI_Init()) { } else {
qFatal() << "Failed to initialize Steam API!"; putenv("SteamAppId=39210");
} putenv("SteamGameId=39210");
}
qInfo() << "Initialized Steam API...";
if (!SteamAPI_Init()) {
isInitialized = true; std::cerr << "Failed to initialize Steam API!" << std::endl;
}
return "";
}); std::cout << "Initialized Steam API..." << std::endl;
server.route("/shutdown", QHttpServerRequest::Method::Post, [] () {
if (!isInitialized) { isInitialized = true;
return ""; });
} server.Post("/shutdown", [] (const httplib::Request &, httplib::Response &) {
if (!isInitialized) {
SteamAPI_Shutdown(); return;
}
qInfo() << "Shutting down Steam API!";
SteamAPI_Shutdown();
return ""; });
}); server.Get("/ticket", [] (const httplib::Request &, httplib::Response &res) {
server.route("/ticket", QHttpServerRequest::Method::Get, [] () { auto user = SteamAPI_GetHSteamUser();
auto user = SteamAPI_GetHSteamUser();
const int bufsize = 1024;
const int bufsize = 1024; char* buf = new char[bufsize];
char* buf = new char[bufsize];
unsigned int length = 0;
unsigned int length = 0; HAuthTicket ret = SteamUser()->GetAuthSessionTicket(buf, bufsize, &length, nullptr);
HAuthTicket ret = SteamUser()->GetAuthSessionTicket(buf, bufsize, &length, nullptr);
char hexstr[length * 2 + 1];
QJsonObject response btox(hexstr, buf, length * 2);
{ hexstr[length * 2] = 0;
{QStringLiteral("ticket"), QString::fromLatin1(QByteArray::fromRawData(buf, length).toHex())},
{QStringLiteral("time"), static_cast<qint64>(SteamUtils()->GetServerRealTime())} res.set_content("{\"ticket\":\"" + std::string(hexstr) + "\",\"time\":" + std::to_string(SteamUtils()->GetServerRealTime()) + "}", "application/json");
}; });
return QJsonDocument(response).toJson(QJsonDocument::Compact); server.listen("0.0.0.0", 50481);
});
return 0;
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();
} }