1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Authorize via steam for the puzzle api

This commit is contained in:
tobspr
2021-05-23 17:34:13 +02:00
parent ec4d198df3
commit 329cefb3c9
5 changed files with 93 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ import { Application } from "../application";
/* typehints:end */
import { createLogger } from "../core/logging";
import { compressX64 } from "../core/lzstring";
import { getIPCRenderer } from "../core/utils";
import { T } from "../translations";
const logger = createLogger("puzzle-api");
@@ -109,12 +110,27 @@ export class ClientAPI {
* @returns {Promise<{token: string}>}
*/
apiTryLogin() {
return this._request("/v1/public/login", {
method: "POST",
body: {
token: this.syncToken,
if (!G_IS_STANDALONE) {
return Promise.reject("Not possible outside of standalone.");
}
const renderer = getIPCRenderer();
return renderer.invoke("steam:get-ticket").then(
ticket => {
logger.log("Got auth ticket:", ticket);
return this._request("/v1/public/login", {
method: "POST",
body: {
token: ticket,
},
});
},
});
err => {
logger.error("Failed to get auth ticket from steam: ", err);
throw err;
}
);
}
/**

View File

@@ -10,6 +10,10 @@ const logger = createLogger("electron-wrapper");
export class PlatformWrapperImplElectron extends PlatformWrapperImplBrowser {
initialize() {
this.dlcs = {
puzzle: false,
};
this.steamOverlayCanvasFix = document.createElement("canvas");
this.steamOverlayCanvasFix.width = 1;
this.steamOverlayCanvasFix.height = 1;
@@ -23,9 +27,9 @@ export class PlatformWrapperImplElectron extends PlatformWrapperImplBrowser {
this.app.storage = new StorageImplElectron(this);
this.app.achievementProvider = new SteamAchievementProvider(this.app);
return this.initializeAchievementProvider().then(() =>
PlatformWrapperInterface.prototype.initialize.call(this)
);
return this.initializeAchievementProvider()
.then(() => this.initializeDlcStatus())
.then(() => PlatformWrapperInterface.prototype.initialize.call(this));
}
steamOverlayFixRedrawCanvas() {
@@ -66,6 +70,22 @@ export class PlatformWrapperImplElectron extends PlatformWrapperImplBrowser {
});
}
initializeDlcStatus() {
const renderer = getIPCRenderer();
logger.log("Checking DLC ownership ...");
// @todo: Don't hardcode the app id
return renderer.invoke("steam:check-app-ownership", 1625400).then(
res => {
logger.log("Got DLC ownership:", res);
this.dlcs.puzzle = Boolean(res);
},
err => {
logger.error("Failed to get DLC ownership:", err);
}
);
}
getSupportsFullscreen() {
return true;
}