@zaisma/game-server 1.43.0 → 1.44.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/game-server",
3
- "version": "1.43.0",
3
+ "version": "1.44.0",
4
4
  "description": "Run your Zaisma game server: the same rooms on Zaisma or on your own server.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",
package/sdk/zaisma.d.ts CHANGED
@@ -1268,8 +1268,11 @@ declare namespace Zaisma {
1268
1268
  block(playerId: string): Promise<boolean>;
1269
1269
  /**
1270
1270
  * Report a player to Zaisma, with what happened in the player's own words if they gave any (details).
1271
- * The last chat lines (up to 20) they sent this player, or this player sent them, go with it from this
1272
- * screen; nothing else about the reporting player is sent.
1271
+ * On Zaisma it opens Zaisma's report sheet beside the game, filled in with the player, reason and words,
1272
+ * where the player picks the messages to send and sends it: only reports a player sends there count
1273
+ * toward muting someone. Resolves once they send it; rejects with error.code "report_not_sent" when they
1274
+ * close it without sending. Off Zaisma (a game's own site) the last chat lines (up to 20) they sent this
1275
+ * player, or this player sent them, go with it; nothing else about the reporting player is sent.
1273
1276
  */
1274
1277
  report(playerId: string, reason: ReportReason, details?: string): Promise<ReportAnswer>;
1275
1278
  /**
@@ -1782,6 +1785,7 @@ declare namespace Zaisma {
1782
1785
  * - slow_down: too many calls; try again in a minute.
1783
1786
  * - zaisma_rooms_not_used: the game doesn't use Zaisma rooms.
1784
1787
  * - bad_report: a report whose reason isn't a {@link ReportReason}, or whose player ID isn't one.
1788
+ * - report_not_sent: the player closed Zaisma's report sheet, which {@link Room.report} opened, without sending it.
1785
1789
  * - bad_origin: the call didn't come from the game's own page.
1786
1790
  * - not_on_zaisma: the game is played off Zaisma, so it has no player passes, sign-in or room lists; joinRoom and server.request need {@link setUpOffZaisma} and a serverUrl.
1787
1791
  * - bad_game_slug: {@link setUpOffZaisma}'s gameSlug isn't a game slug: 1 to 40 lowercase letters, digits or hyphens.
@@ -1811,6 +1815,7 @@ declare namespace Zaisma {
1811
1815
  type ErrorCode =
1812
1816
  | RoomErrorCode
1813
1817
  | RequestErrorCode
1818
+ | "report_not_sent"
1814
1819
  | "chat_stopped"
1815
1820
  | "chat_not_allowed"
1816
1821
  | "chat_empty"
@@ -1916,7 +1921,7 @@ declare namespace Zaisma {
1916
1921
  type ChatCheckReason = "contact_details" | "personal_details" | "slur" | "sexual" | "unchecked" | "too_long";
1917
1922
 
1918
1923
  /** What happened, in a player report. Zaisma looks at real_life_threat (a threat that reaches past the game: their real details, finding them, a plan), personal_details (sharing someone's), following_after_block and sexual (behavior); harassment, cheating and other go to the game's developer. */
1919
- type ReportReason = "real_life_threat" | "personal_details" | "following_after_block" | "sexual" | "harassment" | "cheating" | "other";
1924
+ type ReportReason = "real_life_threat" | "personal_details" | "following_after_block" | "sexual" | "harassment" | "cheating" | "wrong_age" | "under_13" | "other";
1920
1925
 
1921
1926
  /** Zaisma's answer to a report. */
1922
1927
  interface ReportAnswer {
package/sdk/zaisma.js CHANGED
@@ -1751,10 +1751,20 @@
1751
1751
  return blockAsk;
1752
1752
  }
1753
1753
  /**
1754
- * Report a player to Zaisma. reason: real_life_threat, personal_details, following_after_block or sexual (Zaisma looks), or harassment, cheating or other (passed to the game's developer).
1755
- * The last chat lines they sent you, or you sent them, go with it (up to 20); nothing else about you is sent.
1754
+ * Report a player to Zaisma. reason: real_life_threat, personal_details, following_after_block, sexual, wrong_age or under_13 (Zaisma looks), or harassment, cheating or other (passed to the game's developer).
1755
+ * On a Zaisma page it opens Zaisma's report sheet beside the game, filled in, and the player sends it there: only a report the
1756
+ * player sends from Zaisma counts toward muting someone. Anywhere else the last chat lines they sent you, or you sent them,
1757
+ * go with it (up to 20); nothing else about you is sent.
1756
1758
  */
1757
1759
  Room.prototype.report = function (playerId, reason, details) {
1760
+ var reported = this.players.filter(function (each) { return each.id === playerId; })[0];
1761
+ var room = this;
1762
+ var sendDirectly = function () { return room._sendReport(playerId, reason, details); };
1763
+ if (onZaismaPage() && this.roomCode) return askPageToReport(this.roomCode, { id: playerId, name: reported ? reported.name : "" }, reason, details || "", sendDirectly);
1764
+ return sendDirectly();
1765
+ };
1766
+ /** A report straight to Zaisma's rooms, with the last chat lines: off Zaisma, or when the page has no report sheet. */
1767
+ Room.prototype._sendReport = function (playerId, reason, details) {
1758
1768
  var reported = this.players.filter(function (each) { return each.id === playerId; })[0];
1759
1769
  var me = this.me ? this.me.id : null;
1760
1770
  var chatMessages = this._chatLines.filter(function (line) {
@@ -2845,6 +2855,49 @@
2845
2855
  });
2846
2856
  });
2847
2857
 
2858
+ /**
2859
+ * Zaisma's report sheet, opened beside the game for room.report: resolves { isReported: true } once the player sends it, and rejects
2860
+ * (report_not_sent) when they close it. A page that doesn't say it opened the sheet within REPORT_SHEET_WAIT_MS gets the report the
2861
+ * way it goes off Zaisma instead (fallback), so room.report never hangs.
2862
+ */
2863
+ var REPORT_SHEET_WAIT_MS = 3000;
2864
+ var reportAsks = {};
2865
+ function askPageToReport(roomCode, player, reason, details, fallback) {
2866
+ if (reportAsks[player.id]) return reportAsks[player.id];
2867
+ reportAsks[player.id] = new Promise(function (resolve, reject) {
2868
+ var isOpened = false;
2869
+ var timer = setTimeout(function () { if (!isOpened) settle(function () { fallback().then(resolve, reject); }); }, REPORT_SHEET_WAIT_MS);
2870
+ function settle(then) {
2871
+ removeEventListener("message", onMessage);
2872
+ clearTimeout(timer);
2873
+ delete reportAsks[player.id];
2874
+ then();
2875
+ }
2876
+ function onMessage(event) {
2877
+ if (event.origin !== config.site || event.source !== window.parent || !event.data || event.data.playerId !== player.id) return;
2878
+ if (event.data.type === "zaisma:report-opened") { isOpened = true; return; }
2879
+ if (event.data.type !== "zaisma:report-done") return;
2880
+ settle(function () {
2881
+ if (event.data.isReported === true) resolve({ isReported: true });
2882
+ else reject(codedError("report_not_sent", "The player closed Zaisma's report sheet without sending it."));
2883
+ });
2884
+ }
2885
+ addEventListener("message", onMessage);
2886
+ window.parent.postMessage({ type: "zaisma:report-player", code: roomCode, player: player, reason: typeof reason === "string" ? reason : "", details: String(details).slice(0, 2000) }, config.site);
2887
+ });
2888
+ return reportAsks[player.id];
2889
+ }
2890
+
2891
+ // Zaisma's report sheet asks for a player's last chat lines on this screen, for the player to tick the ones to send.
2892
+ window.addEventListener("message", function (event) {
2893
+ if (!config.site || event.origin !== config.site || event.source !== window.parent || !event.data || event.data.type !== "zaisma:chat-lines-request") return;
2894
+ var playerId = event.data.playerId, lines = [];
2895
+ joined.forEach(function (room) {
2896
+ room._chatLines.forEach(function (line) { if (line.fromPlayerId === playerId) lines.push({ fromPlayerId: line.fromPlayerId, text: line.text, sentAt: line.sentAt }); });
2897
+ });
2898
+ window.parent.postMessage({ type: "zaisma:chat-lines", id: event.data.id, playerId: playerId, lines: lines.slice(-REPORTED_CHAT_LINE_COUNT) }, config.site);
2899
+ });
2900
+
2848
2901
  // The Zaisma page says when a player report was sent from its plate: mute them, as the panel's own form does.
2849
2902
  window.addEventListener("message", function (event) {
2850
2903
  if (!config.site || event.origin !== config.site || event.source !== window.parent || !event.data || event.data.type !== "zaisma:reported") return;