#include #include #include #include #include "httplib.h" static bool isInitialized = false; // 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]; } int main(int argc, char *argv[]) { httplib::Server server; server.Post("/init", [] (const httplib::Request &req, httplib::Response &) { if (isInitialized) { return; } const bool freeTrial = req.get_param_value("ft") == "1"; if (freeTrial) { putenv("SteamAppId=312060"); putenv("SteamGameId=312060"); } else { putenv("SteamAppId=39210"); putenv("SteamGameId=39210"); } if (!SteamAPI_Init()) { std::cerr << "Failed to initialize Steam API!" << std::endl; return; } std::cout << "Initialized Steam API..." << std::endl; isInitialized = true; }); server.Post("/shutdown", [] (const httplib::Request &, httplib::Response &) { if (!isInitialized) { return; } SteamAPI_Shutdown(); }); server.Get("/ticket", [] (const httplib::Request &, httplib::Response &res) { auto user = SteamAPI_GetHSteamUser(); const int bufsize = 1024; char* buf = new char[bufsize]; unsigned int length = 0; HAuthTicket ret = SteamUser()->GetAuthSessionTicket(buf, bufsize, &length, nullptr); char hexstr[length * 2 + 1]; btox(hexstr, buf, length * 2); hexstr[length * 2] = 0; res.set_content("{\"ticket\":\"" + std::string(hexstr) + "\",\"time\":" + std::to_string(SteamUtils()->GetServerRealTime()) + "}", "application/json"); }); server.listen("0.0.0.0", 50481); return 0; }