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 <QTcpServer>
|
||||
#include <QCoreApplication>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <steam/steam_api.h>
|
||||
#include <steam/steamclientpublic.h>
|
||||
|
||||
static bool isInitialized = false;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QHttpServer server;
|
||||
|
||||
server.route("/init", QHttpServerRequest::Method::Post, [] (const QHttpServerRequest &request) {
|
||||
if (isInitialized) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const bool freeTrial = request.query().queryItemValue(QStringLiteral("ft")) == QStringLiteral("1");
|
||||
|
||||
if (freeTrial) {
|
||||
|
@ -28,9 +36,15 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
qInfo() << "Initialized Steam API...";
|
||||
|
||||
isInitialized = true;
|
||||
|
||||
return "";
|
||||
});
|
||||
server.route("/shutdown", QHttpServerRequest::Method::Post, [] () {
|
||||
if (!isInitialized) {
|
||||
return "";
|
||||
}
|
||||
|
||||
SteamAPI_Shutdown();
|
||||
|
||||
qInfo() << "Shutting down Steam API!";
|
||||
|
@ -43,13 +57,16 @@ int main(int argc, char *argv[]) {
|
|||
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);
|
||||
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();
|
||||
|
|
Loading…
Add table
Reference in a new issue