@anweather/game-plugin-ssdk 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist-cjs/runtime/auth.js +8 -0
  2. package/dist-cjs/runtime/conformance.js +6 -0
  3. package/dist-cjs/runtime/index.js +15 -1
  4. package/dist-cjs/runtime/live/checkpoint.js +31 -0
  5. package/dist-cjs/runtime/live/conformance.js +215 -0
  6. package/dist-cjs/runtime/live/harness.js +144 -0
  7. package/dist-cjs/runtime/live/outbox.js +72 -0
  8. package/dist-cjs/runtime/live/protocol.js +227 -0
  9. package/dist-cjs/runtime/live/rooms.js +579 -0
  10. package/dist-cjs/runtime/live/server.js +105 -0
  11. package/dist-cjs/runtime/servePlugin.js +8 -2
  12. package/dist-cjs/tsconfig.cjs.tsbuildinfo +1 -1
  13. package/dist-es/runtime/auth.js +5 -0
  14. package/dist-es/runtime/conformance.js +6 -0
  15. package/dist-es/runtime/index.js +5 -0
  16. package/dist-es/runtime/live/checkpoint.js +28 -0
  17. package/dist-es/runtime/live/conformance.js +210 -0
  18. package/dist-es/runtime/live/harness.js +141 -0
  19. package/dist-es/runtime/live/outbox.js +68 -0
  20. package/dist-es/runtime/live/protocol.js +217 -0
  21. package/dist-es/runtime/live/rooms.js +575 -0
  22. package/dist-es/runtime/live/server.js +102 -0
  23. package/dist-es/runtime/servePlugin.js +8 -2
  24. package/dist-es/tsconfig.es.tsbuildinfo +1 -1
  25. package/dist-types/runtime/auth.d.ts +3 -0
  26. package/dist-types/runtime/conformance.d.ts +6 -0
  27. package/dist-types/runtime/index.d.ts +11 -0
  28. package/dist-types/runtime/live/checkpoint.d.ts +15 -0
  29. package/dist-types/runtime/live/conformance.d.ts +24 -0
  30. package/dist-types/runtime/live/harness.d.ts +71 -0
  31. package/dist-types/runtime/live/outbox.d.ts +39 -0
  32. package/dist-types/runtime/live/protocol.d.ts +169 -0
  33. package/dist-types/runtime/live/rooms.d.ts +302 -0
  34. package/dist-types/runtime/live/server.d.ts +36 -0
  35. package/dist-types/runtime/servePlugin.d.ts +8 -0
  36. package/package.json +6 -3
@@ -4,6 +4,8 @@ import { createGamePluginService } from "./defaultService";
4
4
  import { mountSsdkHandler } from "./express";
5
5
  import { createRegistrationLoop } from "./registration";
6
6
  import { PLUGIN_PROTOCOL_VERSION, runtimeVersion } from "./version";
7
+ import { attachLive } from "./live/server";
8
+ import { bearerMatches } from "./auth";
7
9
  const permissiveValidation = () => undefined;
8
10
  export function createPluginApp(options) {
9
11
  const env = options.env ?? process.env;
@@ -29,7 +31,7 @@ export function createPluginApp(options) {
29
31
  return next();
30
32
  if (!authToken)
31
33
  return next();
32
- if (req.header("X-Plugin-Auth") === `Bearer ${authToken}`)
34
+ if (bearerMatches(req.header("X-Plugin-Auth"), authToken))
33
35
  return next();
34
36
  res.status(401).json({ __type: "Unauthorized", message: "missing or invalid X-Plugin-Auth" });
35
37
  });
@@ -58,10 +60,14 @@ export async function servePlugin(options) {
58
60
  });
59
61
  const boundPort = server.address().port;
60
62
  log.log(`${options.gameType} plugin backend listening on :${boundPort}`);
63
+ const live = options.live
64
+ ? attachLive(server, { gameType: options.gameType, authToken: built.authToken, live: options.live, log })
65
+ : undefined;
61
66
  built.registration.start();
62
67
  let closing;
63
68
  const close = () => (closing ??= (async () => {
64
69
  await built.registration.stop();
70
+ await live?.close();
65
71
  await new Promise((resolve) => server.close(() => resolve()));
66
72
  })());
67
73
  if (options.handleSignals ?? true) {
@@ -71,5 +77,5 @@ export async function servePlugin(options) {
71
77
  process.once("SIGTERM", onSignal);
72
78
  process.once("SIGINT", onSignal);
73
79
  }
74
- return { ...built, server, port: boundPort, close };
80
+ return { ...built, server, live, port: boundPort, close };
75
81
  }