@chrischall/warapp-mcp 0.3.1 → 0.5.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +4 -0
- package/dist/bundle.js +1312 -573
- package/dist/chat.js +11 -3
- package/dist/direct/transport.js +153 -11
- package/dist/my-games.js +1 -1
- package/dist/protocol/bundle.js +283 -20
- package/dist/protocol/codec.js +1 -1
- package/dist/protocol/dialect.js +371 -0
- package/dist/protocol/interp.js +143 -66
- package/dist/protocol/methods.js +35 -29
- package/dist/protocol/rpc.js +45 -4
- package/dist/push/socketio.js +2 -2
- package/dist/surrender-pending.js +4 -4
- package/dist/tools/begin-turn.js +3 -5
- package/dist/tools/chat-inbox.js +32 -3
- package/dist/tools/chat-read-mark.js +3 -1
- package/dist/tools/check-plan.js +3 -1
- package/dist/tools/healthcheck.js +64 -8
- package/dist/tools/index.js +2 -1
- package/dist/tools/live-context.js +71 -6
- package/dist/tools/my-games.js +10 -3
- package/dist/tools/notifications.js +2 -2
- package/dist/tools/push.js +2 -1
- package/dist/tools/session.js +20 -4
- package/dist/tools/surrender-pending.js +11 -6
- package/dist/tools/turn.js +9 -1
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/bundle.js
CHANGED
|
@@ -68,7 +68,7 @@ var require_util = __commonJS({
|
|
|
68
68
|
exports.getElementAtPath = getElementAtPath2;
|
|
69
69
|
exports.promiseAllObject = promiseAllObject2;
|
|
70
70
|
exports.randomString = randomString2;
|
|
71
|
-
exports.esc =
|
|
71
|
+
exports.esc = esc3;
|
|
72
72
|
exports.slugify = slugify2;
|
|
73
73
|
exports.isObject = isObject3;
|
|
74
74
|
exports.isPlainObject = isPlainObject4;
|
|
@@ -295,7 +295,7 @@ var require_util = __commonJS({
|
|
|
295
295
|
}
|
|
296
296
|
return str;
|
|
297
297
|
}
|
|
298
|
-
function
|
|
298
|
+
function esc3(str) {
|
|
299
299
|
return JSON.stringify(str);
|
|
300
300
|
}
|
|
301
301
|
function slugify2(input2) {
|
|
@@ -93667,34 +93667,34 @@ var StatsCollector = class {
|
|
|
93667
93667
|
var Method = {
|
|
93668
93668
|
/** Exists in the client's method table, but the web client never calls it (open games come from a page). */
|
|
93669
93669
|
GetOpenGames: 10,
|
|
93670
|
-
GetGameDetails:
|
|
93671
|
-
GameRefresh:
|
|
93672
|
-
GetLatestGameInfo:
|
|
93673
|
-
SendChat:
|
|
93674
|
-
RegisterChatView:
|
|
93675
|
-
GetGameSettings:
|
|
93676
|
-
GetMyGames:
|
|
93677
|
-
AcceptGame:
|
|
93678
|
-
AcceptOpenSeat:
|
|
93679
|
-
AcceptOpenAutoGame:
|
|
93680
|
-
GetOpenAutoGame:
|
|
93681
|
-
DeclineGame:
|
|
93682
|
-
Surrender:
|
|
93683
|
-
AcceptSurrender:
|
|
93684
|
-
GetMapDetails:
|
|
93685
|
-
SendOrders:
|
|
93686
|
-
SendInProgressOrders:
|
|
93687
|
-
SendTerritoryPicks:
|
|
93688
|
-
SendInProgressPicks:
|
|
93689
|
-
BeginFirstTurn:
|
|
93690
|
-
GetTerritoryPicks:
|
|
93691
|
-
UnCommit:
|
|
93692
|
-
GetTurns:
|
|
93693
|
-
Subscribe:
|
|
93694
|
-
GameUpdated:
|
|
93695
|
-
GetInAppNotifications:
|
|
93696
|
-
DeleteInAppNotification:
|
|
93697
|
-
AcknowledgeInAppNotifications:
|
|
93670
|
+
GetGameDetails: 39,
|
|
93671
|
+
GameRefresh: 40,
|
|
93672
|
+
GetLatestGameInfo: 41,
|
|
93673
|
+
SendChat: 43,
|
|
93674
|
+
RegisterChatView: 44,
|
|
93675
|
+
GetGameSettings: 49,
|
|
93676
|
+
GetMyGames: 51,
|
|
93677
|
+
AcceptGame: 61,
|
|
93678
|
+
AcceptOpenSeat: 62,
|
|
93679
|
+
AcceptOpenAutoGame: 63,
|
|
93680
|
+
GetOpenAutoGame: 64,
|
|
93681
|
+
DeclineGame: 65,
|
|
93682
|
+
Surrender: 68,
|
|
93683
|
+
AcceptSurrender: 69,
|
|
93684
|
+
GetMapDetails: 75,
|
|
93685
|
+
SendOrders: 76,
|
|
93686
|
+
SendInProgressOrders: 77,
|
|
93687
|
+
SendTerritoryPicks: 78,
|
|
93688
|
+
SendInProgressPicks: 79,
|
|
93689
|
+
BeginFirstTurn: 80,
|
|
93690
|
+
GetTerritoryPicks: 81,
|
|
93691
|
+
UnCommit: 82,
|
|
93692
|
+
GetTurns: 83,
|
|
93693
|
+
Subscribe: 242,
|
|
93694
|
+
GameUpdated: 245,
|
|
93695
|
+
GetInAppNotifications: 323,
|
|
93696
|
+
DeleteInAppNotification: 324,
|
|
93697
|
+
AcknowledgeInAppNotifications: 325
|
|
93698
93698
|
};
|
|
93699
93699
|
var NAMES = new Map(
|
|
93700
93700
|
Object.entries(Method).map(([name, id]) => [id, name])
|
|
@@ -93795,7 +93795,7 @@ function readSubscribeResult(body) {
|
|
|
93795
93795
|
var CHAT_CHANNEL_PUBLIC = -1;
|
|
93796
93796
|
var NO_CHAT_MARKER = "-1";
|
|
93797
93797
|
function writeGameRefreshParams(w, p) {
|
|
93798
|
-
w.int32(p.gameId).bool(p.chat).bool(p.nonChat).string(NO_CHAT_MARKER).string(NO_CHAT_MARKER).bool(p.lobby).bool(false).bool(false);
|
|
93798
|
+
w.int32(p.gameId).bool(p.chat).bool(p.nonChat).string(NO_CHAT_MARKER).string(NO_CHAT_MARKER).bool(p.lobby).bool(false).bool(false).bool(false);
|
|
93799
93799
|
}
|
|
93800
93800
|
var CHAT_MARK = /^(-1|\d{1,20})$/;
|
|
93801
93801
|
function writeMarkDict(w, marks) {
|
|
@@ -93820,7 +93820,7 @@ function writeSendChatParams(w, p) {
|
|
|
93820
93820
|
w.int32(p.gameId).string(p.text).int32(p.channel ?? CHAT_CHANNEL_PUBLIC);
|
|
93821
93821
|
if (p.recipient === void 0) w.bool(false);
|
|
93822
93822
|
else w.bool(true).int32(p.recipient);
|
|
93823
|
-
w.bool(false).string(null).string(null).bool(false).bool(false);
|
|
93823
|
+
w.bool(false).string(null).string(null).bool(false).bool(false).bool(false);
|
|
93824
93824
|
}
|
|
93825
93825
|
var AttackTransferMode = { Attack: 1, Transfer: 2, AttackTransfer: 3 };
|
|
93826
93826
|
var ORDER_TAG_ATTACK_TRANSFER = 1;
|
|
@@ -109738,6 +109738,432 @@ import { createHash as createHash4, randomBytes as randomBytes4 } from "node:cry
|
|
|
109738
109738
|
import { chmod, mkdir as mkdir4, readdir as readdir4, readFile as readFile4, rename as rename4, rm, stat as stat3, unlink as unlink4, writeFile as writeFile4 } from "node:fs/promises";
|
|
109739
109739
|
import { join as join7 } from "node:path";
|
|
109740
109740
|
|
|
109741
|
+
// src/protocol/codec.ts
|
|
109742
|
+
var PREAMBLE = 1514664249;
|
|
109743
|
+
var PROTOCOL_VERSION = 243;
|
|
109744
|
+
var REPLY_FLAG = 32768;
|
|
109745
|
+
var DATE_EPOCH_MS = Date.UTC(2e3, 0, 1);
|
|
109746
|
+
var NO_DATE_SENTINEL = -34028235e47;
|
|
109747
|
+
var MAX_DATE_SENTINEL = 34028235e47;
|
|
109748
|
+
var DATE_SENTINEL_THRESHOLD = 2524556148e5;
|
|
109749
|
+
var MAX_DATE = /* @__PURE__ */ new Date(864e13);
|
|
109750
|
+
var EXTRAS_PRESENT = 1;
|
|
109751
|
+
var ERROR_KIND = 5;
|
|
109752
|
+
var ProtocolError3 = class extends Error {
|
|
109753
|
+
constructor(kind, message) {
|
|
109754
|
+
super(message);
|
|
109755
|
+
this.kind = kind;
|
|
109756
|
+
this.name = "ProtocolError";
|
|
109757
|
+
}
|
|
109758
|
+
kind;
|
|
109759
|
+
};
|
|
109760
|
+
var MAX_WIRE_COUNT = 1e6;
|
|
109761
|
+
var MAX_EMPTY_ITEMS = 1024;
|
|
109762
|
+
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
109763
|
+
var utf8Encoder = new TextEncoder();
|
|
109764
|
+
var GUID_ORDER = [3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15];
|
|
109765
|
+
function checkInt(value, min, max, what) {
|
|
109766
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
109767
|
+
throw new ProtocolError3("out-of-range", `${what} out of range: ${value}`);
|
|
109768
|
+
}
|
|
109769
|
+
}
|
|
109770
|
+
var Writer = class {
|
|
109771
|
+
buf = new Uint8Array(64);
|
|
109772
|
+
view = new DataView(this.buf.buffer);
|
|
109773
|
+
len = 0;
|
|
109774
|
+
ensure(n) {
|
|
109775
|
+
if (this.len + n <= this.buf.length) return;
|
|
109776
|
+
let size = this.buf.length * 2;
|
|
109777
|
+
while (size < this.len + n) size *= 2;
|
|
109778
|
+
const next = new Uint8Array(size);
|
|
109779
|
+
next.set(this.buf.subarray(0, this.len));
|
|
109780
|
+
this.buf = next;
|
|
109781
|
+
this.view = new DataView(next.buffer);
|
|
109782
|
+
}
|
|
109783
|
+
get length() {
|
|
109784
|
+
return this.len;
|
|
109785
|
+
}
|
|
109786
|
+
bytes() {
|
|
109787
|
+
return this.buf.slice(0, this.len);
|
|
109788
|
+
}
|
|
109789
|
+
u8(value) {
|
|
109790
|
+
checkInt(value, 0, 255, "u8");
|
|
109791
|
+
this.ensure(1);
|
|
109792
|
+
this.buf[this.len++] = value;
|
|
109793
|
+
return this;
|
|
109794
|
+
}
|
|
109795
|
+
raw(bytes) {
|
|
109796
|
+
this.ensure(bytes.length);
|
|
109797
|
+
this.buf.set(bytes, this.len);
|
|
109798
|
+
this.len += bytes.length;
|
|
109799
|
+
return this;
|
|
109800
|
+
}
|
|
109801
|
+
bool(value) {
|
|
109802
|
+
return this.u8(value ? 1 : 0);
|
|
109803
|
+
}
|
|
109804
|
+
uint16(value) {
|
|
109805
|
+
checkInt(value, 0, 65535, "uint16");
|
|
109806
|
+
this.ensure(2);
|
|
109807
|
+
this.view.setUint16(this.len, value, true);
|
|
109808
|
+
this.len += 2;
|
|
109809
|
+
return this;
|
|
109810
|
+
}
|
|
109811
|
+
int16(value) {
|
|
109812
|
+
checkInt(value, -32768, 32767, "int16");
|
|
109813
|
+
this.ensure(2);
|
|
109814
|
+
this.view.setInt16(this.len, value, true);
|
|
109815
|
+
this.len += 2;
|
|
109816
|
+
return this;
|
|
109817
|
+
}
|
|
109818
|
+
int32(value) {
|
|
109819
|
+
checkInt(value, -2147483648, 2147483647, "int32");
|
|
109820
|
+
this.ensure(4);
|
|
109821
|
+
this.view.setInt32(this.len, value, true);
|
|
109822
|
+
this.len += 4;
|
|
109823
|
+
return this;
|
|
109824
|
+
}
|
|
109825
|
+
int64(value) {
|
|
109826
|
+
if (typeof value === "number") checkInt(value, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, "int64");
|
|
109827
|
+
const big = BigInt(value);
|
|
109828
|
+
if (big < -(1n << 63n) || big >= 1n << 63n) throw new ProtocolError3("out-of-range", `int64 out of range: ${big}`);
|
|
109829
|
+
this.ensure(8);
|
|
109830
|
+
this.view.setBigInt64(this.len, big, true);
|
|
109831
|
+
this.len += 8;
|
|
109832
|
+
return this;
|
|
109833
|
+
}
|
|
109834
|
+
float32(value) {
|
|
109835
|
+
this.ensure(4);
|
|
109836
|
+
this.view.setFloat32(this.len, value, true);
|
|
109837
|
+
this.len += 4;
|
|
109838
|
+
return this;
|
|
109839
|
+
}
|
|
109840
|
+
float64(value) {
|
|
109841
|
+
this.ensure(8);
|
|
109842
|
+
this.view.setFloat64(this.len, value, true);
|
|
109843
|
+
this.len += 8;
|
|
109844
|
+
return this;
|
|
109845
|
+
}
|
|
109846
|
+
varint(value) {
|
|
109847
|
+
checkInt(value, 0, 4294967295, "varint");
|
|
109848
|
+
let n = value;
|
|
109849
|
+
for (; ; ) {
|
|
109850
|
+
const low = n % 128;
|
|
109851
|
+
n = Math.floor(n / 128);
|
|
109852
|
+
this.u8(n > 0 ? low | 128 : low);
|
|
109853
|
+
if (n === 0) return this;
|
|
109854
|
+
}
|
|
109855
|
+
}
|
|
109856
|
+
/** A nullable string: present flag, varint byte length, UTF-8. */
|
|
109857
|
+
string(value) {
|
|
109858
|
+
if (value === null) return this.bool(false);
|
|
109859
|
+
const encoded = utf8Encoder.encode(value);
|
|
109860
|
+
return this.bool(true).varint(encoded.length).raw(encoded);
|
|
109861
|
+
}
|
|
109862
|
+
/** A datetime; null is the "no date" sentinel. */
|
|
109863
|
+
date(value) {
|
|
109864
|
+
if (value === null) return this.float64(NO_DATE_SENTINEL);
|
|
109865
|
+
const ms = value.getTime();
|
|
109866
|
+
if (Number.isNaN(ms)) throw new ProtocolError3("out-of-range", "invalid Date");
|
|
109867
|
+
if (ms >= MAX_DATE.getTime()) return this.float64(MAX_DATE_SENTINEL);
|
|
109868
|
+
return this.float64(ms - DATE_EPOCH_MS);
|
|
109869
|
+
}
|
|
109870
|
+
/** A GUID from its 32-hex-digit form (dashes allowed), written in .NET byte order. */
|
|
109871
|
+
guid(value) {
|
|
109872
|
+
const hex3 = value.replace(/-/g, "");
|
|
109873
|
+
if (!/^[0-9a-fA-F]{32}$/.test(hex3)) throw new ProtocolError3("out-of-range", `not a guid: ${value}`);
|
|
109874
|
+
const canonical = Array.from({ length: 16 }, (_, i2) => parseInt(hex3.slice(i2 * 2, i2 * 2 + 2), 16));
|
|
109875
|
+
const out = new Uint8Array(16);
|
|
109876
|
+
GUID_ORDER.forEach((src, i2) => {
|
|
109877
|
+
out[src] = canonical[i2];
|
|
109878
|
+
});
|
|
109879
|
+
return this.raw(out);
|
|
109880
|
+
}
|
|
109881
|
+
/** A nullable list: int32 count (-1 = null), then each item. */
|
|
109882
|
+
list(items, writeItem) {
|
|
109883
|
+
if (items === null) return this.int32(-1);
|
|
109884
|
+
this.int32(items.length);
|
|
109885
|
+
for (const item of items) writeItem(this, item);
|
|
109886
|
+
return this;
|
|
109887
|
+
}
|
|
109888
|
+
/** A nullable dict: int32 count (-1 = null), then key, value pairs. */
|
|
109889
|
+
dict(entries2, writeKey, writeValue) {
|
|
109890
|
+
if (entries2 === null) return this.int32(-1);
|
|
109891
|
+
this.int32(entries2.size);
|
|
109892
|
+
for (const [k, v] of entries2) {
|
|
109893
|
+
writeKey(this, k);
|
|
109894
|
+
writeValue(this, v);
|
|
109895
|
+
}
|
|
109896
|
+
return this;
|
|
109897
|
+
}
|
|
109898
|
+
};
|
|
109899
|
+
var Reader = class {
|
|
109900
|
+
constructor(buf, offset2 = 0) {
|
|
109901
|
+
this.buf = buf;
|
|
109902
|
+
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
109903
|
+
this.pos = offset2;
|
|
109904
|
+
}
|
|
109905
|
+
buf;
|
|
109906
|
+
view;
|
|
109907
|
+
pos;
|
|
109908
|
+
get position() {
|
|
109909
|
+
return this.pos;
|
|
109910
|
+
}
|
|
109911
|
+
get remaining() {
|
|
109912
|
+
return this.buf.length - this.pos;
|
|
109913
|
+
}
|
|
109914
|
+
need(n) {
|
|
109915
|
+
if (this.pos + n > this.buf.length) {
|
|
109916
|
+
throw new ProtocolError3("truncated", `read past end: need ${n} byte(s) at offset ${this.pos} of ${this.buf.length}`);
|
|
109917
|
+
}
|
|
109918
|
+
}
|
|
109919
|
+
u8() {
|
|
109920
|
+
this.need(1);
|
|
109921
|
+
return this.buf[this.pos++];
|
|
109922
|
+
}
|
|
109923
|
+
/**
|
|
109924
|
+
* `n` bytes. `n` often comes from the wire (a string or byte-array length), so anything but a
|
|
109925
|
+
* non-negative integer is refused before the position moves: a negative length would rewind the
|
|
109926
|
+
* reader and a NaN or fractional one would leave every later read misaligned.
|
|
109927
|
+
*/
|
|
109928
|
+
raw(n) {
|
|
109929
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
109930
|
+
throw new ProtocolError3("bad-length", `bad byte count ${n} at offset ${this.pos}`);
|
|
109931
|
+
}
|
|
109932
|
+
this.need(n);
|
|
109933
|
+
const out = this.buf.slice(this.pos, this.pos + n);
|
|
109934
|
+
this.pos += n;
|
|
109935
|
+
return out;
|
|
109936
|
+
}
|
|
109937
|
+
bool() {
|
|
109938
|
+
const v = this.u8();
|
|
109939
|
+
if (v > 1) throw new ProtocolError3("bad-bool", `bad bool ${v} at offset ${this.pos - 1}`);
|
|
109940
|
+
return v === 1;
|
|
109941
|
+
}
|
|
109942
|
+
uint16() {
|
|
109943
|
+
this.need(2);
|
|
109944
|
+
const v = this.view.getUint16(this.pos, true);
|
|
109945
|
+
this.pos += 2;
|
|
109946
|
+
return v;
|
|
109947
|
+
}
|
|
109948
|
+
int16() {
|
|
109949
|
+
this.need(2);
|
|
109950
|
+
const v = this.view.getInt16(this.pos, true);
|
|
109951
|
+
this.pos += 2;
|
|
109952
|
+
return v;
|
|
109953
|
+
}
|
|
109954
|
+
int32() {
|
|
109955
|
+
this.need(4);
|
|
109956
|
+
const v = this.view.getInt32(this.pos, true);
|
|
109957
|
+
this.pos += 4;
|
|
109958
|
+
return v;
|
|
109959
|
+
}
|
|
109960
|
+
/** An int64 as a number (exact up to 2^53). */
|
|
109961
|
+
int64() {
|
|
109962
|
+
this.need(8);
|
|
109963
|
+
const v = this.view.getBigInt64(this.pos, true);
|
|
109964
|
+
this.pos += 8;
|
|
109965
|
+
return Number(v);
|
|
109966
|
+
}
|
|
109967
|
+
float32() {
|
|
109968
|
+
this.need(4);
|
|
109969
|
+
const v = this.view.getFloat32(this.pos, true);
|
|
109970
|
+
this.pos += 4;
|
|
109971
|
+
return v;
|
|
109972
|
+
}
|
|
109973
|
+
float64() {
|
|
109974
|
+
this.need(8);
|
|
109975
|
+
const v = this.view.getFloat64(this.pos, true);
|
|
109976
|
+
this.pos += 8;
|
|
109977
|
+
return v;
|
|
109978
|
+
}
|
|
109979
|
+
varint() {
|
|
109980
|
+
let n = 0;
|
|
109981
|
+
let scale = 1;
|
|
109982
|
+
for (let i2 = 0; i2 < 5; i2++) {
|
|
109983
|
+
const c = this.u8();
|
|
109984
|
+
n += (c & 127) * scale;
|
|
109985
|
+
if (!(c & 128)) return n;
|
|
109986
|
+
scale *= 128;
|
|
109987
|
+
}
|
|
109988
|
+
throw new ProtocolError3("bad-varint", `varint longer than 5 bytes ending at offset ${this.pos}`);
|
|
109989
|
+
}
|
|
109990
|
+
string() {
|
|
109991
|
+
if (!this.bool()) return null;
|
|
109992
|
+
const start = this.pos;
|
|
109993
|
+
const n = this.varint();
|
|
109994
|
+
const bytes = this.raw(n);
|
|
109995
|
+
try {
|
|
109996
|
+
return utf8Decoder.decode(bytes);
|
|
109997
|
+
} catch {
|
|
109998
|
+
throw new ProtocolError3("bad-string", `invalid UTF-8 in string at offset ${start}`);
|
|
109999
|
+
}
|
|
110000
|
+
}
|
|
110001
|
+
/** A datetime; the "no date" sentinel reads as null, the max sentinel as MAX_DATE. */
|
|
110002
|
+
date() {
|
|
110003
|
+
const ms = this.float64();
|
|
110004
|
+
if (ms <= -DATE_SENTINEL_THRESHOLD) return null;
|
|
110005
|
+
if (ms >= DATE_SENTINEL_THRESHOLD) return MAX_DATE;
|
|
110006
|
+
return new Date(DATE_EPOCH_MS + ms);
|
|
110007
|
+
}
|
|
110008
|
+
/** A GUID as 32 lowercase hex digits in canonical order. */
|
|
110009
|
+
guid() {
|
|
110010
|
+
const b = this.raw(16);
|
|
110011
|
+
return GUID_ORDER.map((i2) => b[i2].toString(16).padStart(2, "0")).join("");
|
|
110012
|
+
}
|
|
110013
|
+
count() {
|
|
110014
|
+
const at2 = this.pos;
|
|
110015
|
+
const n = this.int32();
|
|
110016
|
+
if (n === -1) return null;
|
|
110017
|
+
if (!Number.isInteger(n) || n < 0) throw new ProtocolError3("bad-length", `bad count ${n} at offset ${at2}`);
|
|
110018
|
+
if (n > MAX_WIRE_COUNT) {
|
|
110019
|
+
throw new ProtocolError3("bad-length", `count ${n} at offset ${at2} exceeds ${MAX_WIRE_COUNT}`);
|
|
110020
|
+
}
|
|
110021
|
+
return n;
|
|
110022
|
+
}
|
|
110023
|
+
/** Refuses a long collection once an item is seen to take no bytes (see MAX_EMPTY_ITEMS). */
|
|
110024
|
+
checkItemSize(n, before, at2) {
|
|
110025
|
+
if (n > MAX_EMPTY_ITEMS && this.pos === before) {
|
|
110026
|
+
throw new ProtocolError3(
|
|
110027
|
+
"bad-length",
|
|
110028
|
+
`count ${n} at offset ${at2} of items that take no bytes (at most ${MAX_EMPTY_ITEMS})`
|
|
110029
|
+
);
|
|
110030
|
+
}
|
|
110031
|
+
}
|
|
110032
|
+
list(readItem) {
|
|
110033
|
+
const at2 = this.pos;
|
|
110034
|
+
const n = this.count();
|
|
110035
|
+
if (n === null) return null;
|
|
110036
|
+
const out = [];
|
|
110037
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
110038
|
+
const before = this.pos;
|
|
110039
|
+
out.push(readItem(this));
|
|
110040
|
+
this.checkItemSize(n, before, at2);
|
|
110041
|
+
}
|
|
110042
|
+
return out;
|
|
110043
|
+
}
|
|
110044
|
+
dict(readKey, readValue) {
|
|
110045
|
+
const at2 = this.pos;
|
|
110046
|
+
const n = this.count();
|
|
110047
|
+
if (n === null) return null;
|
|
110048
|
+
const out = /* @__PURE__ */ new Map();
|
|
110049
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
110050
|
+
const before = this.pos;
|
|
110051
|
+
const k = readKey(this);
|
|
110052
|
+
out.set(k, readValue(this));
|
|
110053
|
+
this.checkItemSize(n, before, at2);
|
|
110054
|
+
}
|
|
110055
|
+
return out;
|
|
110056
|
+
}
|
|
110057
|
+
};
|
|
110058
|
+
function writeHeader(w, h) {
|
|
110059
|
+
w.uint16(h.version & 32767 | (h.reply ? REPLY_FLAG : 0)).int32(PREAMBLE).int32(h.msgNum).int32(h.method);
|
|
110060
|
+
}
|
|
110061
|
+
function readHeader(r) {
|
|
110062
|
+
const flags = r.uint16();
|
|
110063
|
+
const preamble = r.int32();
|
|
110064
|
+
if (preamble !== PREAMBLE) {
|
|
110065
|
+
throw new ProtocolError3("bad-preamble", `bad preamble ${preamble} (expected ${PREAMBLE})`);
|
|
110066
|
+
}
|
|
110067
|
+
return { version: flags & 32767, reply: (flags & REPLY_FLAG) !== 0, msgNum: r.int32(), method: r.int32() };
|
|
110068
|
+
}
|
|
110069
|
+
var writeIntStringDict = (w, d) => {
|
|
110070
|
+
if (d === null) {
|
|
110071
|
+
w.bool(false);
|
|
110072
|
+
return;
|
|
110073
|
+
}
|
|
110074
|
+
w.bool(true).dict(
|
|
110075
|
+
d,
|
|
110076
|
+
(ww, k) => ww.int32(k),
|
|
110077
|
+
(ww, v) => ww.string(v)
|
|
110078
|
+
);
|
|
110079
|
+
};
|
|
110080
|
+
var readIntStringDict = (r) => r.bool() ? r.dict(
|
|
110081
|
+
(rr) => rr.int32(),
|
|
110082
|
+
(rr) => rr.string()
|
|
110083
|
+
) : null;
|
|
110084
|
+
function writeExtrasUp(w, e) {
|
|
110085
|
+
writeIntStringDict(w, e.dict);
|
|
110086
|
+
w.string(e.client).int32(e.serverInfoVersionA).int32(e.serverInfoVersionB).date(e.fDb).date(e.kFa).int32(e.platform);
|
|
110087
|
+
}
|
|
110088
|
+
function readExtrasUp(r) {
|
|
110089
|
+
const dict = readIntStringDict(r);
|
|
110090
|
+
return {
|
|
110091
|
+
dict: dict === null ? null : new Map([...dict].map(([k, v]) => [k, v ?? ""])),
|
|
110092
|
+
client: r.string(),
|
|
110093
|
+
serverInfoVersionA: r.int32(),
|
|
110094
|
+
serverInfoVersionB: r.int32(),
|
|
110095
|
+
fDb: r.date(),
|
|
110096
|
+
kFa: r.date(),
|
|
110097
|
+
platform: r.int32()
|
|
110098
|
+
};
|
|
110099
|
+
}
|
|
110100
|
+
function optional4(r, read) {
|
|
110101
|
+
return r.bool() ? read(r) : null;
|
|
110102
|
+
}
|
|
110103
|
+
function readExtrasDown(r) {
|
|
110104
|
+
return {
|
|
110105
|
+
cAa: readIntStringDict(r),
|
|
110106
|
+
wca: optional4(r, (rr) => rr.int32()),
|
|
110107
|
+
c2a: r.string(),
|
|
110108
|
+
serverInfo: optional4(r, (rr) => ({
|
|
110109
|
+
okb: rr.string(),
|
|
110110
|
+
lbFlags: rr.string(),
|
|
110111
|
+
serverInfoVersionA: rr.int32(),
|
|
110112
|
+
livestream: optional4(rr, (l) => ({
|
|
110113
|
+
j7: l.string(),
|
|
110114
|
+
jdb: l.int32(),
|
|
110115
|
+
lr: l.date(),
|
|
110116
|
+
zfd: l.string(),
|
|
110117
|
+
yfd: l.string()
|
|
110118
|
+
})),
|
|
110119
|
+
serverInfoVersionB: rr.int32()
|
|
110120
|
+
})),
|
|
110121
|
+
j9: optional4(
|
|
110122
|
+
r,
|
|
110123
|
+
(rr) => rr.dict(
|
|
110124
|
+
(k) => k.int32(),
|
|
110125
|
+
(v) => optional4(v, (vv) => vv.list((s) => s.string()))
|
|
110126
|
+
)
|
|
110127
|
+
),
|
|
110128
|
+
unreadMail: optional4(r, (rr) => ({ cYa: rr.bool(), kFa: rr.date(), h9: rr.bool() }))
|
|
110129
|
+
};
|
|
110130
|
+
}
|
|
110131
|
+
var AUTH_TAG = 4;
|
|
110132
|
+
function encodeRequest(frame) {
|
|
110133
|
+
const w = new Writer();
|
|
110134
|
+
writeHeader(w, {
|
|
110135
|
+
version: frame.version ?? PROTOCOL_VERSION,
|
|
110136
|
+
reply: false,
|
|
110137
|
+
msgNum: frame.msgNum,
|
|
110138
|
+
method: frame.method
|
|
110139
|
+
});
|
|
110140
|
+
writeExtrasUp(w, frame.extras);
|
|
110141
|
+
if (frame.email !== null) w.bool(true).u8(AUTH_TAG).string(frame.email);
|
|
110142
|
+
frame.params?.(w);
|
|
110143
|
+
return w.bytes();
|
|
110144
|
+
}
|
|
110145
|
+
function decodeReplyEnvelope(bytes) {
|
|
110146
|
+
const r = new Reader(bytes);
|
|
110147
|
+
const header = readHeader(r);
|
|
110148
|
+
if (!header.reply) throw new ProtocolError3("not-a-reply", `frame for method ${header.method} is not a reply`);
|
|
110149
|
+
const env = { version: header.version, method: header.method, msgNum: header.msgNum, body: r };
|
|
110150
|
+
if (r.u8() === EXTRAS_PRESENT) env.extrasDown = readExtrasDown(r);
|
|
110151
|
+
if (r.u8() === ERROR_KIND) env.error = { code: r.int32(), message: r.string() };
|
|
110152
|
+
return env;
|
|
110153
|
+
}
|
|
110154
|
+
function toHex(bytes) {
|
|
110155
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
110156
|
+
}
|
|
110157
|
+
function fromHex(hex3) {
|
|
110158
|
+
const clean2 = hex3.trim();
|
|
110159
|
+
if (clean2.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(clean2)) {
|
|
110160
|
+
throw new ProtocolError3("bad-length", "not an even-length hex string");
|
|
110161
|
+
}
|
|
110162
|
+
const out = new Uint8Array(clean2.length / 2);
|
|
110163
|
+
for (let i2 = 0; i2 < out.length; i2++) out[i2] = parseInt(clean2.slice(i2 * 2, i2 * 2 + 2), 16);
|
|
110164
|
+
return out;
|
|
110165
|
+
}
|
|
110166
|
+
|
|
109741
110167
|
// node_modules/acorn/dist/acorn.mjs
|
|
109742
110168
|
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 31, 4, 33, 15, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 7, 0, 259, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 481, 1, 61, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 12, 2, 9, 1, 3, 0, 33, 1, 1357, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
109743
110169
|
var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 13, 65, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 18, 21, 18, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 18, 0, 182, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 22, 0, 239, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 111, 6, 206, 13, 310, 2314, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7386, 37, 33, 96, 114, 14, 913, 15, 50, 7710, 3, 2, 6, 2, 1, 2, 296, 10, 0, 30, 2, 3, 0, 15, 4, 8, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 340, 2, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 129, 15, 6, 55, 50, 49, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4382, 2, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489, 39815, 11327];
|
|
@@ -115418,11 +115844,11 @@ pp.readWord1 = function() {
|
|
|
115418
115844
|
this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX");
|
|
115419
115845
|
}
|
|
115420
115846
|
++this.pos;
|
|
115421
|
-
var
|
|
115422
|
-
if (!(first ? isIdentifierStart : isIdentifierChar)(
|
|
115847
|
+
var esc3 = this.readCodePoint();
|
|
115848
|
+
if (!(first ? isIdentifierStart : isIdentifierChar)(esc3, astral)) {
|
|
115423
115849
|
this.invalidStringToken(escStart, "Invalid Unicode escape");
|
|
115424
115850
|
}
|
|
115425
|
-
word += codePointToString(
|
|
115851
|
+
word += codePointToString(esc3);
|
|
115426
115852
|
chunkStart = this.pos;
|
|
115427
115853
|
} else {
|
|
115428
115854
|
break;
|
|
@@ -115465,430 +115891,274 @@ function parseExpressionAt2(input2, pos, options) {
|
|
|
115465
115891
|
return Parser.parseExpressionAt(input2, pos, options);
|
|
115466
115892
|
}
|
|
115467
115893
|
|
|
115468
|
-
// src/protocol/
|
|
115469
|
-
var
|
|
115470
|
-
var
|
|
115471
|
-
var
|
|
115472
|
-
var
|
|
115473
|
-
var
|
|
115474
|
-
var
|
|
115475
|
-
var
|
|
115476
|
-
|
|
115477
|
-
|
|
115478
|
-
|
|
115479
|
-
|
|
115480
|
-
|
|
115481
|
-
|
|
115482
|
-
|
|
115483
|
-
|
|
115484
|
-
|
|
115485
|
-
|
|
115486
|
-
|
|
115487
|
-
|
|
115488
|
-
|
|
115489
|
-
|
|
115490
|
-
|
|
115491
|
-
|
|
115492
|
-
|
|
115493
|
-
|
|
115494
|
-
|
|
115894
|
+
// src/protocol/dialect.ts
|
|
115895
|
+
var INPUT_TYPE = "haxe.io.Input";
|
|
115896
|
+
var READER_TYPE = "system.io.BinaryReader";
|
|
115897
|
+
var SERIALIZER_TYPE = "warlight.shared.Serializer";
|
|
115898
|
+
var UTILITY_TYPE = "warlight.shared.SharedUtility";
|
|
115899
|
+
var PUMP_TYPE = "warlight.shared.MessagePump";
|
|
115900
|
+
var ENUMERABLE_TYPE = "system.linq.Enumerable";
|
|
115901
|
+
var WRAPPER_TYPES = [
|
|
115902
|
+
"system.Nullable_Int",
|
|
115903
|
+
"system.Nullable",
|
|
115904
|
+
"system.Nullable_Float",
|
|
115905
|
+
"system.Nullable_Bool",
|
|
115906
|
+
"system.CsRef",
|
|
115907
|
+
"system.TimeSpan",
|
|
115908
|
+
"system.DateTime"
|
|
115909
|
+
];
|
|
115910
|
+
var MAX_FN_SOURCE = 4e3;
|
|
115911
|
+
var REQUIRED_READER_ROLES = ["bool", "int32", "u8", "string", "float64", "float32", "uint16", "raw", "varint"];
|
|
115912
|
+
var REQUIRED_STATIC_ROLES = [
|
|
115913
|
+
"int32",
|
|
115914
|
+
"string",
|
|
115915
|
+
"bool",
|
|
115916
|
+
"u8",
|
|
115917
|
+
"float32",
|
|
115918
|
+
"float64",
|
|
115919
|
+
"timespan",
|
|
115920
|
+
"date",
|
|
115921
|
+
"guid",
|
|
115922
|
+
"uint16",
|
|
115923
|
+
"bytes",
|
|
115924
|
+
"list",
|
|
115925
|
+
"dict"
|
|
115926
|
+
];
|
|
115927
|
+
var KEYWORDS = new Set(
|
|
115928
|
+
"var let const function return if else for while do break continue new null true false this typeof instanceof in of throw try catch finally switch case default void delete".split(" ")
|
|
115929
|
+
);
|
|
115930
|
+
var TOKEN = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[A-Za-z_$][\w$]*|\d+(?:\.\d+)?(?:[eE][-+]?\d+)?|>>>=?|===|!==|<<=|>>=|[=!<>]=|&&|\|\||\+\+|--|<<|>>|[-+*/%&|^]=|\S/g;
|
|
115931
|
+
function canonicalize(src, roleOf, typeOf2) {
|
|
115932
|
+
const names2 = /* @__PURE__ */ new Map();
|
|
115933
|
+
const out = [];
|
|
115934
|
+
let prev = "";
|
|
115935
|
+
for (const t of src.match(TOKEN) ?? []) {
|
|
115936
|
+
const c = t[0];
|
|
115937
|
+
const isName = /[A-Za-z_$]/.test(c);
|
|
115938
|
+
if (!isName || KEYWORDS.has(t)) out.push(t);
|
|
115939
|
+
else if (prev === "." && roleOf(t) !== void 0) out.push(`@${roleOf(t)}`);
|
|
115940
|
+
else if (prev !== "." && typeOf2(t) !== void 0) out.push(`@T:${typeOf2(t)}`);
|
|
115941
|
+
else {
|
|
115942
|
+
let n = names2.get(t);
|
|
115943
|
+
if (n === void 0) {
|
|
115944
|
+
n = `#${names2.size}`;
|
|
115945
|
+
names2.set(t, n);
|
|
115946
|
+
}
|
|
115947
|
+
out.push(n);
|
|
115948
|
+
}
|
|
115949
|
+
prev = t;
|
|
115950
|
+
}
|
|
115951
|
+
return out.join(" ");
|
|
115952
|
+
}
|
|
115953
|
+
var SERIALIZER_TEMPLATES = {
|
|
115954
|
+
"function ( #0 ) { return #0 . @int32 ( ) }": "int32",
|
|
115955
|
+
"function ( #0 ) { return #0 . @bool ( ) ? #0 . @string ( ) : null }": "string",
|
|
115956
|
+
"function ( #0 ) { return #0 . @bool ( ) }": "bool",
|
|
115957
|
+
"function ( #0 ) { return #0 . @u8 ( ) }": "u8",
|
|
115958
|
+
"function ( #0 ) { return #0 . @float32 ( ) }": "float32",
|
|
115959
|
+
"function ( #0 ) { return #0 . @float64 ( ) }": "float64",
|
|
115960
|
+
"function ( #0 ) { return #0 . @uint16 ( ) }": "uint16",
|
|
115961
|
+
"function ( #0 ) { #0 = #0 . @float64 ( ) ; return - 922336666814565 >= #0 ? @T:system.TimeSpan . #1 : 922336666814565 <= #0 ? @T:system.TimeSpan . #2 : new @T:system.TimeSpan ( #0 ) }": "timespan",
|
|
115962
|
+
"function ( #0 ) { var #1 = #0 . @int32 ( ) ; return - 1 == #1 ? null : #0 . @raw ( #1 ) }": "bytes",
|
|
115963
|
+
"function ( #0 , #1 ) { #0 = #0 . @int32 ( ) ; if ( - 1 == #0 ) return null ; for ( var #2 = [ ] , #3 = 0 ; #3 < #0 ; ) #2 . #4 ( #1 ( ) ) , ++ #3 ; return #2 }": "list",
|
|
115964
|
+
"function ( #0 , #1 ) { #0 = #0 . @int32 ( ) ; if ( - 1 == #0 ) return null ; for ( var #2 = [ ] , #3 = 0 ; #3 < #0 ; ) #2 [ #3 ] = #1 ( ) , ++ #3 ; return #2 }": "list",
|
|
115965
|
+
'function ( #0 , #1 , #2 ) { #0 = #0 . @int32 ( ) ; if ( - 1 == #0 ) return null ; for ( var #3 = new @T:system.collections.generic.Dictionary ( #0 ) , #4 = 0 ; #4 < #0 ; ) { var #5 = #1 ( ) ; @T:warlight.shared.Assert . #6 ( ! #3 . #7 ( #5 ) , "Dupe keys deserialized" ) ; #3 . #8 ( #5 , #2 ( ) ) ; ++ #4 } return #3 }': "dict"
|
|
115966
|
+
};
|
|
115967
|
+
var UTILITY_CALL = "function ( #0 ) { return @T:warlight.shared.SharedUtility . #1 ( #0 ) }";
|
|
115968
|
+
var COLLECTION_LIST = /^function \( #0 , #1 \) \{ #0 = #0 \. @int32 \( \) ; if \( - 1 == #0 \) return null ; for \( var #2 = new (?:#\d+|@T:[\w.$]+) , #3 = 0 ; #3 < #0 ; \) #2 \. #\d+ \( #1 \( \) \) , \+\+ #3 ; return #2 \}$/;
|
|
115969
|
+
var UTILITY_IDENTITY_MARK = '"ParseLongSafe(null)"';
|
|
115970
|
+
var UTILITY_TRY_GET = /^function \( #0 , #1 , #2 \) \{ var #3 = new @T:system\.CsRef \( null \) ; return #0 \. #4 \( #1 , #3 \) \? #3 \. #5 : #2 \}$/;
|
|
115971
|
+
var IDENTITY = "function ( #0 ) { return #0 }";
|
|
115972
|
+
var SELECT = "function ( #0 , #1 ) { for ( var #2 = [ ] , #3 = 0 ; #3 < #0 . #4 ; ) { var #5 = #0 [ #3 ] ; ++ #3 ; #2 . #6 ( #1 ( #5 ) ) } return #2 }";
|
|
115973
|
+
var TO_ARRAY = "function ( #0 ) { for ( var #1 = [ ] , #2 = 0 ; #2 < #0 . #3 ; ) { var #4 = #0 [ #2 ] ; ++ #2 ; #1 . #5 ( #4 ) } return #1 }";
|
|
115974
|
+
function functionAt(src, at2) {
|
|
115975
|
+
try {
|
|
115976
|
+
const end = Math.min(src.length, at2 + MAX_FN_SOURCE);
|
|
115977
|
+
const node2 = parseExpressionAt2(src.slice(0, end), at2, { ecmaVersion: "latest" });
|
|
115978
|
+
if (node2.type !== "FunctionExpression") return void 0;
|
|
115979
|
+
return src.slice(at2, node2.end);
|
|
115980
|
+
} catch {
|
|
115981
|
+
return void 0;
|
|
115495
115982
|
}
|
|
115496
115983
|
}
|
|
115497
|
-
var
|
|
115498
|
-
|
|
115499
|
-
|
|
115500
|
-
|
|
115501
|
-
|
|
115502
|
-
|
|
115503
|
-
|
|
115504
|
-
while (size < this.len + n) size *= 2;
|
|
115505
|
-
const next = new Uint8Array(size);
|
|
115506
|
-
next.set(this.buf.subarray(0, this.len));
|
|
115507
|
-
this.buf = next;
|
|
115508
|
-
this.view = new DataView(next.buffer);
|
|
115509
|
-
}
|
|
115510
|
-
get length() {
|
|
115511
|
-
return this.len;
|
|
115512
|
-
}
|
|
115513
|
-
bytes() {
|
|
115514
|
-
return this.buf.slice(0, this.len);
|
|
115515
|
-
}
|
|
115516
|
-
u8(value) {
|
|
115517
|
-
checkInt(value, 0, 255, "u8");
|
|
115518
|
-
this.ensure(1);
|
|
115519
|
-
this.buf[this.len++] = value;
|
|
115520
|
-
return this;
|
|
115521
|
-
}
|
|
115522
|
-
raw(bytes) {
|
|
115523
|
-
this.ensure(bytes.length);
|
|
115524
|
-
this.buf.set(bytes, this.len);
|
|
115525
|
-
this.len += bytes.length;
|
|
115526
|
-
return this;
|
|
115527
|
-
}
|
|
115528
|
-
bool(value) {
|
|
115529
|
-
return this.u8(value ? 1 : 0);
|
|
115530
|
-
}
|
|
115531
|
-
uint16(value) {
|
|
115532
|
-
checkInt(value, 0, 65535, "uint16");
|
|
115533
|
-
this.ensure(2);
|
|
115534
|
-
this.view.setUint16(this.len, value, true);
|
|
115535
|
-
this.len += 2;
|
|
115536
|
-
return this;
|
|
115537
|
-
}
|
|
115538
|
-
int16(value) {
|
|
115539
|
-
checkInt(value, -32768, 32767, "int16");
|
|
115540
|
-
this.ensure(2);
|
|
115541
|
-
this.view.setInt16(this.len, value, true);
|
|
115542
|
-
this.len += 2;
|
|
115543
|
-
return this;
|
|
115544
|
-
}
|
|
115545
|
-
int32(value) {
|
|
115546
|
-
checkInt(value, -2147483648, 2147483647, "int32");
|
|
115547
|
-
this.ensure(4);
|
|
115548
|
-
this.view.setInt32(this.len, value, true);
|
|
115549
|
-
this.len += 4;
|
|
115550
|
-
return this;
|
|
115551
|
-
}
|
|
115552
|
-
int64(value) {
|
|
115553
|
-
if (typeof value === "number") checkInt(value, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, "int64");
|
|
115554
|
-
const big = BigInt(value);
|
|
115555
|
-
if (big < -(1n << 63n) || big >= 1n << 63n) throw new ProtocolError3("out-of-range", `int64 out of range: ${big}`);
|
|
115556
|
-
this.ensure(8);
|
|
115557
|
-
this.view.setBigInt64(this.len, big, true);
|
|
115558
|
-
this.len += 8;
|
|
115559
|
-
return this;
|
|
115560
|
-
}
|
|
115561
|
-
float32(value) {
|
|
115562
|
-
this.ensure(4);
|
|
115563
|
-
this.view.setFloat32(this.len, value, true);
|
|
115564
|
-
this.len += 4;
|
|
115565
|
-
return this;
|
|
115566
|
-
}
|
|
115567
|
-
float64(value) {
|
|
115568
|
-
this.ensure(8);
|
|
115569
|
-
this.view.setFloat64(this.len, value, true);
|
|
115570
|
-
this.len += 8;
|
|
115571
|
-
return this;
|
|
115572
|
-
}
|
|
115573
|
-
varint(value) {
|
|
115574
|
-
checkInt(value, 0, 4294967295, "varint");
|
|
115575
|
-
let n = value;
|
|
115576
|
-
for (; ; ) {
|
|
115577
|
-
const low = n % 128;
|
|
115578
|
-
n = Math.floor(n / 128);
|
|
115579
|
-
this.u8(n > 0 ? low | 128 : low);
|
|
115580
|
-
if (n === 0) return this;
|
|
115581
|
-
}
|
|
115582
|
-
}
|
|
115583
|
-
/** A nullable string: present flag, varint byte length, UTF-8. */
|
|
115584
|
-
string(value) {
|
|
115585
|
-
if (value === null) return this.bool(false);
|
|
115586
|
-
const encoded = utf8Encoder.encode(value);
|
|
115587
|
-
return this.bool(true).varint(encoded.length).raw(encoded);
|
|
115588
|
-
}
|
|
115589
|
-
/** A datetime; null is the "no date" sentinel. */
|
|
115590
|
-
date(value) {
|
|
115591
|
-
if (value === null) return this.float64(NO_DATE_SENTINEL);
|
|
115592
|
-
const ms = value.getTime();
|
|
115593
|
-
if (Number.isNaN(ms)) throw new ProtocolError3("out-of-range", "invalid Date");
|
|
115594
|
-
if (ms >= MAX_DATE.getTime()) return this.float64(MAX_DATE_SENTINEL);
|
|
115595
|
-
return this.float64(ms - DATE_EPOCH_MS);
|
|
115596
|
-
}
|
|
115597
|
-
/** A GUID from its 32-hex-digit form (dashes allowed), written in .NET byte order. */
|
|
115598
|
-
guid(value) {
|
|
115599
|
-
const hex3 = value.replace(/-/g, "");
|
|
115600
|
-
if (!/^[0-9a-fA-F]{32}$/.test(hex3)) throw new ProtocolError3("out-of-range", `not a guid: ${value}`);
|
|
115601
|
-
const canonical = Array.from({ length: 16 }, (_, i2) => parseInt(hex3.slice(i2 * 2, i2 * 2 + 2), 16));
|
|
115602
|
-
const out = new Uint8Array(16);
|
|
115603
|
-
GUID_ORDER.forEach((src, i2) => {
|
|
115604
|
-
out[src] = canonical[i2];
|
|
115605
|
-
});
|
|
115606
|
-
return this.raw(out);
|
|
115607
|
-
}
|
|
115608
|
-
/** A nullable list: int32 count (-1 = null), then each item. */
|
|
115609
|
-
list(items, writeItem) {
|
|
115610
|
-
if (items === null) return this.int32(-1);
|
|
115611
|
-
this.int32(items.length);
|
|
115612
|
-
for (const item of items) writeItem(this, item);
|
|
115613
|
-
return this;
|
|
115614
|
-
}
|
|
115615
|
-
/** A nullable dict: int32 count (-1 = null), then key, value pairs. */
|
|
115616
|
-
dict(entries2, writeKey, writeValue) {
|
|
115617
|
-
if (entries2 === null) return this.int32(-1);
|
|
115618
|
-
this.int32(entries2.size);
|
|
115619
|
-
for (const [k, v] of entries2) {
|
|
115620
|
-
writeKey(this, k);
|
|
115621
|
-
writeValue(this, v);
|
|
115622
|
-
}
|
|
115623
|
-
return this;
|
|
115624
|
-
}
|
|
115625
|
-
};
|
|
115626
|
-
var Reader = class {
|
|
115627
|
-
constructor(buf, offset2 = 0) {
|
|
115628
|
-
this.buf = buf;
|
|
115629
|
-
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
115630
|
-
this.pos = offset2;
|
|
115631
|
-
}
|
|
115632
|
-
buf;
|
|
115633
|
-
view;
|
|
115634
|
-
pos;
|
|
115635
|
-
get position() {
|
|
115636
|
-
return this.pos;
|
|
115637
|
-
}
|
|
115638
|
-
get remaining() {
|
|
115639
|
-
return this.buf.length - this.pos;
|
|
115640
|
-
}
|
|
115641
|
-
need(n) {
|
|
115642
|
-
if (this.pos + n > this.buf.length) {
|
|
115643
|
-
throw new ProtocolError3("truncated", `read past end: need ${n} byte(s) at offset ${this.pos} of ${this.buf.length}`);
|
|
115644
|
-
}
|
|
115984
|
+
var esc2 = (s) => s.replace(/\$/g, "\\$");
|
|
115985
|
+
function staticsOf(src, cls) {
|
|
115986
|
+
const out = /* @__PURE__ */ new Map();
|
|
115987
|
+
for (const m of src.matchAll(new RegExp(`(?<![\\w$.])${esc2(cls)}\\.([\\w$]+)\\s*=\\s*(?=function\\b)`, "g"))) {
|
|
115988
|
+
if (out.has(m[1])) continue;
|
|
115989
|
+
const fn = functionAt(src, m.index + m[0].length);
|
|
115990
|
+
if (fn) out.set(m[1], fn);
|
|
115645
115991
|
}
|
|
115646
|
-
|
|
115647
|
-
|
|
115648
|
-
|
|
115992
|
+
return out;
|
|
115993
|
+
}
|
|
115994
|
+
function prototypeOf(src, cls) {
|
|
115995
|
+
const out = /* @__PURE__ */ new Map();
|
|
115996
|
+
const m = new RegExp(`(?<![\\w$.])${esc2(cls)}\\.prototype\\s*=\\s*`).exec(src);
|
|
115997
|
+
if (!m) return out;
|
|
115998
|
+
let at2 = m.index + m[0].length;
|
|
115999
|
+
if (src[at2] !== "{") {
|
|
116000
|
+
const brace = src.indexOf("{", at2);
|
|
116001
|
+
if (brace < 0 || brace - at2 > 200) return out;
|
|
116002
|
+
at2 = brace;
|
|
115649
116003
|
}
|
|
115650
|
-
|
|
115651
|
-
|
|
115652
|
-
|
|
115653
|
-
|
|
115654
|
-
*/
|
|
115655
|
-
raw(n) {
|
|
115656
|
-
if (!Number.isInteger(n) || n < 0) {
|
|
115657
|
-
throw new ProtocolError3("bad-length", `bad byte count ${n} at offset ${this.pos}`);
|
|
115658
|
-
}
|
|
115659
|
-
this.need(n);
|
|
115660
|
-
const out = this.buf.slice(this.pos, this.pos + n);
|
|
115661
|
-
this.pos += n;
|
|
116004
|
+
let obj;
|
|
116005
|
+
try {
|
|
116006
|
+
obj = parseExpressionAt2(src, at2, { ecmaVersion: "latest" });
|
|
116007
|
+
} catch {
|
|
115662
116008
|
return out;
|
|
115663
116009
|
}
|
|
115664
|
-
|
|
115665
|
-
|
|
115666
|
-
if (
|
|
115667
|
-
|
|
115668
|
-
|
|
115669
|
-
uint16() {
|
|
115670
|
-
this.need(2);
|
|
115671
|
-
const v = this.view.getUint16(this.pos, true);
|
|
115672
|
-
this.pos += 2;
|
|
115673
|
-
return v;
|
|
115674
|
-
}
|
|
115675
|
-
int16() {
|
|
115676
|
-
this.need(2);
|
|
115677
|
-
const v = this.view.getInt16(this.pos, true);
|
|
115678
|
-
this.pos += 2;
|
|
115679
|
-
return v;
|
|
115680
|
-
}
|
|
115681
|
-
int32() {
|
|
115682
|
-
this.need(4);
|
|
115683
|
-
const v = this.view.getInt32(this.pos, true);
|
|
115684
|
-
this.pos += 4;
|
|
115685
|
-
return v;
|
|
115686
|
-
}
|
|
115687
|
-
/** An int64 as a number (exact up to 2^53). */
|
|
115688
|
-
int64() {
|
|
115689
|
-
this.need(8);
|
|
115690
|
-
const v = this.view.getBigInt64(this.pos, true);
|
|
115691
|
-
this.pos += 8;
|
|
115692
|
-
return Number(v);
|
|
115693
|
-
}
|
|
115694
|
-
float32() {
|
|
115695
|
-
this.need(4);
|
|
115696
|
-
const v = this.view.getFloat32(this.pos, true);
|
|
115697
|
-
this.pos += 4;
|
|
115698
|
-
return v;
|
|
115699
|
-
}
|
|
115700
|
-
float64() {
|
|
115701
|
-
this.need(8);
|
|
115702
|
-
const v = this.view.getFloat64(this.pos, true);
|
|
115703
|
-
this.pos += 8;
|
|
115704
|
-
return v;
|
|
116010
|
+
if (obj.type !== "ObjectExpression") return out;
|
|
116011
|
+
for (const p of obj.properties ?? []) {
|
|
116012
|
+
if (p.type !== "Property" || p.key.type !== "Identifier" || !p.key.name) continue;
|
|
116013
|
+
if (p.value.type !== "FunctionExpression" || p.value.end - p.value.start > MAX_FN_SOURCE) continue;
|
|
116014
|
+
out.set(p.key.name, src.slice(p.value.start, p.value.end));
|
|
115705
116015
|
}
|
|
115706
|
-
|
|
115707
|
-
|
|
115708
|
-
|
|
115709
|
-
|
|
115710
|
-
|
|
115711
|
-
|
|
115712
|
-
|
|
115713
|
-
|
|
116016
|
+
return out;
|
|
116017
|
+
}
|
|
116018
|
+
function inputRoles(methods) {
|
|
116019
|
+
const roles = /* @__PURE__ */ new Map();
|
|
116020
|
+
let readByte;
|
|
116021
|
+
for (const [name, fn] of methods) {
|
|
116022
|
+
if (/methodName\s*:\s*"readByte"/.test(fn)) readByte = name;
|
|
116023
|
+
}
|
|
116024
|
+
if (!readByte) return roles;
|
|
116025
|
+
roles.set(readByte, "readByte");
|
|
116026
|
+
const calls = (fn, name) => fn.split(`this.${name}(`).length - 1;
|
|
116027
|
+
let readInt32;
|
|
116028
|
+
for (const [name, fn] of methods) {
|
|
116029
|
+
if (name === readByte) continue;
|
|
116030
|
+
const bytes = calls(fn, readByte);
|
|
116031
|
+
if (bytes === 4 && fn.includes("<<24")) {
|
|
116032
|
+
readInt32 = name;
|
|
116033
|
+
roles.set(name, "readInt32");
|
|
116034
|
+
} else if (bytes === 2 && fn.includes("32768")) roles.set(name, "readInt16");
|
|
116035
|
+
else if (bytes === 2) roles.set(name, "readUInt16");
|
|
116036
|
+
}
|
|
116037
|
+
if (readInt32) {
|
|
116038
|
+
for (const [name, fn] of methods) {
|
|
116039
|
+
if (roles.has(name)) continue;
|
|
116040
|
+
const ints3 = calls(fn, readInt32);
|
|
116041
|
+
if (ints3 === 2) roles.set(name, "readDouble");
|
|
116042
|
+
else if (ints3 === 1) roles.set(name, "readFloat");
|
|
116043
|
+
}
|
|
116044
|
+
}
|
|
116045
|
+
return roles;
|
|
116046
|
+
}
|
|
116047
|
+
var FROM_INPUT = {
|
|
116048
|
+
readByte: "u8",
|
|
116049
|
+
readInt32: "int32",
|
|
116050
|
+
readInt16: "int16",
|
|
116051
|
+
readUInt16: "uint16",
|
|
116052
|
+
readFloat: "float32",
|
|
116053
|
+
readDouble: "float64"
|
|
116054
|
+
};
|
|
116055
|
+
function readerRoles(methods, input2) {
|
|
116056
|
+
const roles = /* @__PURE__ */ new Map();
|
|
116057
|
+
for (const [name, fn] of methods) {
|
|
116058
|
+
if (fn.includes('"Bad format"') && /&127\)<</.test(fn)) roles.set(name, "varint");
|
|
116059
|
+
else if (/new [\w$]+\(new ArrayBuffer\(/.test(fn)) roles.set(name, "raw");
|
|
116060
|
+
else if (fn.includes("4294967296")) continue;
|
|
116061
|
+
else {
|
|
116062
|
+
const bool2 = /return\s*0\s*!=\s*this\.[\w$]+\.([\w$]+)\(\)/.exec(fn);
|
|
116063
|
+
if (bool2 && input2.get(bool2[1]) === "readByte") {
|
|
116064
|
+
roles.set(name, "bool");
|
|
116065
|
+
continue;
|
|
116066
|
+
}
|
|
116067
|
+
const direct = /return\s+this\.[\w$]+\.([\w$]+)\(\)/.exec(fn);
|
|
116068
|
+
const r = direct ? input2.get(direct[1]) : void 0;
|
|
116069
|
+
if (r) roles.set(name, FROM_INPUT[r]);
|
|
115714
116070
|
}
|
|
115715
|
-
throw new ProtocolError3("bad-varint", `varint longer than 5 bytes ending at offset ${this.pos}`);
|
|
115716
116071
|
}
|
|
115717
|
-
|
|
115718
|
-
|
|
115719
|
-
|
|
115720
|
-
|
|
115721
|
-
|
|
115722
|
-
|
|
115723
|
-
return
|
|
115724
|
-
} catch {
|
|
115725
|
-
throw new ProtocolError3("bad-string", `invalid UTF-8 in string at offset ${start}`);
|
|
116072
|
+
for (let pass = 0; pass < 3; pass++) {
|
|
116073
|
+
for (const [name, fn] of methods) {
|
|
116074
|
+
if (roles.has(name)) continue;
|
|
116075
|
+
const own2 = [...fn.matchAll(/this\.([\w$]+)\(/g)].map((m) => m[1]).filter((n) => methods.has(n));
|
|
116076
|
+
const ownRoles = own2.map((n) => roles.get(n));
|
|
116077
|
+
if (ownRoles.includes("varint") && ownRoles.includes("raw")) roles.set(name, "string");
|
|
116078
|
+
else if (own2.length === 1 && ownRoles[0] && /^function\(\)\{try\{return this\.[\w$]+\(\)\}/.test(fn)) roles.set(name, ownRoles[0]);
|
|
115726
116079
|
}
|
|
115727
116080
|
}
|
|
115728
|
-
|
|
115729
|
-
|
|
115730
|
-
|
|
115731
|
-
|
|
115732
|
-
|
|
115733
|
-
|
|
115734
|
-
|
|
115735
|
-
/** A GUID as 32 lowercase hex digits in canonical order. */
|
|
115736
|
-
guid() {
|
|
115737
|
-
const b = this.raw(16);
|
|
115738
|
-
return GUID_ORDER.map((i2) => b[i2].toString(16).padStart(2, "0")).join("");
|
|
116081
|
+
return roles;
|
|
116082
|
+
}
|
|
116083
|
+
function bundleProtocol(src) {
|
|
116084
|
+
const counts = /* @__PURE__ */ new Map();
|
|
116085
|
+
for (const m of src.matchAll(/null==([a-z])&&\(\1=(\d{3})\)/g)) {
|
|
116086
|
+
const v = Number(m[2]);
|
|
116087
|
+
counts.set(v, (counts.get(v) ?? 0) + 1);
|
|
115739
116088
|
}
|
|
115740
|
-
|
|
115741
|
-
|
|
115742
|
-
|
|
115743
|
-
if (
|
|
115744
|
-
|
|
115745
|
-
|
|
115746
|
-
|
|
116089
|
+
let best;
|
|
116090
|
+
let n = 0;
|
|
116091
|
+
for (const [v, c] of counts) {
|
|
116092
|
+
if (c > n) {
|
|
116093
|
+
best = v;
|
|
116094
|
+
n = c;
|
|
116095
|
+
}
|
|
116096
|
+
}
|
|
116097
|
+
return n >= 3 ? best : void 0;
|
|
116098
|
+
}
|
|
116099
|
+
function deriveDialect(bundle) {
|
|
116100
|
+
const { src, typeNameOf, varOf } = bundle;
|
|
116101
|
+
const inputVar = varOf.get(INPUT_TYPE);
|
|
116102
|
+
const readerVar = varOf.get(READER_TYPE);
|
|
116103
|
+
const serializer = varOf.get(SERIALIZER_TYPE);
|
|
116104
|
+
if (!inputVar || !readerVar || !serializer) return null;
|
|
116105
|
+
const input2 = inputRoles(prototypeOf(src, inputVar));
|
|
116106
|
+
const reader2 = readerRoles(prototypeOf(src, readerVar), input2);
|
|
116107
|
+
const readerMethods = {};
|
|
116108
|
+
for (const [n, r] of reader2) readerMethods[n] = r;
|
|
116109
|
+
const found = new Set(reader2.values());
|
|
116110
|
+
if (!REQUIRED_READER_ROLES.every((r) => found.has(r))) return null;
|
|
116111
|
+
const roleOf = (n) => reader2.get(n);
|
|
116112
|
+
const typeOf2 = (n) => typeNameOf.get(n);
|
|
116113
|
+
const canon = (fn) => canonicalize(fn, roleOf, typeOf2);
|
|
116114
|
+
const statics = {};
|
|
116115
|
+
const put = (cls, name, role) => {
|
|
116116
|
+
(statics[cls] ??= {})[name] = role;
|
|
116117
|
+
};
|
|
116118
|
+
const utility = varOf.get(UTILITY_TYPE);
|
|
116119
|
+
const utilityStatics = utility ? staticsOf(src, utility) : /* @__PURE__ */ new Map();
|
|
116120
|
+
const utilityRole = (name) => {
|
|
116121
|
+
const fn = utilityStatics.get(name);
|
|
116122
|
+
if (!fn) return void 0;
|
|
116123
|
+
if (/@raw \( 16 \)/.test(canon(fn)) || /\(16\)/.test(fn)) return "guid";
|
|
116124
|
+
if (canon(fn).includes("@float64")) return "date";
|
|
116125
|
+
return void 0;
|
|
116126
|
+
};
|
|
116127
|
+
for (const [name, fn] of staticsOf(src, serializer)) {
|
|
116128
|
+
const c = canon(fn);
|
|
116129
|
+
const role = SERIALIZER_TEMPLATES[c];
|
|
116130
|
+
if (role) put(serializer, name, role);
|
|
116131
|
+
else if (COLLECTION_LIST.test(c)) put(serializer, name, "list");
|
|
116132
|
+
else if (c === UTILITY_CALL) {
|
|
116133
|
+
const callee = /return [\w$]+\.([\w$]+)\(/.exec(fn)?.[1];
|
|
116134
|
+
const r = callee ? utilityRole(callee) : void 0;
|
|
116135
|
+
if (r) put(serializer, name, r);
|
|
115747
116136
|
}
|
|
115748
|
-
return n;
|
|
115749
116137
|
}
|
|
115750
|
-
|
|
115751
|
-
|
|
115752
|
-
|
|
115753
|
-
|
|
115754
|
-
|
|
115755
|
-
`count ${n} at offset ${at2} of items that take no bytes (at most ${MAX_EMPTY_ITEMS})`
|
|
115756
|
-
);
|
|
116138
|
+
const roles = new Set(Object.values(statics[serializer] ?? {}));
|
|
116139
|
+
if (!REQUIRED_STATIC_ROLES.every((r) => roles.has(r))) return null;
|
|
116140
|
+
if (utility) {
|
|
116141
|
+
for (const [name, fn] of utilityStatics) {
|
|
116142
|
+
if (fn.includes(UTILITY_IDENTITY_MARK) || UTILITY_TRY_GET.test(canon(fn))) put(utility, name, "identity");
|
|
115757
116143
|
}
|
|
115758
116144
|
}
|
|
115759
|
-
|
|
115760
|
-
|
|
115761
|
-
const
|
|
115762
|
-
if (n === null) return null;
|
|
115763
|
-
const out = [];
|
|
115764
|
-
for (let i2 = 0; i2 < n; i2++) {
|
|
115765
|
-
const before = this.pos;
|
|
115766
|
-
out.push(readItem(this));
|
|
115767
|
-
this.checkItemSize(n, before, at2);
|
|
115768
|
-
}
|
|
115769
|
-
return out;
|
|
116145
|
+
const pump = varOf.get(PUMP_TYPE);
|
|
116146
|
+
if (pump) {
|
|
116147
|
+
for (const [name, fn] of staticsOf(src, pump)) if (canon(fn) === IDENTITY) put(pump, name, "identity");
|
|
115770
116148
|
}
|
|
115771
|
-
|
|
115772
|
-
|
|
115773
|
-
const
|
|
115774
|
-
|
|
115775
|
-
|
|
115776
|
-
|
|
115777
|
-
|
|
115778
|
-
|
|
115779
|
-
|
|
115780
|
-
this.checkItemSize(n, before, at2);
|
|
116149
|
+
const enumerable = varOf.get(ENUMERABLE_TYPE);
|
|
116150
|
+
if (enumerable) {
|
|
116151
|
+
for (const [name, fn] of staticsOf(src, enumerable)) {
|
|
116152
|
+
if (name === "Range") put(enumerable, name, "range");
|
|
116153
|
+
else {
|
|
116154
|
+
const c = canon(fn);
|
|
116155
|
+
if (c === SELECT) put(enumerable, name, "select");
|
|
116156
|
+
else if (c === TO_ARRAY) put(enumerable, name, "toArray");
|
|
116157
|
+
}
|
|
115781
116158
|
}
|
|
115782
|
-
return out;
|
|
115783
|
-
}
|
|
115784
|
-
};
|
|
115785
|
-
function writeHeader(w, h) {
|
|
115786
|
-
w.uint16(h.version & 32767 | (h.reply ? REPLY_FLAG : 0)).int32(PREAMBLE).int32(h.msgNum).int32(h.method);
|
|
115787
|
-
}
|
|
115788
|
-
function readHeader(r) {
|
|
115789
|
-
const flags = r.uint16();
|
|
115790
|
-
const preamble = r.int32();
|
|
115791
|
-
if (preamble !== PREAMBLE) {
|
|
115792
|
-
throw new ProtocolError3("bad-preamble", `bad preamble ${preamble} (expected ${PREAMBLE})`);
|
|
115793
|
-
}
|
|
115794
|
-
return { version: flags & 32767, reply: (flags & REPLY_FLAG) !== 0, msgNum: r.int32(), method: r.int32() };
|
|
115795
|
-
}
|
|
115796
|
-
var writeIntStringDict = (w, d) => {
|
|
115797
|
-
if (d === null) {
|
|
115798
|
-
w.bool(false);
|
|
115799
|
-
return;
|
|
115800
|
-
}
|
|
115801
|
-
w.bool(true).dict(
|
|
115802
|
-
d,
|
|
115803
|
-
(ww, k) => ww.int32(k),
|
|
115804
|
-
(ww, v) => ww.string(v)
|
|
115805
|
-
);
|
|
115806
|
-
};
|
|
115807
|
-
var readIntStringDict = (r) => r.bool() ? r.dict(
|
|
115808
|
-
(rr) => rr.int32(),
|
|
115809
|
-
(rr) => rr.string()
|
|
115810
|
-
) : null;
|
|
115811
|
-
function writeExtrasUp(w, e) {
|
|
115812
|
-
writeIntStringDict(w, e.dict);
|
|
115813
|
-
w.string(e.client).int32(e.serverInfoVersionA).int32(e.serverInfoVersionB).date(e.fDb).date(e.kFa).int32(e.platform);
|
|
115814
|
-
}
|
|
115815
|
-
function readExtrasUp(r) {
|
|
115816
|
-
const dict = readIntStringDict(r);
|
|
115817
|
-
return {
|
|
115818
|
-
dict: dict === null ? null : new Map([...dict].map(([k, v]) => [k, v ?? ""])),
|
|
115819
|
-
client: r.string(),
|
|
115820
|
-
serverInfoVersionA: r.int32(),
|
|
115821
|
-
serverInfoVersionB: r.int32(),
|
|
115822
|
-
fDb: r.date(),
|
|
115823
|
-
kFa: r.date(),
|
|
115824
|
-
platform: r.int32()
|
|
115825
|
-
};
|
|
115826
|
-
}
|
|
115827
|
-
function optional4(r, read) {
|
|
115828
|
-
return r.bool() ? read(r) : null;
|
|
115829
|
-
}
|
|
115830
|
-
function readExtrasDown(r) {
|
|
115831
|
-
return {
|
|
115832
|
-
cAa: readIntStringDict(r),
|
|
115833
|
-
wca: optional4(r, (rr) => rr.int32()),
|
|
115834
|
-
c2a: r.string(),
|
|
115835
|
-
serverInfo: optional4(r, (rr) => ({
|
|
115836
|
-
okb: rr.string(),
|
|
115837
|
-
lbFlags: rr.string(),
|
|
115838
|
-
serverInfoVersionA: rr.int32(),
|
|
115839
|
-
livestream: optional4(rr, (l) => ({
|
|
115840
|
-
j7: l.string(),
|
|
115841
|
-
jdb: l.int32(),
|
|
115842
|
-
lr: l.date(),
|
|
115843
|
-
zfd: l.string(),
|
|
115844
|
-
yfd: l.string()
|
|
115845
|
-
})),
|
|
115846
|
-
serverInfoVersionB: rr.int32()
|
|
115847
|
-
})),
|
|
115848
|
-
j9: optional4(
|
|
115849
|
-
r,
|
|
115850
|
-
(rr) => rr.dict(
|
|
115851
|
-
(k) => k.int32(),
|
|
115852
|
-
(v) => optional4(v, (vv) => vv.list((s) => s.string()))
|
|
115853
|
-
)
|
|
115854
|
-
),
|
|
115855
|
-
unreadMail: optional4(r, (rr) => ({ cYa: rr.bool(), kFa: rr.date(), h9: rr.bool() }))
|
|
115856
|
-
};
|
|
115857
|
-
}
|
|
115858
|
-
var AUTH_TAG = 4;
|
|
115859
|
-
function encodeRequest(frame) {
|
|
115860
|
-
const w = new Writer();
|
|
115861
|
-
writeHeader(w, {
|
|
115862
|
-
version: frame.version ?? PROTOCOL_VERSION,
|
|
115863
|
-
reply: false,
|
|
115864
|
-
msgNum: frame.msgNum,
|
|
115865
|
-
method: frame.method
|
|
115866
|
-
});
|
|
115867
|
-
writeExtrasUp(w, frame.extras);
|
|
115868
|
-
if (frame.email !== null) w.bool(true).u8(AUTH_TAG).string(frame.email);
|
|
115869
|
-
frame.params?.(w);
|
|
115870
|
-
return w.bytes();
|
|
115871
|
-
}
|
|
115872
|
-
function decodeReplyEnvelope(bytes) {
|
|
115873
|
-
const r = new Reader(bytes);
|
|
115874
|
-
const header = readHeader(r);
|
|
115875
|
-
if (!header.reply) throw new ProtocolError3("not-a-reply", `frame for method ${header.method} is not a reply`);
|
|
115876
|
-
const env = { version: header.version, method: header.method, msgNum: header.msgNum, body: r };
|
|
115877
|
-
if (r.u8() === EXTRAS_PRESENT) env.extrasDown = readExtrasDown(r);
|
|
115878
|
-
if (r.u8() === ERROR_KIND) env.error = { code: r.int32(), message: r.string() };
|
|
115879
|
-
return env;
|
|
115880
|
-
}
|
|
115881
|
-
function toHex(bytes) {
|
|
115882
|
-
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
115883
|
-
}
|
|
115884
|
-
function fromHex(hex3) {
|
|
115885
|
-
const clean2 = hex3.trim();
|
|
115886
|
-
if (clean2.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(clean2)) {
|
|
115887
|
-
throw new ProtocolError3("bad-length", "not an even-length hex string");
|
|
115888
116159
|
}
|
|
115889
|
-
const
|
|
115890
|
-
|
|
115891
|
-
return out;
|
|
116160
|
+
const wrappers = WRAPPER_TYPES.map((t) => varOf.get(t)).filter((v) => v !== void 0);
|
|
116161
|
+
return { readerMethods, statics, wrappers, serializer, protocol: bundleProtocol(src) };
|
|
115892
116162
|
}
|
|
115893
116163
|
|
|
115894
116164
|
// src/protocol/interp.ts
|
|
@@ -115956,61 +116226,100 @@ function list2(r, item) {
|
|
|
115956
116226
|
const f = callback(item);
|
|
115957
116227
|
return asReader(r).list(() => f());
|
|
115958
116228
|
}
|
|
115959
|
-
var
|
|
116229
|
+
var READER_NATIVES = {
|
|
116230
|
+
bool: (r) => r.bool(),
|
|
116231
|
+
int32: (r) => r.int32(),
|
|
116232
|
+
u8: (r) => r.u8(),
|
|
116233
|
+
string: (r) => strBody(r),
|
|
116234
|
+
// The client's 8-byte read is a float64 (its two int32 halves reassembled as a double), not an
|
|
116235
|
+
// int64: kill rates, luck and TimeSpans (milliseconds) all arrive through it.
|
|
116236
|
+
float64: (r) => r.float64(),
|
|
116237
|
+
float32: (r) => r.float32(),
|
|
116238
|
+
uint16: (r) => r.uint16(),
|
|
116239
|
+
int16: (r) => r.int16(),
|
|
116240
|
+
raw: (r, n) => {
|
|
116241
|
+
if (typeof n !== "number" || !Number.isInteger(n) || n < 0) throw new InterpError("bad-value", `bad byte count ${String(n)}`);
|
|
116242
|
+
return r.raw(n);
|
|
116243
|
+
},
|
|
116244
|
+
varint: (r) => r.varint()
|
|
116245
|
+
};
|
|
116246
|
+
var STATIC_NATIVES = {
|
|
116247
|
+
int32: (r) => asReader(r).int32(),
|
|
116248
|
+
string: (r) => asReader(r).string(),
|
|
116249
|
+
bool: (r) => asReader(r).bool(),
|
|
116250
|
+
u8: (r) => asReader(r).u8(),
|
|
116251
|
+
float32: (r) => asReader(r).float32(),
|
|
116252
|
+
float64: (r) => asReader(r).float64(),
|
|
116253
|
+
timespan: (r) => asReader(r).float64(),
|
|
116254
|
+
date: (r) => asReader(r).date(),
|
|
116255
|
+
guid: (r) => asReader(r).guid(),
|
|
116256
|
+
uint16: (r) => asReader(r).uint16(),
|
|
116257
|
+
bytes: (r) => readBytes(asReader(r)),
|
|
116258
|
+
list: list2,
|
|
116259
|
+
dict: (r, k, v) => {
|
|
116260
|
+
const fk = callback(k);
|
|
116261
|
+
const fv = callback(v);
|
|
116262
|
+
return asReader(r).list(() => [fk(), fv()]);
|
|
116263
|
+
},
|
|
116264
|
+
identity: (x) => x,
|
|
116265
|
+
// Enumerable helpers (special-unit lists): Range → Select → ToArray.
|
|
116266
|
+
range,
|
|
116267
|
+
select: (xs, f) => {
|
|
116268
|
+
const fn = callback(f);
|
|
116269
|
+
return asArray(xs).map((x) => fn(x));
|
|
116270
|
+
},
|
|
116271
|
+
toArray: (xs) => [...asArray(xs)]
|
|
116272
|
+
};
|
|
116273
|
+
function dialectFrom(names2) {
|
|
116274
|
+
const readerMethods = {};
|
|
116275
|
+
for (const [n, role] of Object.entries(names2.readerMethods)) readerMethods[n] = READER_NATIVES[role];
|
|
116276
|
+
const statics = {};
|
|
116277
|
+
for (const [cls, fns] of Object.entries(names2.statics)) {
|
|
116278
|
+
statics[cls] = {};
|
|
116279
|
+
for (const [n, role] of Object.entries(fns)) statics[cls][n] = STATIC_NATIVES[role];
|
|
116280
|
+
}
|
|
116281
|
+
return { readerMethods, statics, wrappers: [...names2.wrappers] };
|
|
116282
|
+
}
|
|
116283
|
+
var V607_NAMES = {
|
|
115960
116284
|
readerMethods: {
|
|
115961
|
-
Ua:
|
|
115962
|
-
Og:
|
|
115963
|
-
bc:
|
|
115964
|
-
FJ:
|
|
115965
|
-
|
|
115966
|
-
|
|
115967
|
-
|
|
115968
|
-
|
|
115969
|
-
|
|
115970
|
-
|
|
115971
|
-
|
|
115972
|
-
JS: (r, n) => {
|
|
115973
|
-
if (typeof n !== "number" || !Number.isInteger(n) || n < 0) throw new InterpError("bad-value", `bad byte count ${String(n)}`);
|
|
115974
|
-
return r.raw(n);
|
|
115975
|
-
},
|
|
115976
|
-
I3c: (r) => r.varint()
|
|
116285
|
+
Ua: "bool",
|
|
116286
|
+
Og: "int32",
|
|
116287
|
+
bc: "u8",
|
|
116288
|
+
FJ: "string",
|
|
116289
|
+
E3a: "float64",
|
|
116290
|
+
Om: "float32",
|
|
116291
|
+
NGb: "uint16",
|
|
116292
|
+
S3c: "int16",
|
|
116293
|
+
MGb: "u8",
|
|
116294
|
+
JS: "raw",
|
|
116295
|
+
I3c: "varint"
|
|
115977
116296
|
},
|
|
115978
116297
|
statics: {
|
|
115979
116298
|
P: {
|
|
115980
|
-
Ya:
|
|
115981
|
-
wc:
|
|
115982
|
-
Yc:
|
|
115983
|
-
uq:
|
|
115984
|
-
Ao:
|
|
115985
|
-
ak:
|
|
115986
|
-
uy:
|
|
115987
|
-
Td:
|
|
115988
|
-
tL:
|
|
115989
|
-
Z5:
|
|
115990
|
-
sL:
|
|
115991
|
-
Sd:
|
|
115992
|
-
ms:
|
|
115993
|
-
uL:
|
|
115994
|
-
ef:
|
|
115995
|
-
const fk = callback(k);
|
|
115996
|
-
const fv = callback(v);
|
|
115997
|
-
return asReader(r).list(() => [fk(), fv()]);
|
|
115998
|
-
}
|
|
116299
|
+
Ya: "int32",
|
|
116300
|
+
wc: "string",
|
|
116301
|
+
Yc: "bool",
|
|
116302
|
+
uq: "u8",
|
|
116303
|
+
Ao: "float32",
|
|
116304
|
+
ak: "float64",
|
|
116305
|
+
uy: "timespan",
|
|
116306
|
+
Td: "date",
|
|
116307
|
+
tL: "guid",
|
|
116308
|
+
Z5: "uint16",
|
|
116309
|
+
sL: "bytes",
|
|
116310
|
+
Sd: "list",
|
|
116311
|
+
ms: "list",
|
|
116312
|
+
uL: "list",
|
|
116313
|
+
ef: "dict"
|
|
115999
116314
|
},
|
|
116000
|
-
O: { fA:
|
|
116001
|
-
za: { rc:
|
|
116002
|
-
|
|
116003
|
-
E: {
|
|
116004
|
-
Range: range,
|
|
116005
|
-
Za: (xs, f) => {
|
|
116006
|
-
const fn = callback(f);
|
|
116007
|
-
return asArray(xs).map((x) => fn(x));
|
|
116008
|
-
},
|
|
116009
|
-
Sa: (xs) => [...asArray(xs)]
|
|
116010
|
-
}
|
|
116315
|
+
O: { fA: "identity", Fy: "identity", rc: "identity" },
|
|
116316
|
+
za: { rc: "identity" },
|
|
116317
|
+
E: { Range: "range", Za: "select", Sa: "toArray" }
|
|
116011
116318
|
},
|
|
116012
116319
|
wrappers: ["Z", "Yb", "uc", "dc", "oc", "ec", "fc"]
|
|
116013
116320
|
};
|
|
116321
|
+
var DEFAULT_DIALECT = dialectFrom(V607_NAMES);
|
|
116322
|
+
var REQUIRED_ROLES = ["int32", "bool", "u8"];
|
|
116014
116323
|
var READER_HELPERS = "P";
|
|
116015
116324
|
var REQUIRED_HELPERS = ["Ya", "Yc", "uq"];
|
|
116016
116325
|
var MAX_LITERAL_SITES = 16;
|
|
@@ -116179,18 +116488,39 @@ var BundleInterpreter = class {
|
|
|
116179
116488
|
this.maxDepth = opts.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
116180
116489
|
this.maxMillis = opts.maxMillis ?? DEFAULT_MAX_MILLIS;
|
|
116181
116490
|
this.now = opts.now ?? (() => performance.now());
|
|
116182
|
-
const
|
|
116183
|
-
|
|
116184
|
-
|
|
116185
|
-
|
|
116186
|
-
|
|
116187
|
-
|
|
116491
|
+
const derived2 = opts.dialect ? null : deriveDialect(bundle);
|
|
116492
|
+
if (derived2) {
|
|
116493
|
+
this.dialect = dialectFrom(derived2);
|
|
116494
|
+
this.helperClass = derived2.serializer;
|
|
116495
|
+
const helpers = derived2.statics[derived2.serializer] ?? {};
|
|
116496
|
+
this.requiredHelpers = Object.keys(helpers).filter((n) => REQUIRED_ROLES.includes(helpers[n])).sort();
|
|
116497
|
+
this.derived = true;
|
|
116498
|
+
} else {
|
|
116499
|
+
const d = opts.dialect ?? {};
|
|
116500
|
+
this.dialect = {
|
|
116501
|
+
readerMethods: { ...DEFAULT_DIALECT.readerMethods, ...d.readerMethods },
|
|
116502
|
+
statics: { ...DEFAULT_DIALECT.statics, ...d.statics },
|
|
116503
|
+
wrappers: d.wrappers ?? DEFAULT_DIALECT.wrappers
|
|
116504
|
+
};
|
|
116505
|
+
this.helperClass = READER_HELPERS;
|
|
116506
|
+
this.requiredHelpers = REQUIRED_HELPERS;
|
|
116507
|
+
this.derived = false;
|
|
116508
|
+
}
|
|
116509
|
+
this.bundleProtocol = derived2 ? derived2.protocol : bundleProtocol(bundle.src);
|
|
116188
116510
|
this.wrappers = new Set(this.dialect.wrappers);
|
|
116189
116511
|
}
|
|
116190
116512
|
bundle;
|
|
116191
116513
|
opts;
|
|
116192
116514
|
version;
|
|
116193
116515
|
dialect;
|
|
116516
|
+
/** The class whose statics are the reader helpers `verifyDialect` checks (the Serializer). */
|
|
116517
|
+
helperClass;
|
|
116518
|
+
/** The reader helpers that must verify for the bundle to load (int32, bool and byte, by role). */
|
|
116519
|
+
requiredHelpers;
|
|
116520
|
+
/** The dialect was derived from this bundle (false: the built-in v6.07 names). */
|
|
116521
|
+
derived;
|
|
116522
|
+
/** The protocol version the bundle's readers default to, when clear (`null==d&&(d=243)`). */
|
|
116523
|
+
bundleProtocol;
|
|
116194
116524
|
wrappers;
|
|
116195
116525
|
/** Resolved functions by `Cls.fn` / `new Cls`: a hit, `null` (no constructor) or the cached failure. */
|
|
116196
116526
|
fnCache = /* @__PURE__ */ new Map();
|
|
@@ -116267,13 +116597,13 @@ var BundleInterpreter = class {
|
|
|
116267
116597
|
verifyDialect() {
|
|
116268
116598
|
const out = { verified: [], unverified: [], mismatched: [] };
|
|
116269
116599
|
const reasons = {};
|
|
116270
|
-
const natives = Object.hasOwn(this.dialect.statics,
|
|
116600
|
+
const natives = Object.hasOwn(this.dialect.statics, this.helperClass) ? this.dialect.statics[this.helperClass] : {};
|
|
116271
116601
|
const budget = { spent: 0 };
|
|
116272
|
-
const forms = this.helperForms(
|
|
116273
|
-
const order = [...forms.keys()].sort((a, b) => Number(
|
|
116602
|
+
const forms = this.helperForms(this.helperClass, Object.keys(natives), budget);
|
|
116603
|
+
const order = [...forms.keys()].sort((a, b) => Number(this.requiredHelpers.includes(b)) - Number(this.requiredHelpers.includes(a)) || (a < b ? -1 : 1));
|
|
116274
116604
|
for (const name of order) {
|
|
116275
116605
|
const native = natives[name];
|
|
116276
|
-
const key = `${
|
|
116606
|
+
const key = `${this.helperClass}.${name}`;
|
|
116277
116607
|
let mismatch = false;
|
|
116278
116608
|
let why;
|
|
116279
116609
|
for (const form of forms.get(name)) {
|
|
@@ -116307,12 +116637,12 @@ var BundleInterpreter = class {
|
|
|
116307
116637
|
}
|
|
116308
116638
|
}
|
|
116309
116639
|
const src = this.bundle.src;
|
|
116310
|
-
const
|
|
116311
|
-
for (const name of
|
|
116640
|
+
const esc3 = this.helperClass.replace(/\$/g, "\\$");
|
|
116641
|
+
for (const name of this.requiredHelpers) {
|
|
116312
116642
|
if (forms.has(name) || !Object.hasOwn(natives, name)) continue;
|
|
116313
|
-
const ref4 = new RegExp(`(?<![\\w$.])${
|
|
116643
|
+
const ref4 = new RegExp(`(?<![\\w$.])${esc3}\\s*(?:\\.\\s*${name}(?![\\w$])|\\[\\s*(["'\`])${name}\\1\\s*\\])`);
|
|
116314
116644
|
if (!ref4.test(src)) continue;
|
|
116315
|
-
const key = `${
|
|
116645
|
+
const key = `${this.helperClass}.${name}`;
|
|
116316
116646
|
out.unverified.push(key);
|
|
116317
116647
|
reasons[key] = "the bundle reads through it, but no definition was found in a form this check can follow";
|
|
116318
116648
|
}
|
|
@@ -116343,8 +116673,8 @@ var BundleInterpreter = class {
|
|
|
116343
116673
|
}
|
|
116344
116674
|
};
|
|
116345
116675
|
const src = this.bundle.src;
|
|
116346
|
-
const
|
|
116347
|
-
for (const m of src.matchAll(new RegExp(`(?<![\\w$.])${
|
|
116676
|
+
const esc3 = cls.replace(/\$/g, "\\$");
|
|
116677
|
+
for (const m of src.matchAll(new RegExp(`(?<![\\w$.])${esc3}\\.([\\w$]+)\\s*=(?!=)\\s*`, "g"))) {
|
|
116348
116678
|
const name = m[1];
|
|
116349
116679
|
if (!wanted.has(name)) continue;
|
|
116350
116680
|
const at2 = m.index + m[0].length;
|
|
@@ -116364,7 +116694,7 @@ var BundleInterpreter = class {
|
|
|
116364
116694
|
let litText = 0;
|
|
116365
116695
|
let litSites = 0;
|
|
116366
116696
|
let cutShort = false;
|
|
116367
|
-
for (const m of src.matchAll(new RegExp(`(?<![\\w$.])${
|
|
116697
|
+
for (const m of src.matchAll(new RegExp(`(?<![\\w$.])${esc3}\\s*=\\s*(?=\\{)`, "g"))) {
|
|
116368
116698
|
const room = this.maxSteps - litText;
|
|
116369
116699
|
if (litSites >= MAX_LITERAL_SITES || room <= 0) {
|
|
116370
116700
|
cutShort = true;
|
|
@@ -117329,6 +117659,14 @@ var WarappBundle = class {
|
|
|
117329
117659
|
constructor(src, version3, opts = {}) {
|
|
117330
117660
|
this.version = version3;
|
|
117331
117661
|
this.interp = new BundleInterpreter(parseBundle(src), opts);
|
|
117662
|
+
const protocol = this.interp.bundleProtocol;
|
|
117663
|
+
if (opts.version === void 0 && protocol !== void 0 && protocol !== PROTOCOL_VERSION) {
|
|
117664
|
+
throw new BundleError(
|
|
117665
|
+
"protocol-mismatch",
|
|
117666
|
+
`war.app's client bundle ${version3} speaks protocol ${protocol}, and this server speaks ${PROTOCOL_VERSION}; its readers would read the replies in the wrong layout, so it is not used. ` + (protocol > PROTOCOL_VERSION ? "The client changed and this server needs an update." : "It is an older client.")
|
|
117667
|
+
);
|
|
117668
|
+
}
|
|
117669
|
+
this.protocol = protocol;
|
|
117332
117670
|
this.dialectCheck = this.interp.verifyDialect();
|
|
117333
117671
|
if (this.dialectCheck.mismatched.length) {
|
|
117334
117672
|
throw new BundleError(
|
|
@@ -117336,7 +117674,7 @@ var WarappBundle = class {
|
|
|
117336
117674
|
`war.app's client bundle ${version3} reads ${this.dialectCheck.mismatched.join(", ")} differently from this server's built-in readers; the client changed and this server needs an update to read it.`
|
|
117337
117675
|
);
|
|
117338
117676
|
}
|
|
117339
|
-
const unverifiedRequired =
|
|
117677
|
+
const unverifiedRequired = this.interp.requiredHelpers.map((n) => `${this.interp.helperClass}.${n}`).filter(
|
|
117340
117678
|
(k) => this.dialectCheck.unverified.includes(k)
|
|
117341
117679
|
);
|
|
117342
117680
|
if (unverifiedRequired.length) {
|
|
@@ -117350,15 +117688,42 @@ var WarappBundle = class {
|
|
|
117350
117688
|
interp;
|
|
117351
117689
|
/** Loaded from the cache because the current version could not be looked up. */
|
|
117352
117690
|
fallback = false;
|
|
117691
|
+
/** Set when this is the pinned known-good client standing in for a refused current one. */
|
|
117692
|
+
standInFor;
|
|
117693
|
+
/** Set while this build stands in for a refused current client: the window (see {@link StandInWindow}). */
|
|
117694
|
+
standIn;
|
|
117695
|
+
/** The SHA-256 of this build's bytes (set by {@link loadBundle}); a build without one is never recorded. */
|
|
117696
|
+
digest;
|
|
117697
|
+
/** Records this build as one that decoded a live board (set by {@link loadBundle}). */
|
|
117698
|
+
recorder;
|
|
117699
|
+
recorded;
|
|
117700
|
+
/**
|
|
117701
|
+
* A live board decoded with this build, every byte consumed: record it as a build that works, so a
|
|
117702
|
+
* later client this server cannot read is stood in for by it (the owner, 2026-11-17: fall back
|
|
117703
|
+
* gracefully). Once per loaded bundle; never throws.
|
|
117704
|
+
*/
|
|
117705
|
+
markDecoded() {
|
|
117706
|
+
if (this.recorded) return this.recorded.then((r) => r === "recorded" ? "unchanged" : r);
|
|
117707
|
+
this.recorded = this.recorder ? this.recorder().catch(() => "failed") : Promise.resolve("unchanged");
|
|
117708
|
+
return this.recorded;
|
|
117709
|
+
}
|
|
117353
117710
|
/** The built-in reader helpers checked against this bundle's own definitions at load. */
|
|
117354
117711
|
dialectCheck;
|
|
117712
|
+
/** The protocol version the bundle's readers default to, when it can be read from the bundle. */
|
|
117713
|
+
protocol;
|
|
117714
|
+
/** The reader names were derived from this bundle (false: the built-in v6.07 names). */
|
|
117715
|
+
get derivedDialect() {
|
|
117716
|
+
return this.interp.derived;
|
|
117717
|
+
}
|
|
117355
117718
|
/** What this bundle's decoding rests on, for the tools to show (#148). */
|
|
117356
117719
|
report() {
|
|
117357
117720
|
const { verified, unverified, reasons } = this.dialectCheck;
|
|
117358
117721
|
return {
|
|
117359
117722
|
bundleVersion: this.version,
|
|
117360
117723
|
fallback: this.fallback,
|
|
117361
|
-
helpers: { verified: [...verified], unverified: [...unverified], ...reasons ? { reasons: { ...reasons } } : {} }
|
|
117724
|
+
helpers: { verified: [...verified], unverified: [...unverified], ...reasons ? { reasons: { ...reasons } } : {} },
|
|
117725
|
+
...this.standInFor ? { standInFor: { ...this.standInFor } } : {},
|
|
117726
|
+
...this.standIn ? { standIn: { ...this.standIn } } : {}
|
|
117362
117727
|
};
|
|
117363
117728
|
}
|
|
117364
117729
|
/** Whether a type name is registered in this bundle. */
|
|
@@ -117381,6 +117746,11 @@ var WarappBundle = class {
|
|
|
117381
117746
|
return this.interp.readClass(typeNameOrVar, reader2, budget);
|
|
117382
117747
|
}
|
|
117383
117748
|
};
|
|
117749
|
+
var KNOWN_GOOD_BUNDLE = {
|
|
117750
|
+
version: "639304508939095333",
|
|
117751
|
+
digest: "3c55e2d08681d05661eb350b3d72d02f25729130bb78dc9c5d3b1febd73febd1"
|
|
117752
|
+
};
|
|
117753
|
+
var bundleUrlOf = (version3) => `https://${BUNDLE_HOST}${BUNDLE_PATH}?v=${version3}`;
|
|
117384
117754
|
var BUNDLE_FILE = /^([A-Za-z0-9._-]{1,64})\.([0-9a-f]{64})\.js$/;
|
|
117385
117755
|
var LEGACY_FILE = /^[A-Za-z0-9._-]{1,64}\.js(?:\.sha256)?$/;
|
|
117386
117756
|
var PARTIAL_FILE = /^[A-Za-z0-9._-]{1,64}(?:\.[0-9a-f]{64})?\.js(?:\.sha256)?\.tmp-(\d+)(?:-[0-9a-f]+)?$/;
|
|
@@ -117407,7 +117777,7 @@ async function abandoned(file2, pid) {
|
|
|
117407
117777
|
async function pruneBundles(dir, keep) {
|
|
117408
117778
|
try {
|
|
117409
117779
|
for (const name of await readdir4(dir)) {
|
|
117410
|
-
if (name
|
|
117780
|
+
if (keep.includes(name)) continue;
|
|
117411
117781
|
const partial2 = PARTIAL_FILE.exec(name);
|
|
117412
117782
|
if (!partial2 && !BUNDLE_FILE.test(name) && !LEGACY_FILE.test(name)) continue;
|
|
117413
117783
|
if (partial2 && !await abandoned(join7(dir, name), Number(partial2[1]))) continue;
|
|
@@ -117473,18 +117843,143 @@ async function readVerified(file2, digest) {
|
|
|
117473
117843
|
await rm(file2, { force: true });
|
|
117474
117844
|
return null;
|
|
117475
117845
|
}
|
|
117846
|
+
var isDialectRefusal = (e) => e instanceof BundleError && (e.kind === "dialect-mismatch" || e.kind === "dialect-unverified" || e.kind === "protocol-mismatch");
|
|
117847
|
+
async function cacheBundle(dataDir2, dir, name, src) {
|
|
117848
|
+
await ensurePrivateDir(dataDir2);
|
|
117849
|
+
await ensurePrivateDir(dir);
|
|
117850
|
+
await writePrivateAtomic(join7(dir, name), Buffer.from(src, "utf8"));
|
|
117851
|
+
}
|
|
117852
|
+
var KNOWN_GOOD_FILE = "known-good.json";
|
|
117853
|
+
var STAND_IN_FILE = "stand-in.json";
|
|
117854
|
+
var MAX_KNOWN_GOOD = 3;
|
|
117855
|
+
var DIGEST = /^[0-9a-f]{64}$/;
|
|
117856
|
+
var isRecorded = (v) => {
|
|
117857
|
+
if (typeof v !== "object" || v === null) return false;
|
|
117858
|
+
const r = v;
|
|
117859
|
+
return typeof r.version === "string" && SAFE_VERSION.test(r.version) && typeof r.digest === "string" && DIGEST.test(r.digest) && typeof r.verifiedAt === "string";
|
|
117860
|
+
};
|
|
117861
|
+
async function readKnownGood(dir) {
|
|
117862
|
+
let text;
|
|
117863
|
+
try {
|
|
117864
|
+
text = await readFile4(join7(dir, KNOWN_GOOD_FILE), "utf8");
|
|
117865
|
+
} catch (e) {
|
|
117866
|
+
return e.code === "ENOENT" ? [] : "unreadable";
|
|
117867
|
+
}
|
|
117868
|
+
try {
|
|
117869
|
+
const parsed = JSON.parse(text);
|
|
117870
|
+
const builds = parsed?.builds;
|
|
117871
|
+
if (!Array.isArray(builds)) return "unreadable";
|
|
117872
|
+
return builds.filter(isRecorded);
|
|
117873
|
+
} catch {
|
|
117874
|
+
return "unreadable";
|
|
117875
|
+
}
|
|
117876
|
+
}
|
|
117877
|
+
async function recordKnownGood(dataDir2, entry) {
|
|
117878
|
+
if (!isRecorded(entry)) return "failed";
|
|
117879
|
+
const dir = join7(dataDir2, "bundle");
|
|
117880
|
+
const file2 = join7(dir, KNOWN_GOOD_FILE);
|
|
117881
|
+
return withPathLock(file2, async () => {
|
|
117882
|
+
const builds = await readKnownGood(dir);
|
|
117883
|
+
if (builds === "unreadable") return "unreadable";
|
|
117884
|
+
const rest = builds.filter((b) => !(b.version === entry.version && b.digest === entry.digest));
|
|
117885
|
+
const next = [entry, ...rest].slice(0, MAX_KNOWN_GOOD);
|
|
117886
|
+
try {
|
|
117887
|
+
await ensurePrivateDir(dataDir2);
|
|
117888
|
+
await ensurePrivateDir(dir);
|
|
117889
|
+
await writePrivateAtomic(file2, `${JSON.stringify({ builds: next }, null, 2)}
|
|
117890
|
+
`);
|
|
117891
|
+
return "recorded";
|
|
117892
|
+
} catch {
|
|
117893
|
+
return "failed";
|
|
117894
|
+
}
|
|
117895
|
+
});
|
|
117896
|
+
}
|
|
117897
|
+
async function readWindow(dir) {
|
|
117898
|
+
try {
|
|
117899
|
+
const w = JSON.parse(await readFile4(join7(dir, STAND_IN_FILE), "utf8"));
|
|
117900
|
+
if (typeof w.refusedVersion === "string" && typeof w.since === "string" && !Number.isNaN(Date.parse(w.since))) {
|
|
117901
|
+
return { refusedVersion: w.refusedVersion, since: w.since };
|
|
117902
|
+
}
|
|
117903
|
+
} catch {
|
|
117904
|
+
}
|
|
117905
|
+
return void 0;
|
|
117906
|
+
}
|
|
117907
|
+
async function openWindow(dataDir2, dir, refusedVersion, reason, now) {
|
|
117908
|
+
const kept = await readWindow(dir);
|
|
117909
|
+
if (kept?.refusedVersion === refusedVersion) return kept.since;
|
|
117910
|
+
const since = new Date(now).toISOString();
|
|
117911
|
+
try {
|
|
117912
|
+
await ensurePrivateDir(dataDir2);
|
|
117913
|
+
await ensurePrivateDir(dir);
|
|
117914
|
+
await writePrivateAtomic(join7(dir, STAND_IN_FILE), `${JSON.stringify({ refusedVersion, since, reason }, null, 2)}
|
|
117915
|
+
`);
|
|
117916
|
+
} catch {
|
|
117917
|
+
}
|
|
117918
|
+
return since;
|
|
117919
|
+
}
|
|
117920
|
+
async function closeWindow(dir) {
|
|
117921
|
+
await rm(join7(dir, STAND_IN_FILE), { force: true }).catch(() => void 0);
|
|
117922
|
+
}
|
|
117923
|
+
async function loadPinned(opts, dir, kg) {
|
|
117924
|
+
const name = bundleName(kg.version, kg.digest);
|
|
117925
|
+
let src = await readVerified(join7(dir, name), kg.digest);
|
|
117926
|
+
if (src === null) {
|
|
117927
|
+
let fetched;
|
|
117928
|
+
try {
|
|
117929
|
+
fetched = await opts.fetchText(bundleUrlOf(kg.version));
|
|
117930
|
+
} catch {
|
|
117931
|
+
return void 0;
|
|
117932
|
+
}
|
|
117933
|
+
if (sha256(Buffer.from(fetched, "utf8")) !== kg.digest || !looksLikeBundle(fetched)) return void 0;
|
|
117934
|
+
try {
|
|
117935
|
+
await cacheBundle(opts.dataDir, dir, name, fetched);
|
|
117936
|
+
} catch {
|
|
117937
|
+
return void 0;
|
|
117938
|
+
}
|
|
117939
|
+
src = fetched;
|
|
117940
|
+
}
|
|
117941
|
+
try {
|
|
117942
|
+
const bundle = new WarappBundle(src, kg.version, opts.interp);
|
|
117943
|
+
bundle.digest = kg.digest;
|
|
117944
|
+
return { bundle, name };
|
|
117945
|
+
} catch {
|
|
117946
|
+
return void 0;
|
|
117947
|
+
}
|
|
117948
|
+
}
|
|
117949
|
+
function withRecorder(opts, bundle) {
|
|
117950
|
+
const now = opts.now ?? Date.now;
|
|
117951
|
+
bundle.recorder = async () => {
|
|
117952
|
+
if (!bundle.digest) return "unchanged";
|
|
117953
|
+
return recordKnownGood(opts.dataDir, { version: bundle.version, digest: bundle.digest, verifiedAt: new Date(now()).toISOString() });
|
|
117954
|
+
};
|
|
117955
|
+
return bundle;
|
|
117956
|
+
}
|
|
117957
|
+
async function recordedNames(dir) {
|
|
117958
|
+
const builds = await readKnownGood(dir);
|
|
117959
|
+
return builds === "unreadable" ? [] : builds.map((b) => bundleName(b.version, b.digest));
|
|
117960
|
+
}
|
|
117476
117961
|
async function loadBundle(opts) {
|
|
117477
117962
|
const pageUrl = opts.pageUrl ?? DEFAULT_PAGE_URL;
|
|
117478
117963
|
const dir = join7(opts.dataDir, "bundle");
|
|
117964
|
+
const kg = opts.knownGood === void 0 ? KNOWN_GOOD_BUNDLE : opts.knownGood;
|
|
117965
|
+
const now = opts.now ?? Date.now;
|
|
117479
117966
|
let source;
|
|
117480
117967
|
try {
|
|
117481
117968
|
source = discoverBundleUrl(await opts.fetchText(pageUrl), pageUrl);
|
|
117482
117969
|
} catch (e) {
|
|
117483
|
-
const
|
|
117484
|
-
|
|
117485
|
-
|
|
117486
|
-
|
|
117487
|
-
|
|
117970
|
+
for (const c of await cachedNewestFirst(dir)) {
|
|
117971
|
+
const src2 = await readVerified(c.file, c.digest);
|
|
117972
|
+
if (src2 === null) continue;
|
|
117973
|
+
try {
|
|
117974
|
+
const b = new WarappBundle(src2, c.version, opts.interp);
|
|
117975
|
+
b.fallback = true;
|
|
117976
|
+
b.digest = c.digest;
|
|
117977
|
+
return withRecorder(opts, b);
|
|
117978
|
+
} catch (err) {
|
|
117979
|
+
if (!isDialectRefusal(err)) throw err;
|
|
117980
|
+
}
|
|
117981
|
+
}
|
|
117982
|
+
throw e;
|
|
117488
117983
|
}
|
|
117489
117984
|
const { url: url4, version: version3 } = source;
|
|
117490
117985
|
const cached3 = await newestVerified(dir, version3);
|
|
@@ -117497,17 +117992,39 @@ async function loadBundle(opts) {
|
|
|
117497
117992
|
if (!looksLikeBundle(src)) {
|
|
117498
117993
|
throw new BundleError("bad-bundle", `${url4} does not look like the war.app client bundle`);
|
|
117499
117994
|
}
|
|
117500
|
-
|
|
117501
|
-
await
|
|
117502
|
-
const bytes = Buffer.from(src, "utf8");
|
|
117503
|
-
name = bundleName(version3, sha256(bytes));
|
|
117504
|
-
await writePrivateAtomic(join7(dir, name), bytes);
|
|
117995
|
+
name = bundleName(version3, sha256(Buffer.from(src, "utf8")));
|
|
117996
|
+
await cacheBundle(opts.dataDir, dir, name, src);
|
|
117505
117997
|
}
|
|
117506
|
-
const
|
|
117507
|
-
await
|
|
117508
|
-
|
|
117998
|
+
const keepKnownGood = kg ? [bundleName(kg.version, kg.digest)] : [];
|
|
117999
|
+
const keepRecorded = await recordedNames(dir);
|
|
118000
|
+
let bundle;
|
|
118001
|
+
try {
|
|
118002
|
+
bundle = new WarappBundle(src, version3, opts.interp);
|
|
118003
|
+
} catch (e) {
|
|
118004
|
+
if (!isDialectRefusal(e)) throw e;
|
|
118005
|
+
const recorded = await readKnownGood(dir);
|
|
118006
|
+
const candidates = [
|
|
118007
|
+
...recorded === "unreadable" ? [] : recorded.map(({ version: v, digest }) => ({ version: v, digest })),
|
|
118008
|
+
...kg ? [kg] : []
|
|
118009
|
+
].filter((c, i2, all2) => c.version !== version3 && all2.findIndex((o) => o.version === c.version && o.digest === c.digest) === i2);
|
|
118010
|
+
for (const c of candidates) {
|
|
118011
|
+
const standIn = await loadPinned(opts, dir, c);
|
|
118012
|
+
if (!standIn) continue;
|
|
118013
|
+
const since = await openWindow(opts.dataDir, dir, version3, e.message, now());
|
|
118014
|
+
standIn.bundle.standInFor = { version: version3, reason: e.message };
|
|
118015
|
+
standIn.bundle.standIn = { version: c.version, refusedVersion: version3, since, reason: e.message };
|
|
118016
|
+
await pruneBundles(dir, [name, standIn.name, ...keepKnownGood, ...keepRecorded]);
|
|
118017
|
+
return withRecorder(opts, standIn.bundle);
|
|
118018
|
+
}
|
|
118019
|
+
throw e;
|
|
118020
|
+
}
|
|
118021
|
+
bundle.digest = name.slice(version3.length + 1, -".js".length);
|
|
118022
|
+
await closeWindow(dir);
|
|
118023
|
+
await pruneBundles(dir, [name, ...keepKnownGood, ...keepRecorded]);
|
|
118024
|
+
return withRecorder(opts, bundle);
|
|
117509
118025
|
}
|
|
117510
118026
|
var FALLBACK_RETRY_MS = 5 * 6e4;
|
|
118027
|
+
var STAND_IN_RETRY_MS = 60 * 6e4;
|
|
117511
118028
|
var BundleProvider = class {
|
|
117512
118029
|
constructor(opts) {
|
|
117513
118030
|
this.opts = opts;
|
|
@@ -117524,11 +118041,13 @@ var BundleProvider = class {
|
|
|
117524
118041
|
this.pending = p;
|
|
117525
118042
|
p.then(
|
|
117526
118043
|
(b) => {
|
|
117527
|
-
if (
|
|
118044
|
+
if (this.pending !== p) return;
|
|
118045
|
+
if (b.standInFor) this.fallbackUntil = now() + STAND_IN_RETRY_MS;
|
|
118046
|
+
else if (b.fallback) this.fallbackUntil = now() + FALLBACK_RETRY_MS;
|
|
117528
118047
|
},
|
|
117529
118048
|
(e) => {
|
|
117530
118049
|
if (this.pending !== p) return;
|
|
117531
|
-
if (
|
|
118050
|
+
if (isDialectRefusal(e)) {
|
|
117532
118051
|
this.fallbackUntil = now() + FALLBACK_RETRY_MS;
|
|
117533
118052
|
} else this.pending = null;
|
|
117534
118053
|
}
|
|
@@ -117539,7 +118058,7 @@ var BundleProvider = class {
|
|
|
117539
118058
|
};
|
|
117540
118059
|
|
|
117541
118060
|
// src/protocol/rpc.ts
|
|
117542
|
-
var CLIENT_VERSION = "v6.
|
|
118061
|
+
var CLIENT_VERSION = "v6.08.0.2";
|
|
117543
118062
|
var PLATFORM_WEBSITE = 15;
|
|
117544
118063
|
var INITIAL_SERVER_INFO_A = 348;
|
|
117545
118064
|
var INITIAL_SERVER_INFO_B = 88732;
|
|
@@ -117550,6 +118069,8 @@ function methodTakesAuth(methodId) {
|
|
|
117550
118069
|
return !NO_AUTH_METHODS.has(methodId);
|
|
117551
118070
|
}
|
|
117552
118071
|
var SERVER_ERROR_MESSAGES = {
|
|
118072
|
+
// AuthFailed (live 2026-11-17): war.app's answer when the request's session is not signed in.
|
|
118073
|
+
3: "war.app refused the request as not signed in (AuthFailed): the war.app session this server uses is signed out.",
|
|
117553
118074
|
10: "war.app refused the order sequence \u2014 card plays must come in turn-phase order.",
|
|
117554
118075
|
11: "Your orders deploy more or fewer armies than you are receiving this turn. Please verify your orders deploy the correct number.",
|
|
117555
118076
|
51: "You hold more cards than this game allows, so war.app requires you to play or discard one this turn.",
|
|
@@ -117563,9 +118084,20 @@ var SERVER_ERROR_MESSAGES = {
|
|
|
117563
118084
|
750: "Sorry, the slot you joined is no longer available. Please try again with a different slot."
|
|
117564
118085
|
};
|
|
117565
118086
|
var MAX_SERVER_MESSAGE = 200;
|
|
118087
|
+
var ProtocolVersionError = class extends McpToolError {
|
|
118088
|
+
constructor(methodName, answered) {
|
|
118089
|
+
super(`war.app answered ${methodName} in protocol version ${answered}; this server reads version ${PROTOCOL_VERSION}.`, {
|
|
118090
|
+
kind: "unknown",
|
|
118091
|
+
hint: "The war.app client may have changed; this server needs an update to read it."
|
|
118092
|
+
});
|
|
118093
|
+
this.answered = answered;
|
|
118094
|
+
}
|
|
118095
|
+
answered;
|
|
118096
|
+
name = "ProtocolVersionError";
|
|
118097
|
+
};
|
|
117566
118098
|
var WarappServerError = class extends McpToolError {
|
|
117567
|
-
constructor(code2, message) {
|
|
117568
|
-
super(message, { kind: "unknown" });
|
|
118099
|
+
constructor(code2, message, hint) {
|
|
118100
|
+
super(message, { kind: "unknown", ...hint ? { hint } : {} });
|
|
117569
118101
|
this.code = code2;
|
|
117570
118102
|
}
|
|
117571
118103
|
code;
|
|
@@ -117644,10 +118176,7 @@ var WarappRpc = class {
|
|
|
117644
118176
|
);
|
|
117645
118177
|
}
|
|
117646
118178
|
if (env.version !== PROTOCOL_VERSION) {
|
|
117647
|
-
throw new
|
|
117648
|
-
`war.app answered ${methodName} in protocol version ${env.version}; this server reads version ${PROTOCOL_VERSION}.`,
|
|
117649
|
-
{ kind: "unknown", hint: "The war.app client may have changed; this server needs an update to read it." }
|
|
117650
|
-
);
|
|
118179
|
+
throw new ProtocolVersionError(methodName, env.version);
|
|
117651
118180
|
}
|
|
117652
118181
|
if (env.method !== methodId) {
|
|
117653
118182
|
throw new McpToolError(`war.app answered ${methodName} (method ${methodId}) with method ${env.method}.`, {
|
|
@@ -117687,7 +118216,20 @@ var WarappRpc = class {
|
|
|
117687
118216
|
if (down.unreadMail) this.state.kFa = down.unreadMail.kFa;
|
|
117688
118217
|
}
|
|
117689
118218
|
};
|
|
118219
|
+
var CLIENT_OUT_OF_DATE = 48;
|
|
118220
|
+
var CLIENT_VERSION_TOO_HIGH = 49;
|
|
118221
|
+
var ClientOutOfDateError = class extends WarappServerError {
|
|
118222
|
+
name = "ClientOutOfDateError";
|
|
118223
|
+
constructor(methodName, code2) {
|
|
118224
|
+
super(
|
|
118225
|
+
code2,
|
|
118226
|
+
code2 === CLIENT_OUT_OF_DATE ? `war.app refused ${methodName} as ClientOutOfDate (war.app error 48): it no longer accepts protocol ${PROTOCOL_VERSION}, the one this server speaks, so every war.app call through the web protocol will fail until this server is updated to war.app\u2019s current client.` : `war.app refused ${methodName} as ClientVersionTooHigh (war.app error 49): it does not know client ${CLIENT_VERSION}, the version this server sends.`,
|
|
118227
|
+
'This server needs an update to war.app\u2019s current client: see docs/CLIENT-RELEASES.md, "Updating to a new client". Retrying or signing in again will not help.'
|
|
118228
|
+
);
|
|
118229
|
+
}
|
|
118230
|
+
};
|
|
117690
118231
|
function serverError(methodName, code2, message, email4) {
|
|
118232
|
+
if (code2 === CLIENT_OUT_OF_DATE || code2 === CLIENT_VERSION_TOO_HIGH) return new ClientOutOfDateError(methodName, code2);
|
|
117691
118233
|
const known2 = SERVER_ERROR_MESSAGES[code2];
|
|
117692
118234
|
if (known2) return new WarappServerError(code2, `${known2} (war.app error ${code2})`);
|
|
117693
118235
|
let detail2 = (message ?? "").split(/\r?\n/, 1)[0].trim();
|
|
@@ -124776,7 +125318,7 @@ async function captureBearerHeader(opts) {
|
|
|
124776
125318
|
}
|
|
124777
125319
|
|
|
124778
125320
|
// src/version.ts
|
|
124779
|
-
var VERSION2 = "0.
|
|
125321
|
+
var VERSION2 = "0.5.0";
|
|
124780
125322
|
|
|
124781
125323
|
// src/transport-bridge.ts
|
|
124782
125324
|
var SERVER_NAME = "warapp-mcp";
|
|
@@ -125168,15 +125710,52 @@ function beginFirstError(game) {
|
|
|
125168
125710
|
async function loadLiveTerritories(ctx, game) {
|
|
125169
125711
|
return (await loadLiveGame(ctx, game)).territories;
|
|
125170
125712
|
}
|
|
125713
|
+
var PROTOCOL_UPDATE_ISSUE = "https://github.com/chrischall/warapp-mcp/issues/340";
|
|
125714
|
+
function standInLine(w) {
|
|
125715
|
+
if (!w) return void 0;
|
|
125716
|
+
return `war.app ships a client this server cannot read yet (${w.refusedVersion}), so the client build ${w.version}, which war.app still answers, stands in and decodes the board (since ${w.since}). Boards still decode exactly; war.app may stop answering the old build at any time, and this server then needs its update (#340, ${PROTOCOL_UPDATE_ISSUE}).`;
|
|
125717
|
+
}
|
|
125718
|
+
function standInOf(ctx) {
|
|
125719
|
+
return ctx.decoderReport()?.standIn;
|
|
125720
|
+
}
|
|
125721
|
+
var StandInClosedError = class extends McpToolError {
|
|
125722
|
+
constructor(window, cause) {
|
|
125723
|
+
const why = cause instanceof Error ? cause.message : String(cause);
|
|
125724
|
+
super(
|
|
125725
|
+
`war.app no longer answers the client build ${window.version} this server has decoded with since ${window.since} (standing in for ${window.refusedVersion}, which this server cannot read yet): ${why} Nothing was decoded; the old client is no longer accepted, so this server needs the protocol update (#340).`,
|
|
125726
|
+
{
|
|
125727
|
+
kind: "unknown",
|
|
125728
|
+
hint: `The old client is no longer accepted: this server needs the protocol update (${PROTOCOL_UPDATE_ISSUE}). Play in the war.app web client until then.`,
|
|
125729
|
+
cause
|
|
125730
|
+
}
|
|
125731
|
+
);
|
|
125732
|
+
this.window = window;
|
|
125733
|
+
}
|
|
125734
|
+
window;
|
|
125735
|
+
name = "StandInClosedError";
|
|
125736
|
+
};
|
|
125737
|
+
var isLayoutFailure = (e) => e instanceof ProtocolVersionError || e instanceof LiveBoardFormatError || e instanceof ProtocolError3 || e instanceof InterpError;
|
|
125738
|
+
async function windowClosed(ctx, bundle, e) {
|
|
125739
|
+
if (!isLayoutFailure(e)) return e;
|
|
125740
|
+
const b = bundle ?? await ctx.bundle().catch(() => void 0);
|
|
125741
|
+
const w = b?.report?.().standIn;
|
|
125742
|
+
return w ? new StandInClosedError(w, e) : e;
|
|
125743
|
+
}
|
|
125744
|
+
async function readLatestBoard(ctx, gameId) {
|
|
125745
|
+
let bundle;
|
|
125746
|
+
try {
|
|
125747
|
+
const env = await ctx.rpc.call("GetLatestGameInfo", Method.GetLatestGameInfo, (w) => writeGetLatestGameInfoParams(w, gameId));
|
|
125748
|
+
bundle = await ctx.bundle();
|
|
125749
|
+
const info = readLatestGameInfo(bundle, env.body);
|
|
125750
|
+
const territories = standingFromInfo(info);
|
|
125751
|
+
if (territories) await bundle.markDecoded?.();
|
|
125752
|
+
return { info, territories };
|
|
125753
|
+
} catch (e) {
|
|
125754
|
+
throw await windowClosed(ctx, bundle, e);
|
|
125755
|
+
}
|
|
125756
|
+
}
|
|
125171
125757
|
async function loadLiveGame(ctx, game) {
|
|
125172
|
-
const
|
|
125173
|
-
"GetLatestGameInfo",
|
|
125174
|
-
Method.GetLatestGameInfo,
|
|
125175
|
-
(w) => writeGetLatestGameInfoParams(w, game.id)
|
|
125176
|
-
);
|
|
125177
|
-
const bundle = await ctx.bundle();
|
|
125178
|
-
const info = readLatestGameInfo(bundle, env.body);
|
|
125179
|
-
const territories = standingFromInfo(info);
|
|
125758
|
+
const { info, territories } = await readLatestBoard(ctx, game.id);
|
|
125180
125759
|
if (!territories) {
|
|
125181
125760
|
if (awaitsBegin(game)) throw beginFirstError(game);
|
|
125182
125761
|
throw new McpToolError(`war.app has no board for game ${game.id} yet (game state: ${game.state}).`, {
|
|
@@ -125526,6 +126105,45 @@ function looksSignedOut(requestedUrl, res) {
|
|
|
125526
126105
|
if (/\/services\b/i.test(reqPath) && !looksLikeHexFrame(res.body)) return true;
|
|
125527
126106
|
return false;
|
|
125528
126107
|
}
|
|
126108
|
+
var SIGNED_IN_PROBE_URL = `${SESSION_ORIGIN}/InviteToken`;
|
|
126109
|
+
var AUTH_FAILED_CODE = 3;
|
|
126110
|
+
var INVITE_TOKEN_TEXT = /Your invite token is\s*\d{5,20}/;
|
|
126111
|
+
function signInVerdict(res) {
|
|
126112
|
+
let path = "";
|
|
126113
|
+
try {
|
|
126114
|
+
path = new URL(res.url).pathname;
|
|
126115
|
+
} catch {
|
|
126116
|
+
path = "";
|
|
126117
|
+
}
|
|
126118
|
+
if (SIGNIN_PATH.test(path)) return "signed-out";
|
|
126119
|
+
if (res.status !== 200) return "unknown";
|
|
126120
|
+
if (INVITE_TOKEN_TEXT.test(res.body)) return "signed-in";
|
|
126121
|
+
if (hasPasswordInput(res.body)) return "signed-out";
|
|
126122
|
+
return "unknown";
|
|
126123
|
+
}
|
|
126124
|
+
function isAuthFailedReply(body) {
|
|
126125
|
+
if (!looksLikeHexFrame(body)) return false;
|
|
126126
|
+
try {
|
|
126127
|
+
return decodeReplyEnvelope(fromHex(body.trim())).error?.code === AUTH_FAILED_CODE;
|
|
126128
|
+
} catch {
|
|
126129
|
+
return false;
|
|
126130
|
+
}
|
|
126131
|
+
}
|
|
126132
|
+
var isServicesUrl = (url4) => {
|
|
126133
|
+
try {
|
|
126134
|
+
return /\/services\b/i.test(new URL(url4).pathname);
|
|
126135
|
+
} catch {
|
|
126136
|
+
return false;
|
|
126137
|
+
}
|
|
126138
|
+
};
|
|
126139
|
+
var isProbeUrl = (url4) => {
|
|
126140
|
+
try {
|
|
126141
|
+
const u = new URL(url4);
|
|
126142
|
+
return u.origin === SESSION_ORIGIN && u.pathname === new URL(SIGNED_IN_PROBE_URL).pathname;
|
|
126143
|
+
} catch {
|
|
126144
|
+
return false;
|
|
126145
|
+
}
|
|
126146
|
+
};
|
|
125529
126147
|
var DirectBridge = class {
|
|
125530
126148
|
constructor(store, fetchImpl = fetchViaPublic, hostSignIn = false) {
|
|
125531
126149
|
this.store = store;
|
|
@@ -125535,6 +126153,24 @@ var DirectBridge = class {
|
|
|
125535
126153
|
store;
|
|
125536
126154
|
fetchImpl;
|
|
125537
126155
|
hostSignIn;
|
|
126156
|
+
/** One GET of {@link SIGNED_IN_PROBE_URL} with the session; `none` when no session is linked. Never throws. */
|
|
126157
|
+
async checkSignedIn(signal) {
|
|
126158
|
+
const sess = await this.store.read();
|
|
126159
|
+
if (!sess) return "none";
|
|
126160
|
+
return this.probe(sess.authToken, signal);
|
|
126161
|
+
}
|
|
126162
|
+
async probe(token, signal) {
|
|
126163
|
+
try {
|
|
126164
|
+
const res = await this.fetchImpl(SIGNED_IN_PROBE_URL, {
|
|
126165
|
+
method: "GET",
|
|
126166
|
+
headers: { cookie: `AuthToken=${token}` },
|
|
126167
|
+
...signal ? { signal } : {}
|
|
126168
|
+
});
|
|
126169
|
+
return signInVerdict(res);
|
|
126170
|
+
} catch {
|
|
126171
|
+
return "unknown";
|
|
126172
|
+
}
|
|
126173
|
+
}
|
|
125538
126174
|
async fetch(init, signal) {
|
|
125539
126175
|
const sess = await this.store.read();
|
|
125540
126176
|
if (!sess) throw new SessionNotLinkedError(this.hostSignIn ? { hostSignIn: true } : {});
|
|
@@ -125563,13 +126199,19 @@ var DirectBridge = class {
|
|
|
125563
126199
|
});
|
|
125564
126200
|
}
|
|
125565
126201
|
}
|
|
125566
|
-
|
|
125567
|
-
|
|
126202
|
+
const suspect = looksSignedOut(url4, res) || answered && isServicesUrl(url4) && isAuthFailedReply(res.body);
|
|
126203
|
+
if (suspect) {
|
|
126204
|
+
const verdict = isProbeUrl(url4) && isSafeToReplay(init.method) ? signInVerdict(res) : await this.probe(token, signal);
|
|
126205
|
+
if (verdict !== "signed-in") {
|
|
126206
|
+
throw new SessionExpiredError({ capturedAt: sess.capturedAt, hostSignIn: this.hostSignIn || sess.origin === "host" });
|
|
126207
|
+
}
|
|
125568
126208
|
}
|
|
125569
126209
|
return { status: res.status, body: res.body, url: res.url };
|
|
125570
126210
|
}
|
|
125571
126211
|
};
|
|
125572
126212
|
var RELINK_CHECK_MS = 5e3;
|
|
126213
|
+
var WALL_RETRY_BASE_MS = 6e4;
|
|
126214
|
+
var WALL_RETRY_MAX_MS = 30 * 6e4;
|
|
125573
126215
|
function createDirectFirstBridge(opts) {
|
|
125574
126216
|
const env = opts.env ?? process.env;
|
|
125575
126217
|
const hosted = isHosted(env);
|
|
@@ -125584,10 +126226,15 @@ function createDirectFirstBridge(opts) {
|
|
|
125584
126226
|
let wall = null;
|
|
125585
126227
|
let stale = false;
|
|
125586
126228
|
let lastRelinkCheck = Number.NEGATIVE_INFINITY;
|
|
126229
|
+
let wallsInARow = 0;
|
|
125587
126230
|
const onFallback = ({ error: error62 }) => {
|
|
125588
|
-
const next = error62 instanceof SessionExpiredError ? { kind: "session", capturedAt: error62.capturedAt ?? null } : error62 instanceof SessionNotLinkedError ? { kind: "session", capturedAt: null } : { kind: "edge" };
|
|
125589
|
-
wall = next;
|
|
125590
126231
|
const why = error62 instanceof SessionExpiredError ? "the linked war.app session is signed out" : error62 instanceof SessionNotLinkedError ? "no war.app session is linked" : "the site edge refused the direct request";
|
|
126232
|
+
const since = now();
|
|
126233
|
+
wallsInARow += 1;
|
|
126234
|
+
const retryAt = hosted ? since + Math.min(WALL_RETRY_BASE_MS * 2 ** (wallsInARow - 1), WALL_RETRY_MAX_MS) : null;
|
|
126235
|
+
const timing = { reason: why, since, retryAt };
|
|
126236
|
+
const next = error62 instanceof SessionExpiredError ? { kind: "session", capturedAt: error62.capturedAt ?? null, ...timing } : error62 instanceof SessionNotLinkedError ? { kind: "session", capturedAt: null, ...timing } : { kind: "edge", ...timing };
|
|
126237
|
+
wall = next;
|
|
125591
126238
|
log(
|
|
125592
126239
|
`[warapp-mcp] Direct transport unavailable (${why}) \u2014 switching to the ContextMint Bridge browser bridge. Keep a ${SESSION_HOST} tab open and approve the pairing prompt in the extension if one appears` + (next.kind !== "session" ? "." : hostSignIn ? `. ${HOST_SIGN_IN_ADVICE}` : hosted ? "." : "; run warapp_link_session to return to the direct transport.")
|
|
125593
126240
|
);
|
|
@@ -125603,11 +126250,15 @@ function createDirectFirstBridge(opts) {
|
|
|
125603
126250
|
onFallback
|
|
125604
126251
|
});
|
|
125605
126252
|
let legs = build2();
|
|
125606
|
-
const
|
|
125607
|
-
if (wall
|
|
126253
|
+
const liftWall = () => {
|
|
126254
|
+
if (!wall) return;
|
|
125608
126255
|
wall = null;
|
|
125609
126256
|
legs = build2();
|
|
125610
126257
|
};
|
|
126258
|
+
const liftSessionWall = () => {
|
|
126259
|
+
if (wall?.kind !== "session") return;
|
|
126260
|
+
liftWall();
|
|
126261
|
+
};
|
|
125611
126262
|
const relinkedSinceWall = async () => {
|
|
125612
126263
|
if (wall?.kind !== "session") return false;
|
|
125613
126264
|
const t = now();
|
|
@@ -125621,12 +126272,16 @@ function createDirectFirstBridge(opts) {
|
|
|
125621
126272
|
liftSessionWall();
|
|
125622
126273
|
stale = false;
|
|
125623
126274
|
}
|
|
126275
|
+
if (mode === "auto" && wall?.retryAt != null && now() >= wall.retryAt) liftWall();
|
|
125624
126276
|
let reached;
|
|
125625
126277
|
return legs.run(async (leg, ctx) => {
|
|
125626
126278
|
if (leg === direct) {
|
|
125627
126279
|
try {
|
|
125628
126280
|
const res = await direct.fetch(init, ctx.signal);
|
|
125629
|
-
if (res.status === 200)
|
|
126281
|
+
if (res.status === 200) {
|
|
126282
|
+
stale = false;
|
|
126283
|
+
wallsInARow = 0;
|
|
126284
|
+
}
|
|
125630
126285
|
return res;
|
|
125631
126286
|
} catch (err) {
|
|
125632
126287
|
if (err instanceof SessionExpiredError) {
|
|
@@ -125648,6 +126303,23 @@ function createDirectFirstBridge(opts) {
|
|
|
125648
126303
|
bridgeTransport: () => legs.bridgeTransport(),
|
|
125649
126304
|
stats: () => legs.stats(),
|
|
125650
126305
|
sessionStale: () => stale,
|
|
126306
|
+
wall: () => wall ? {
|
|
126307
|
+
kind: wall.kind,
|
|
126308
|
+
reason: wall.reason,
|
|
126309
|
+
since: new Date(wall.since).toISOString(),
|
|
126310
|
+
retryAt: wall.retryAt === null ? null : new Date(wall.retryAt).toISOString()
|
|
126311
|
+
} : null,
|
|
126312
|
+
checkSession: async () => {
|
|
126313
|
+
const verdict = await direct.checkSignedIn();
|
|
126314
|
+
if (verdict === "signed-in") {
|
|
126315
|
+
stale = false;
|
|
126316
|
+
wallsInARow = 0;
|
|
126317
|
+
if (mode === "auto") liftWall();
|
|
126318
|
+
} else if (verdict === "signed-out") {
|
|
126319
|
+
stale = true;
|
|
126320
|
+
}
|
|
126321
|
+
return verdict;
|
|
126322
|
+
},
|
|
125651
126323
|
sessionLinked: () => {
|
|
125652
126324
|
stale = false;
|
|
125653
126325
|
if (mode === "auto") liftSessionWall();
|
|
@@ -125823,12 +126495,7 @@ function beginnable(game, me) {
|
|
|
125823
126495
|
requirePlaying(game, mySeat(game, me));
|
|
125824
126496
|
}
|
|
125825
126497
|
async function liveBoard(ctx, gameId) {
|
|
125826
|
-
|
|
125827
|
-
"GetLatestGameInfo",
|
|
125828
|
-
Method.GetLatestGameInfo,
|
|
125829
|
-
(w) => writeGetLatestGameInfoParams(w, gameId)
|
|
125830
|
-
);
|
|
125831
|
-
return standingFromInfo(readLatestGameInfo(await ctx.bundle(), env.body)) ?? void 0;
|
|
126498
|
+
return (await readLatestBoard(ctx, gameId)).territories ?? void 0;
|
|
125832
126499
|
}
|
|
125833
126500
|
function registerBeginTurnTool(server, ctx) {
|
|
125834
126501
|
defineGatedWrite(
|
|
@@ -126271,8 +126938,8 @@ function registerBoardTool(server, client, live) {
|
|
|
126271
126938
|
// src/chat.ts
|
|
126272
126939
|
var GAME_DETAILS_AND_CHAT = "warlight.shared.GameDetailsAndChat";
|
|
126273
126940
|
var GAME_MESSAGE = "warlight.shared.GameMessage";
|
|
126274
|
-
var GM = { date: 0, sender: 1, group: 2, id: 4,
|
|
126275
|
-
var GAME_MESSAGE_FIELDS =
|
|
126941
|
+
var GM = { date: 0, sender: 1, group: 2, id: 4, images: 5, text: 6, reactions: 7, channel: 8, to: 9, turn: 11 };
|
|
126942
|
+
var GAME_MESSAGE_FIELDS = 12;
|
|
126276
126943
|
var PUBLIC_CHANNEL = -1;
|
|
126277
126944
|
var CHAT_CHANNELS = ["public", "team", "private", "unknown"];
|
|
126278
126945
|
var isInt3 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
@@ -126289,7 +126956,10 @@ function webLine(m) {
|
|
|
126289
126956
|
const channel = f[GM.channel];
|
|
126290
126957
|
const to = f[GM.to];
|
|
126291
126958
|
const turn = f[GM.turn];
|
|
126959
|
+
const images = f[GM.images];
|
|
126960
|
+
const reactions = f[GM.reactions];
|
|
126292
126961
|
if (!(date5 === null || date5 instanceof Date) || !optInt(sender) || !optInt(group) || !optInt(to) || !optInt(turn)) return void 0;
|
|
126962
|
+
if (!(images === null || Array.isArray(images)) || !(reactions === null || Array.isArray(reactions))) return void 0;
|
|
126293
126963
|
if (!(id === null || typeof id === "string" || isInt3(id)) || typeof text !== "string" || !isInt3(channel)) return void 0;
|
|
126294
126964
|
const line = { sender, text, turn, channel: "unknown" };
|
|
126295
126965
|
if (id !== null) line.id = String(id);
|
|
@@ -132966,7 +133636,7 @@ var GAME_WL = "warlight.shared.GameWL";
|
|
|
132966
133636
|
var GAME_PLAYER = "warlight.shared.GamePlayer";
|
|
132967
133637
|
var GAME_WL_FIELDS = 14;
|
|
132968
133638
|
var GW_PLAYERS = 7;
|
|
132969
|
-
var GAME_PLAYER_FIELDS =
|
|
133639
|
+
var GAME_PLAYER_FIELDS = 37;
|
|
132970
133640
|
var GPL = { aiId: 0, turnedAI: 14, id: 20, accepted: 21, state: 28, surrendered: 29 };
|
|
132971
133641
|
var seatPlaying = (s) => playerStateName(s.state) === "Playing";
|
|
132972
133642
|
var isInt9 = (v) => typeof v === "number" && Number.isInteger(v);
|
|
@@ -133033,7 +133703,7 @@ function pendingSurrenders(seats, me, feedIdOf = () => null) {
|
|
|
133033
133703
|
var surrenderOwed = (pending) => (pending ?? []).some((p) => p.owedByMe === true);
|
|
133034
133704
|
|
|
133035
133705
|
// src/tools/surrender-pending.ts
|
|
133036
|
-
var SURRENDER_PENDING_NOTE = "Read from the game details (the web client's GameRefresh), UNVERIFIED live: a list is what the details showed (empty: no surrender pending); null means they could not be read, not that none is pending. owedByMe true: the player is waiting for you to accept its surrender. Accepting is the owner's decision (it hands that player's land on and can end the game).";
|
|
133706
|
+
var SURRENDER_PENDING_NOTE = "Read from the game details (the web client's GameRefresh), UNVERIFIED live: a list is what the details showed (empty: no surrender pending); null means they could not be read, not that none is pending. A lobby, a finished game and a game you no longer play in are empty without a read (#327): no surrender there can wait on you. owedByMe true: the player is waiting for you to accept its surrender. Accepting is the owner's decision (it hands that player's land on and can end the game).";
|
|
133037
133707
|
var IN_PLAY = /* @__PURE__ */ new Set(["Playing", "DistributingTerritories"]);
|
|
133038
133708
|
function surrenderMayBePending(state, mySeatState) {
|
|
133039
133709
|
return IN_PLAY.has(state) && mySeatState === "Playing";
|
|
@@ -133054,7 +133724,8 @@ async function readDetailsSeats(ctx, gameId) {
|
|
|
133054
133724
|
}
|
|
133055
133725
|
}
|
|
133056
133726
|
async function readPendingSurrenders(ctx, game, me, read = (id) => readDetailsSeats(ctx, id)) {
|
|
133057
|
-
if (!me
|
|
133727
|
+
if (!me) return null;
|
|
133728
|
+
if (!surrenderMayBePending(game.state, me.state)) return [];
|
|
133058
133729
|
const seats = await read(game.id);
|
|
133059
133730
|
if (!seats) return null;
|
|
133060
133731
|
const byInGame = /* @__PURE__ */ new Map();
|
|
@@ -138020,6 +138691,8 @@ function registerTurnTools(server, ctx, opts = {}) {
|
|
|
138020
138691
|
const guessOrders = guess ? guessOrdersOf(orders, guess) : void 0;
|
|
138021
138692
|
const owedLine = surrenderOwedLine(surrenders);
|
|
138022
138693
|
if (owedLine) warnings.unshift(owedLine);
|
|
138694
|
+
const standInNote = standInLine(standInOf(ctx));
|
|
138695
|
+
if (standInNote) warnings.unshift(standInNote);
|
|
138023
138696
|
const paceRecord = PACE_TURNS.includes(turnsCompleted(game)) ? await mapRecordFor(ctx.dataDir, opts.env, game.settings?.mapId) : void 0;
|
|
138024
138697
|
const pace = paceRecord && paceRecord !== "unreadable" ? paceView(paceRecord, turnsCompleted(game), myIncome) : void 0;
|
|
138025
138698
|
return respond(view, VIEWS6, (rung) => ({
|
|
@@ -138646,6 +139319,8 @@ function registerTurnTools(server, ctx, opts = {}) {
|
|
|
138646
139319
|
})
|
|
138647
139320
|
);
|
|
138648
139321
|
if (belowPlan) warnings.push(belowPlan);
|
|
139322
|
+
const standInNote = standInLine(standInOf(ctx));
|
|
139323
|
+
if (standInNote) warnings.unshift(standInNote);
|
|
138649
139324
|
const merged = /* @__PURE__ */ new Map();
|
|
138650
139325
|
for (const d of deploys) {
|
|
138651
139326
|
const m = merged.get(d.territory.id);
|
|
@@ -139111,6 +139786,7 @@ async function myGamesSurrenders(ctx, games, me) {
|
|
|
139111
139786
|
const mine2 = g.players.find((p) => p.id === me);
|
|
139112
139787
|
return surrenderMayBePending(gameStateName(g.stateCode), mine2 ? playerStateName(mine2.stateCode) : void 0);
|
|
139113
139788
|
});
|
|
139789
|
+
for (const g of games) if (!eligible.includes(g)) byGame.set(g.id, []);
|
|
139114
139790
|
const read = eligible.slice(0, MAX_SURRENDER_READS);
|
|
139115
139791
|
for (let i2 = 0; i2 < read.length; i2 += SURRENDER_READ_BATCH) {
|
|
139116
139792
|
const batch = read.slice(i2, i2 + SURRENDER_READ_BATCH);
|
|
@@ -139136,7 +139812,7 @@ function registerMyGamesTool(server, ctx, deps = {}) {
|
|
|
139136
139812
|
{
|
|
139137
139813
|
title: "List my war.app games and which need me",
|
|
139138
139814
|
description: untrustedDescription(
|
|
139139
|
-
`Your war.app (Warzone) games, games waiting on you first: each with its id, name, state (WaitingForPlayers, DistributingTerritories, Playing, Finished), turn, players (name, state, whether they have committed this turn) and waitingOnYou \u2014 true when the game is being played or distributing territories, you are still playing, and you have not committed \u2014 and surrenderPending: the surrenders other players asked for that are still pending, each with owedByMe (true: waiting for you to accept it), read from the game details (unverified live; null when not read or unreadable, never "none"); the top-level surrenderPending counts the games where one waits on you, and those games come first too. Finished games are left out unless \`include_finished\` (\`finishedLeftOut\` counts them). \`listed\` is how many games war.app returned and \`complete\` false (with a \`warning\`) means the list may be partial. Use the id with the other warapp tools. Each call also gives up to two of your newest 250 finished games not yet processed their end-of-game pass (\`endOfGame\`: each game's history read once from GameFeed and kept name-free for later games; \`pending\` counts the rest). ${BRIDGE_NOTE} Read-only.`
|
|
139815
|
+
`Your war.app (Warzone) games, games waiting on you first: each with its id, name, state (WaitingForPlayers, DistributingTerritories, Playing, Finished), turn, players (name, state, whether they have committed this turn) and waitingOnYou \u2014 true when the game is being played or distributing territories, you are still playing, and you have not committed \u2014 and surrenderPending: the surrenders other players asked for that are still pending, each with owedByMe (true: waiting for you to accept it), read from the game details (unverified live; null when not read or unreadable, never "none"; empty without a read for a lobby, a finished game or a game you no longer play in, where none can wait on you); the top-level surrenderPending counts the games where one waits on you, and those games come first too. Finished games are left out unless \`include_finished\` (\`finishedLeftOut\` counts them). \`listed\` is how many games war.app returned and \`complete\` false (with a \`warning\`) means the list may be partial. Use the id with the other warapp tools. Each call also gives up to two of your newest 250 finished games not yet processed their end-of-game pass (\`endOfGame\`: each game's history read once from GameFeed and kept name-free for later games; \`pending\` counts the rest). ${BRIDGE_NOTE} Read-only.`
|
|
139140
139816
|
),
|
|
139141
139817
|
_meta: canonicalMeta("whats-new", ["my games", "warzone", "whose turn", "games waiting on me", "which games need me"]),
|
|
139142
139818
|
annotations: readAnnotations("List my war.app games"),
|
|
@@ -140668,6 +141344,11 @@ function registerChatTools(server, ctx, opts = {}) {
|
|
|
140668
141344
|
}
|
|
140669
141345
|
|
|
140670
141346
|
// src/tools/chat-inbox.ts
|
|
141347
|
+
var FINISHED_CLEAR_WINDOW = 3;
|
|
141348
|
+
function recentClearFinished(games) {
|
|
141349
|
+
const listed = new Set(chatGameIds(games));
|
|
141350
|
+
return games.filter((g) => g.stateCode === GAME_FINISHED && !listed.has(g.id)).map((g) => g.id).sort((a, b) => b - a).slice(0, FINISHED_CLEAR_WINDOW).sort((a, b) => a - b);
|
|
141351
|
+
}
|
|
140671
141352
|
var MAX_INBOX_GAMES = 10;
|
|
140672
141353
|
var MAX_INBOX_GAME_IDS = 100;
|
|
140673
141354
|
var DEFAULT_INBOX_LIMIT = 20;
|
|
@@ -140703,7 +141384,10 @@ function registerChatInboxTool(server, ctx) {
|
|
|
140703
141384
|
const list3 = given2 ? void 0 : await fetchMyGames(ctx);
|
|
140704
141385
|
const me = await chatMe(ctx);
|
|
140705
141386
|
const after = cursor === void 0 ? void 0 : Number(cursor);
|
|
140706
|
-
const
|
|
141387
|
+
const clearFinished = list3 ? recentClearFinished(list3.games) : [];
|
|
141388
|
+
const ids2 = (given2 ?? [...chatGameIds(list3.games), ...clearFinished].sort((a, b) => a - b)).filter(
|
|
141389
|
+
(id) => after === void 0 || id > after
|
|
141390
|
+
);
|
|
140707
141391
|
const batch = ids2.slice(0, max_games ?? MAX_INBOX_GAMES);
|
|
140708
141392
|
const n = limit ?? DEFAULT_INBOX_LIMIT;
|
|
140709
141393
|
const channels = [...CHAT_CHANNELS];
|
|
@@ -140730,9 +141414,12 @@ function registerChatInboxTool(server, ctx) {
|
|
|
140730
141414
|
}
|
|
140731
141415
|
sources.add(read.source);
|
|
140732
141416
|
const messages = fresh_.slice(-n).map((l) => shown(l, true, game.players, byInGame, me));
|
|
141417
|
+
const name = game.name === void 0 ? null : untrustedText(game.name);
|
|
140733
141418
|
withNew.push({
|
|
141419
|
+
// #322/#323: the game as warapp_get_chat nests it; the top-level keys stay for existing callers.
|
|
141420
|
+
game: { id: game.id, name, state: game.state },
|
|
140734
141421
|
id: game.id,
|
|
140735
|
-
name
|
|
141422
|
+
name,
|
|
140736
141423
|
state: game.state,
|
|
140737
141424
|
source: read.source,
|
|
140738
141425
|
...feedFillFields(read),
|
|
@@ -140766,6 +141453,10 @@ function registerChatInboxTool(server, ctx) {
|
|
|
140766
141453
|
finishedUnflagged: unflagged,
|
|
140767
141454
|
finishedNote: `${unflagged} finished game(s) in your list carry unread-chat flags this server could not read, so they are read like the rest rather than left out (the flags are not yet verified against war.app).`
|
|
140768
141455
|
} : {},
|
|
141456
|
+
...clearFinished.length ? {
|
|
141457
|
+
finishedClearChecked: clearFinished.length,
|
|
141458
|
+
finishedClearNote: `${clearFinished.length} recent finished game(s) are read although war.app's unread flag for their chat is clear: a message GameFeed alone holds (a surrender line, say) leaves that flag clear (#322). Only the ${FINISHED_CLEAR_WINDOW} newest finished games are read so; older ones go by the flag.`
|
|
141459
|
+
} : {},
|
|
140769
141460
|
...sources.size ? { sourceNotes: Object.fromEntries([...sources].map((s) => [s, CHAT_SOURCE_NOTES[s]])) } : {}
|
|
140770
141461
|
}));
|
|
140771
141462
|
}
|
|
@@ -140817,7 +141508,7 @@ function registerMarkChatReadTool(server, ctx) {
|
|
|
140817
141508
|
if (!read || read.source === "gamefeed") {
|
|
140818
141509
|
refuse(
|
|
140819
141510
|
`The chat of game ${game.id} could be read only from GameFeed, which gives no message ids, so nothing was sent.`,
|
|
140820
|
-
"
|
|
141511
|
+
"A message read from GameFeed carries no id, so war.app has nothing to mark for it. Read the game with warapp_get_chat: if its `source` is `web`, those messages can be marked; if it stays `gamefeed`, the web read failed or the signed-in account could not be read, and marking waits until it reads."
|
|
140821
141512
|
);
|
|
140822
141513
|
}
|
|
140823
141514
|
if (read.feedFill?.web === 0) {
|
|
@@ -141281,6 +141972,8 @@ function registerCheckPlanTool(server, ctx) {
|
|
|
141281
141972
|
});
|
|
141282
141973
|
const belowPlan = await bordersBelowPlan(ctx, { game, map: map2, me, turn, territories, info, history, teamsKnown, given: { deploys, moves } });
|
|
141283
141974
|
const warnings = [
|
|
141975
|
+
// The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
|
|
141976
|
+
...[standInLine(standInOf(ctx))].filter((w) => w !== void 0),
|
|
141284
141977
|
// #275 (b): an untrusted estimate is the first thing said (not under an explicit enemy_deploy).
|
|
141285
141978
|
...enemy_deploy === void 0 ? tripwireWarnings(trip.tripwires, (w) => untrustedOf.get(w.player) ?? untrustedDeploy(w, income), (p) => estimates.find((x) => x.playerId === p)?.estimate) : [],
|
|
141286
141979
|
...award ? assumedWarning(award) : [],
|
|
@@ -141629,6 +142322,10 @@ function registerGameTool(server, client, dir, env, identity) {
|
|
|
141629
142322
|
// src/tools/healthcheck.ts
|
|
141630
142323
|
var PROBE_PATH = `/API/GameFeed?GameID=${PROBE_GAME_ID}&GetMap=false`;
|
|
141631
142324
|
var BRIDGE_PROBE_PATH = "/";
|
|
142325
|
+
function withStandIn(health, deps) {
|
|
142326
|
+
const w = deps.standIn?.();
|
|
142327
|
+
return w ? { ...health, standIn: w } : health;
|
|
142328
|
+
}
|
|
141632
142329
|
function sessionSummary(env, now) {
|
|
141633
142330
|
const s = readSessionSync(env);
|
|
141634
142331
|
if (!s) return { linked: false };
|
|
@@ -141641,6 +142338,24 @@ function transportHealth(status, env, now) {
|
|
|
141641
142338
|
}
|
|
141642
142339
|
function registerHealthcheckTool(server, bridge2, direct, deps = {}) {
|
|
141643
142340
|
const now = deps.now ?? Date.now;
|
|
142341
|
+
let lastCheck = {};
|
|
142342
|
+
const checkSession = async () => {
|
|
142343
|
+
lastCheck = {};
|
|
142344
|
+
if (!direct.checkSession || direct.status().mode === "fetchproxy") return void 0;
|
|
142345
|
+
if (!readSessionSync(deps.env)) return void 0;
|
|
142346
|
+
const verdict = await direct.checkSession().catch(() => "unknown");
|
|
142347
|
+
if (verdict === "none") return void 0;
|
|
142348
|
+
const wall = direct.wall?.() ?? null;
|
|
142349
|
+
lastCheck = { sessionCheck: verdict, ...wall ? { wall } : {} };
|
|
142350
|
+
return verdict;
|
|
142351
|
+
};
|
|
142352
|
+
const health = () => withStandIn({ ...transportHealth(direct.status(), deps.env, now), ...lastCheck }, deps);
|
|
142353
|
+
const signedOut = () => new SessionExpiredError({ hostSignIn: readSessionSync(deps.env)?.origin === "host" });
|
|
142354
|
+
const classifySignedOut = (err) => err instanceof SessionExpiredError ? {
|
|
142355
|
+
kind: "session_expired",
|
|
142356
|
+
hint: "war.app shows the session the live tools use as signed out. " + (err.hostSignIn ? HOST_SIGN_IN_ADVICE : "Run warapp_link_session to relink.")
|
|
142357
|
+
} : void 0;
|
|
142358
|
+
let resolvedVerdict;
|
|
141644
142359
|
registerAdaptiveHealthcheckTool({
|
|
141645
142360
|
server,
|
|
141646
142361
|
prefix: "warapp",
|
|
@@ -141655,32 +142370,42 @@ function registerHealthcheckTool(server, bridge2, direct, deps = {}) {
|
|
|
141655
142370
|
bridge: {
|
|
141656
142371
|
probePath: BRIDGE_PROBE_PATH,
|
|
141657
142372
|
transport: () => bridge2.transport(),
|
|
141658
|
-
path:
|
|
142373
|
+
path: health,
|
|
141659
142374
|
probeFn: async (path) => {
|
|
141660
|
-
const
|
|
142375
|
+
const verdict = await checkSession();
|
|
142376
|
+
if (verdict === "signed-out") throw signedOut();
|
|
142377
|
+
const viaRouter = verdict === "signed-in" && direct.ready !== void 0;
|
|
142378
|
+
const leg = viaRouter ? await direct.ready() : await bridge2.ready();
|
|
142379
|
+
const res = await leg.fetch({ method: "GET", path });
|
|
141661
142380
|
if (res.status !== 200) {
|
|
141662
|
-
throw new McpToolError(`war.app answered HTTP ${res.status} through the bridge.`, {
|
|
142381
|
+
throw new McpToolError(`war.app answered HTTP ${res.status}${viaRouter ? "" : " through the bridge"}.`, {
|
|
141663
142382
|
status: res.status,
|
|
141664
142383
|
kind: "http"
|
|
141665
142384
|
});
|
|
141666
142385
|
}
|
|
141667
142386
|
return res.body;
|
|
141668
|
-
}
|
|
142387
|
+
},
|
|
142388
|
+
classifyThrown: classifySignedOut
|
|
141669
142389
|
},
|
|
141670
142390
|
credential: {
|
|
141671
142391
|
probePath: PROBE_PATH,
|
|
141672
142392
|
resolveCredential: async () => {
|
|
141673
|
-
|
|
142393
|
+
resolvedVerdict = await checkSession();
|
|
142394
|
+
const detail2 = health();
|
|
141674
142395
|
try {
|
|
141675
142396
|
readCredentials(deps.env);
|
|
141676
|
-
return { source: "env", detail:
|
|
142397
|
+
return { source: "env", detail: detail2 };
|
|
141677
142398
|
} catch (e) {
|
|
141678
|
-
if (e instanceof WarappConfigError) return { source: null, detail: { ...
|
|
142399
|
+
if (e instanceof WarappConfigError) return { source: null, detail: { ...detail2, reason: e.message } };
|
|
141679
142400
|
throw e;
|
|
141680
142401
|
}
|
|
141681
142402
|
},
|
|
141682
|
-
probeFn: () =>
|
|
141683
|
-
|
|
142403
|
+
probeFn: async () => {
|
|
142404
|
+
const res = await new WarappClient(deps).probeAuth();
|
|
142405
|
+
if (resolvedVerdict === "signed-out") throw signedOut();
|
|
142406
|
+
return res;
|
|
142407
|
+
},
|
|
142408
|
+
classifyThrown: (err) => err instanceof McpToolError && err.kind === "credential_rejected" ? { kind: "credential_rejected", hint: AUTH_FAILED_HINT } : classifySignedOut(err),
|
|
141684
142409
|
hints: { no_credential: `Set WARAPP_EMAIL and WARAPP_API_TOKEN (token from ${TOKEN_URL}).` }
|
|
141685
142410
|
}
|
|
141686
142411
|
});
|
|
@@ -142253,7 +142978,9 @@ function registerSessionTools(server, deps) {
|
|
|
142253
142978
|
return {
|
|
142254
142979
|
decoder: {
|
|
142255
142980
|
...d,
|
|
142256
|
-
...d.
|
|
142981
|
+
...d.standInFor ? {
|
|
142982
|
+
note: `war.app's current client (${d.standInFor.version}) cannot be read by this server, so the client release it was written for (still served by war.app) is decoding boards; war.app answers this server in that layout.`
|
|
142983
|
+
} : d.fallback ? { note: "A cached copy of war.app's client is decoding boards: the current version could not be looked up." } : {}
|
|
142257
142984
|
}
|
|
142258
142985
|
};
|
|
142259
142986
|
};
|
|
@@ -142271,11 +142998,13 @@ function registerSessionTools(server, deps) {
|
|
|
142271
142998
|
async () => {
|
|
142272
142999
|
if (hosted && hostToken === "ok") {
|
|
142273
143000
|
const pt2 = deps.pushTransport?.();
|
|
143001
|
+
const wall = deps.transport.wall?.() ?? null;
|
|
142274
143002
|
const base = {
|
|
142275
143003
|
hosted: true,
|
|
142276
143004
|
linked: true,
|
|
142277
143005
|
linkedBy: "host",
|
|
142278
143006
|
activeTransport: deps.transport.activeLeg(),
|
|
143007
|
+
...wall ? { wall } : {},
|
|
142279
143008
|
...pt2 ? { pushTransport: pt2 } : {},
|
|
142280
143009
|
...decoderView(),
|
|
142281
143010
|
hostedNote: NOTE_HOSTED_DIRECT
|
|
@@ -142304,7 +143033,16 @@ function registerSessionTools(server, deps) {
|
|
|
142304
143033
|
return respond(void 0, ["compact"], () => {
|
|
142305
143034
|
if (!session) return { linked: false, activeTransport, ...push, hint: HINT_NOT_LINKED };
|
|
142306
143035
|
const ageSeconds = Math.max(0, Math.round((now() - Date.parse(session.capturedAt)) / 1e3));
|
|
142307
|
-
const
|
|
143036
|
+
const wall = deps.transport.wall?.() ?? null;
|
|
143037
|
+
const base = {
|
|
143038
|
+
linked: true,
|
|
143039
|
+
host: session.host,
|
|
143040
|
+
capturedAt: session.capturedAt,
|
|
143041
|
+
ageSeconds,
|
|
143042
|
+
activeTransport,
|
|
143043
|
+
...wall ? { wall } : {},
|
|
143044
|
+
...push
|
|
143045
|
+
};
|
|
142308
143046
|
return deps.transport.sessionStale() ? { ...base, sessionExpired: true, hint: HINT_EXPIRED } : base;
|
|
142309
143047
|
});
|
|
142310
143048
|
}
|
|
@@ -143610,7 +144348,7 @@ function registerPushTools(server, ctx, push, deps = {}) {
|
|
|
143610
144348
|
{
|
|
143611
144349
|
title: "Wait for my turn in war.app games",
|
|
143612
144350
|
description: untrustedDescription(
|
|
143613
|
-
"Wait until one of the given war.app (Warzone) games is waiting on you \u2014 the game is being played or its territories picked, you are still playing, and you have not committed \u2014 and return as soon as it is, or at the timeout (default 300 s, max 1800 s) \u2014 or at once with `game_over` when every game has finished or your seat is out (each says why in `ended`). It checks each game once at the start, then listens to war.app's push notifications \u2014 over a direct WebSocket while a linked war.app session serves calls, else through your signed-in war.app tab (ContextMint Bridge) \u2014 and re-checks a game whenever war.app says it changed, and every game after the push socket reconnects. It also returns (status `surrender_pending`) when another player's surrender waits for you to accept it (each game's `surrenderPending`, read from the game details, unverified live: null when unreadable, never \"none\"; after one failed read it stops asking for the rest of the wait and says why in `surrenderUnread`), unless `ignore_surrenders`. Pass the game ids to watch (1\u201320), or omit them to watch every game of yours being played or picked (the first 20, as warapp_my_games lists them). Reports progress while it waits and stops when the call is cancelled. Then plan with warapp_plan_turn (or pick with warapp_submit_picks). Read-only."
|
|
144351
|
+
"Wait until one of the given war.app (Warzone) games is waiting on you \u2014 the game is being played or its territories picked, you are still playing, and you have not committed \u2014 and return as soon as it is, or at the timeout (default 300 s, max 1800 s) \u2014 or at once with `game_over` when every game has finished or your seat is out (each says why in `ended`). It checks each game once at the start, then listens to war.app's push notifications \u2014 over a direct WebSocket while a linked war.app session serves calls, else through your signed-in war.app tab (ContextMint Bridge) \u2014 and re-checks a game whenever war.app says it changed, and every game after the push socket reconnects. It also returns (status `surrender_pending`) when another player's surrender waits for you to accept it (each game's `surrenderPending`, read from the game details, unverified live: null when unreadable, never \"none\"; empty without a read for a lobby, a finished game or one you no longer play in; after one failed read it stops asking for the rest of the wait and says why in `surrenderUnread`), unless `ignore_surrenders`. Pass the game ids to watch (1\u201320), or omit them to watch every game of yours being played or picked (the first 20, as warapp_my_games lists them). Reports progress while it waits and stops when the call is cancelled. Then plan with warapp_plan_turn (or pick with warapp_submit_picks). Read-only."
|
|
143614
144352
|
),
|
|
143615
144353
|
_meta: mintMeta("whats-new", ["is it my turn", "wait for my turn", "tell me when it is my turn", "warzone turn ready"]),
|
|
143616
144354
|
annotations: readAnnotations("Wait for my war.app turn"),
|
|
@@ -146894,7 +147632,7 @@ function registerAllTools(server, deps = {}) {
|
|
|
146894
147632
|
// The cached signed-in account is discarded whenever the account behind the router may have changed.
|
|
146895
147633
|
identity: () => bridge2.identityState()
|
|
146896
147634
|
});
|
|
146897
|
-
registerHealthcheckTool(server, fetchproxy, bridge2, deps);
|
|
147635
|
+
registerHealthcheckTool(server, fetchproxy, bridge2, { ...deps, standIn: () => live.decoderReport()?.standIn });
|
|
146898
147636
|
registerGameTool(server, client, () => dataDir(deps.env), deps.env, () => live.myInviteToken());
|
|
146899
147637
|
registerMapTool(server, client, live);
|
|
146900
147638
|
registerMapStatsTool(server, {
|
|
@@ -146943,6 +147681,7 @@ function registerAllTools(server, deps = {}) {
|
|
|
146943
147681
|
transport: {
|
|
146944
147682
|
activeLeg: () => bridge2.status().transport,
|
|
146945
147683
|
sessionStale: () => bridge2.sessionStale(),
|
|
147684
|
+
wall: () => bridge2.wall(),
|
|
146946
147685
|
sessionLinked: () => bridge2.sessionLinked()
|
|
146947
147686
|
},
|
|
146948
147687
|
pushTransport: () => push.status().transport,
|