@zaisma/cli 0.11.0 → 0.12.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 (2) hide show
  1. package/package.json +1 -1
  2. package/zaisma.mjs +17 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/cli",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Upload and publish browser games on Zaisma from the command line.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",
package/zaisma.mjs CHANGED
@@ -90,6 +90,11 @@ const COMMANDS = {
90
90
  arguments: [{ name: "slug" }, { name: "hosts", isRest: true, isOptional: true }],
91
91
  flags: { none: { hasValue: false, about: "Set the list to none: the game server calls no other servers" } },
92
92
  },
93
+ "own-servers": {
94
+ about: "Your own servers the game connects to from players' browsers, like wss://play.example.com, named in the game's menu; given addresses, set the whole list",
95
+ arguments: [{ name: "slug" }, { name: "urls", isRest: true, isOptional: true }],
96
+ flags: { none: { hasValue: false, about: "Set the list to none: the game uses no servers of its own" } },
97
+ },
93
98
  links: { about: "A game's registered links, which it opens with Zaisma.links.open: each name, address and who it opens for", arguments: [{ name: "slug" }], flags: {} },
94
99
  "links set": {
95
100
  about: "Add a link, or change the one with the same name",
@@ -867,6 +872,17 @@ async function allowedHosts(values, flags) {
867
872
  if (given.length || flags.none) console.log("It works within a minute.");
868
873
  }
869
874
 
875
+ /** The game's own servers players' browsers connect to (own_server_urls on the game), as the MCP's get_game and update_game. */
876
+ async function ownServers(values, flags) {
877
+ const given = (values.urls ?? "").split(/[\s,]+/).filter(Boolean);
878
+ if (given.length && flags.none) refuse("unknown_field", { message: "Addresses and --none were both given.", field: "--none", fix: `Give the whole list, like zaisma own-servers ${values.slug} wss://play.example.com, or --none for none.` });
879
+ const answer = given.length || flags.none ? await api("PATCH", `/games/${values.slug}`, { own_server_urls: given }) : await api("GET", `/games/${values.slug}`);
880
+ if (isJson) return printJson(answer);
881
+ const servers = answer.game.own_server_urls;
882
+ console.log(servers.length ? `${values.slug} connects to its own servers: ${servers.join(", ")}` : `${values.slug} uses no servers of its own. Add one with: zaisma own-servers ${values.slug} wss://play.example.com`);
883
+ if (given.length || flags.none) console.log(servers.length ? "Live now: the game's menu names them." : "Live now.");
884
+ }
885
+
870
886
  /** Who a link opens for, in words (who_can_open). */
871
887
  const LINK_AUDIENCE_WORDS = { everyone: "opens for everyone", signed_in_adults: "opens for signed-in adults", nobody: "opens for nobody" };
872
888
 
@@ -1101,6 +1117,7 @@ async function run({ command, values, flags, globalFlags, rest }) {
1101
1117
  return EXIT_CODES.done;
1102
1118
  }
1103
1119
  if (command === "allowed-hosts") await allowedHosts(values, flags);
1120
+ else if (command === "own-servers") await ownServers(values, flags);
1104
1121
  else if (command === "links" || command.startsWith("links ")) await links(command, values, flags);
1105
1122
  else if (command === "secrets" || command.startsWith("secrets ")) await secrets(command, values);
1106
1123
  else if (command === "database" || command.startsWith("database ")) await database(command, values, flags);