Refactor project, use HTTP for IPC
Now Astra can actually fetch Steam tickets from the Steamworks API!
This commit is contained in:
parent
9acab0626a
commit
9e33b2275e
2 changed files with 54 additions and 24 deletions
|
@ -3,13 +3,15 @@ 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)
|
target_link_libraries(steamwrap PRIVATE Steamworks Qt6::HttpServer Qt6::Network Qt6::Core)
|
||||||
set_target_properties(steamwrap
|
set_target_properties(steamwrap
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
BUILD_RPATH "$ORIGIN"
|
BUILD_RPATH "$ORIGIN"
|
||||||
|
|
70
main.cpp
70
main.cpp
|
@ -1,36 +1,64 @@
|
||||||
|
#include <QHttpServer>
|
||||||
|
#include <QTcpServer>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <steam/steam_api.h>
|
#include <steam/steam_api.h>
|
||||||
#include <cstdlib>
|
#include <steam/steamclientpublic.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
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("SteamAppId=39210");
|
||||||
putenv("SteamGameId=39210");
|
putenv("SteamGameId=39210");
|
||||||
|
}
|
||||||
std::cout << "Previous LD_LIBRARY_PATH:" << getenv("LD_LIBRARY_PATH") << std::endl;
|
|
||||||
|
|
||||||
std::string newEnv = std::string("PREVIOUS_LD_LIBRARY_PATH=") + getenv("LD_LIBRARY_PATH");
|
|
||||||
|
|
||||||
putenv(const_cast<char*>(newEnv.c_str()));
|
|
||||||
|
|
||||||
putenv("LD_LIBRARY_PATH=");
|
|
||||||
|
|
||||||
if (!SteamAPI_Init()) {
|
if (!SteamAPI_Init()) {
|
||||||
throw std::runtime_error("Failed to initialize steam api!");
|
qFatal() << "Failed to initialize Steam API!";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Initialized Steam API..." << std::endl;
|
qInfo() << "Initialized Steam API...";
|
||||||
|
|
||||||
std::string args;
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
args += std::string(argv[i]) + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << args.c_str() << std::endl;
|
|
||||||
system(args.c_str());
|
|
||||||
|
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
server.route("/shutdown", QHttpServerRequest::Method::Post, [] () {
|
||||||
SteamAPI_Shutdown();
|
SteamAPI_Shutdown();
|
||||||
|
|
||||||
std::cout << "Shutdown!" << std::endl;
|
qInfo() << "Shutting down Steam API!";
|
||||||
|
|
||||||
return 0;
|
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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue