Only keep the Steam API initialized once
This commit is contained in:
parent
9e33b2275e
commit
f4ed77d21f
1 changed files with 25 additions and 8 deletions
27
main.cpp
27
main.cpp
|
@ -1,17 +1,25 @@
|
||||||
#include <QHttpServer>
|
#include <QHttpServer>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QCoreApplication>
|
#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>
|
||||||
|
|
||||||
|
static bool isInitialized = false;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
QHttpServer server;
|
QHttpServer server;
|
||||||
|
|
||||||
server.route("/init", QHttpServerRequest::Method::Post, [] (const QHttpServerRequest &request) {
|
server.route("/init", QHttpServerRequest::Method::Post, [] (const QHttpServerRequest &request) {
|
||||||
|
if (isInitialized) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
const bool freeTrial = request.query().queryItemValue(QStringLiteral("ft")) == QStringLiteral("1");
|
const bool freeTrial = request.query().queryItemValue(QStringLiteral("ft")) == QStringLiteral("1");
|
||||||
|
|
||||||
if (freeTrial) {
|
if (freeTrial) {
|
||||||
|
@ -28,9 +36,15 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
qInfo() << "Initialized Steam API...";
|
qInfo() << "Initialized Steam API...";
|
||||||
|
|
||||||
|
isInitialized = true;
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
server.route("/shutdown", QHttpServerRequest::Method::Post, [] () {
|
server.route("/shutdown", QHttpServerRequest::Method::Post, [] () {
|
||||||
|
if (!isInitialized) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
SteamAPI_Shutdown();
|
SteamAPI_Shutdown();
|
||||||
|
|
||||||
qInfo() << "Shutting down Steam API!";
|
qInfo() << "Shutting down Steam API!";
|
||||||
|
@ -43,13 +57,16 @@ int main(int argc, char *argv[]) {
|
||||||
const int bufsize = 1024;
|
const int bufsize = 1024;
|
||||||
char* buf = new char[bufsize];
|
char* buf = new char[bufsize];
|
||||||
|
|
||||||
SteamNetworkingIdentity snid;
|
|
||||||
snid.SetSteamID(SteamUser()->GetSteamID());
|
|
||||||
|
|
||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
HAuthTicket ret = SteamUser()->GetAuthSessionTicket(buf, bufsize, &length, &snid);
|
HAuthTicket ret = SteamUser()->GetAuthSessionTicket(buf, bufsize, &length, nullptr);
|
||||||
|
|
||||||
return QString::fromUtf8(buf, length);
|
QJsonObject response
|
||||||
|
{
|
||||||
|
{QStringLiteral("ticket"), QString::fromLatin1(QByteArray::fromRawData(buf, length).toHex())},
|
||||||
|
{QStringLiteral("time"), QString::number(SteamUtils()->GetServerRealTime())}
|
||||||
|
};
|
||||||
|
|
||||||
|
return QJsonDocument(response).toJson(QJsonDocument::Compact);
|
||||||
});
|
});
|
||||||
|
|
||||||
auto tcpserver = new QTcpServer();
|
auto tcpserver = new QTcpServer();
|
||||||
|
|
Loading…
Add table
Reference in a new issue