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 17:40:04 -04:00
|
|
|
#include "httplib.h"
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
static bool isInitialized = false;
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
// from https://stackoverflow.com/a/53966346
|
|
|
|
void btox(char *xp, const char *bb, int n)
|
|
|
|
{
|
|
|
|
const char xx[]= "0123456789ABCDEF";
|
|
|
|
while (--n >= 0) xp[n] = xx[(bb[n>>1] >> ((1 - (n&1)) << 2)) & 0xF];
|
|
|
|
}
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
httplib::Server server;
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
server.Post("/init", [] (const httplib::Request &req, httplib::Response &) {
|
|
|
|
if (isInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-07 17:20:03 -04:00
|
|
|
const bool freeTrial = req.get_param_value("ft") == "1";
|
2025-05-04 16:38:49 -04:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
if (freeTrial) {
|
|
|
|
putenv("SteamAppId=312060");
|
|
|
|
putenv("SteamGameId=312060");
|
|
|
|
} else {
|
|
|
|
putenv("SteamAppId=39210");
|
|
|
|
putenv("SteamGameId=39210");
|
|
|
|
}
|
2025-05-04 16:38:49 -04:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
if (!SteamAPI_Init()) {
|
|
|
|
std::cerr << "Failed to initialize Steam API!" << std::endl;
|
|
|
|
}
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
std::cout << "Initialized Steam API..." << std::endl;
|
2025-05-04 13:23:59 -04:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
isInitialized = true;
|
|
|
|
});
|
|
|
|
server.Post("/shutdown", [] (const httplib::Request &, httplib::Response &) {
|
|
|
|
if (!isInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
SteamAPI_Shutdown();
|
|
|
|
});
|
|
|
|
server.Get("/ticket", [] (const httplib::Request &, httplib::Response &res) {
|
|
|
|
auto user = SteamAPI_GetHSteamUser();
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
const int bufsize = 1024;
|
|
|
|
char* buf = new char[bufsize];
|
2025-05-04 13:23:59 -04:00
|
|
|
|
2025-05-04 17:40:04 -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 17:40:04 -04:00
|
|
|
char hexstr[length * 2 + 1];
|
|
|
|
btox(hexstr, buf, length * 2);
|
|
|
|
hexstr[length * 2] = 0;
|
2025-05-04 13:23:59 -04:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
res.set_content("{\"ticket\":\"" + std::string(hexstr) + "\",\"time\":" + std::to_string(SteamUtils()->GetServerRealTime()) + "}", "application/json");
|
|
|
|
});
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
server.listen("0.0.0.0", 50481);
|
2023-12-21 20:18:42 -05:00
|
|
|
|
2025-05-04 17:40:04 -04:00
|
|
|
return 0;
|
2023-12-21 20:18:42 -05:00
|
|
|
}
|