@modlock/modlock 0.1.80 → 0.1.82
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/index.d.ts +35 -22
- package/index.js +72 -23
- package/package.json +6 -6
- package/players.d.ts +6 -4
- package/strays.d.ts +6 -0
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference path="./globals.d.ts" />
|
|
2
|
-
import { type DamageEvent, type ChatEvent, type
|
|
3
|
-
import { Cast } from './cast.js';
|
|
2
|
+
import { type DamageEvent, type ChatEvent, type DamagedEvent, type DamageResult, type FrameEvent, type ImpactEvent, type LandedEvent, type LaunchEvent, type Pawn, Player, type PlayerJoinedEvent, type PlayerLeftEvent } from './host.gen.js';
|
|
4
3
|
export * as vector from './vector.js';
|
|
5
4
|
export { Buttons, Layers } from './bits.js';
|
|
6
5
|
export { after, every, sequence, type Timer } from './timer.js';
|
|
@@ -86,35 +85,49 @@ export declare function onPlayerLeave(handler: (left: PlayerLeftEvent) => void):
|
|
|
86
85
|
* handler is registered.
|
|
87
86
|
*/
|
|
88
87
|
export declare function onSpawn(handler: (player: Player, pawn: Pawn) => void): void;
|
|
89
|
-
/** Seating is
|
|
88
|
+
/** Seating is the hero and team seat gives one player. */
|
|
90
89
|
export interface Seating {
|
|
91
90
|
/**
|
|
92
|
-
* hero is
|
|
93
|
-
*
|
|
94
|
-
*
|
|
91
|
+
* hero is the hero's name as players know it or as the game does, such as
|
|
92
|
+
* 'haze' or 'hero_haze', its id, or 'any' for the hero the player has or
|
|
93
|
+
* else a random one. 'any' is the default.
|
|
95
94
|
*/
|
|
96
95
|
readonly hero?: string | number;
|
|
97
96
|
/**
|
|
98
|
-
* team is the team, 2 or 3
|
|
99
|
-
*
|
|
100
|
-
* side with fewer heroes.
|
|
97
|
+
* team is the team, 2 or 3. Without one the player keeps their hero's team
|
|
98
|
+
* or joins the side with fewer heroes.
|
|
101
99
|
*/
|
|
102
|
-
readonly team?: number
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
readonly team?: number;
|
|
101
|
+
}
|
|
102
|
+
declare module './host.gen.js' {
|
|
103
|
+
interface Player {
|
|
104
|
+
/**
|
|
105
|
+
* connection returns the player's connection: their name, Steam ID,
|
|
106
|
+
* whether they are a bot and whether they finished joining. It returns
|
|
107
|
+
* undefined when nobody holds the slot.
|
|
108
|
+
*/
|
|
109
|
+
connection(): Connection | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* seat gives the player a hero on a team, skipping the game's team and
|
|
112
|
+
* hero screens. Call it as the player joins:
|
|
113
|
+
*
|
|
114
|
+
* onPlayerJoin(({ connection }) => connection.player.seat({ hero: 'haze', team: 2 }))
|
|
115
|
+
*
|
|
116
|
+
* The hero appears on a later frame, and onSpawn hears of it. The library
|
|
117
|
+
* asks the game again until the player has the seat, and once more after
|
|
118
|
+
* the player changes hero, so a call before the game is ready is not
|
|
119
|
+
* lost. Seating the player again replaces the seat, and it ends when they
|
|
120
|
+
* leave. It returns false when nobody holds the player's slot.
|
|
121
|
+
*/
|
|
122
|
+
seat(seating?: Seating): boolean;
|
|
123
|
+
}
|
|
108
124
|
}
|
|
109
125
|
/**
|
|
110
|
-
*
|
|
111
|
-
* game's
|
|
112
|
-
* game
|
|
113
|
-
* player again after a hero change. It returns the Cast that does the
|
|
114
|
-
* seating, whose members are the players' connections, and runs it each
|
|
115
|
-
* frame itself.
|
|
126
|
+
* setRespawnDelay brings every fallen hero back after seconds, in place of
|
|
127
|
+
* the game's own respawn time. Without seconds it leaves fallen heroes to the
|
|
128
|
+
* game again.
|
|
116
129
|
*/
|
|
117
|
-
export declare function
|
|
130
|
+
export declare function setRespawnDelay(seconds?: number): void;
|
|
118
131
|
/** onFrame calls handler once per server frame. */
|
|
119
132
|
export declare function onFrame(handler: (frame: FrameEvent) => void): void;
|
|
120
133
|
/**
|
package/index.js
CHANGED
|
@@ -14761,8 +14761,12 @@ function watchPlayers(watcher) {
|
|
|
14761
14761
|
if (roster !== void 0) watcher(roster);
|
|
14762
14762
|
}
|
|
14763
14763
|
function connection(player) {
|
|
14764
|
+
const held = roster ?? players();
|
|
14765
|
+
if (typeof player === "bigint") {
|
|
14766
|
+
return held.find((c) => c.steamId === player);
|
|
14767
|
+
}
|
|
14764
14768
|
const slot = typeof player === "number" ? player : player.slot;
|
|
14765
|
-
return
|
|
14769
|
+
return held.find((c) => c.player.slot === slot);
|
|
14766
14770
|
}
|
|
14767
14771
|
function players() {
|
|
14768
14772
|
if (roster !== void 0) return roster.slice();
|
|
@@ -17564,11 +17568,11 @@ function fewestPlayed(standings) {
|
|
|
17564
17568
|
return least === Infinity ? 0 : least;
|
|
17565
17569
|
}
|
|
17566
17570
|
function nextMatch(line2, size, standing) {
|
|
17567
|
-
const
|
|
17568
|
-
if (size < 1 ||
|
|
17571
|
+
const seated2 = [...line2].sort((a, b) => standing(a).played - standing(b).played).slice(0, 2 * size);
|
|
17572
|
+
if (size < 1 || seated2.length < 2 * size) {
|
|
17569
17573
|
return void 0;
|
|
17570
17574
|
}
|
|
17571
|
-
const ranked =
|
|
17575
|
+
const ranked = seated2.sort((a, b) => standing(b).rating - standing(a).rating);
|
|
17572
17576
|
const sides = [[], []];
|
|
17573
17577
|
for (const [i, player] of ranked.entries()) {
|
|
17574
17578
|
const round = Math.floor(i / 2);
|
|
@@ -17656,6 +17660,12 @@ var strayBlow = 1e6;
|
|
|
17656
17660
|
var Strays = class {
|
|
17657
17661
|
/** since maps each stray pawn to when it was first seen with no player. */
|
|
17658
17662
|
since = /* @__PURE__ */ new Map();
|
|
17663
|
+
/**
|
|
17664
|
+
* gone holds the controller handles strays name that no longer resolve. A
|
|
17665
|
+
* handle carries its entity's serial, so it never resolves again, and each
|
|
17666
|
+
* failed read logs on the host: a sweep reads it once.
|
|
17667
|
+
*/
|
|
17668
|
+
gone = /* @__PURE__ */ new Set();
|
|
17659
17669
|
sweptAt = -Infinity;
|
|
17660
17670
|
/**
|
|
17661
17671
|
* sweep lays down each hero pawn that has belonged to no player for
|
|
@@ -17675,8 +17685,9 @@ var Strays = class {
|
|
|
17675
17685
|
}
|
|
17676
17686
|
}
|
|
17677
17687
|
const since = /* @__PURE__ */ new Map();
|
|
17688
|
+
const gone = /* @__PURE__ */ new Set();
|
|
17678
17689
|
for (const entity of findEntities("player")) {
|
|
17679
|
-
if (held.has(entity) || ownHero(entity)) {
|
|
17690
|
+
if (held.has(entity) || ownHero(entity, this.gone, gone)) {
|
|
17680
17691
|
continue;
|
|
17681
17692
|
}
|
|
17682
17693
|
const first = this.since.get(entity) ?? now4;
|
|
@@ -17686,9 +17697,10 @@ var Strays = class {
|
|
|
17686
17697
|
}
|
|
17687
17698
|
}
|
|
17688
17699
|
this.since = since;
|
|
17700
|
+
this.gone = gone;
|
|
17689
17701
|
}
|
|
17690
17702
|
};
|
|
17691
|
-
function ownHero(entity) {
|
|
17703
|
+
function ownHero(entity, known2, seen) {
|
|
17692
17704
|
const controller = readField(
|
|
17693
17705
|
entity,
|
|
17694
17706
|
"CBasePlayerPawn",
|
|
@@ -17698,6 +17710,10 @@ function ownHero(entity) {
|
|
|
17698
17710
|
if (typeof controller !== "number") {
|
|
17699
17711
|
return false;
|
|
17700
17712
|
}
|
|
17713
|
+
if (known2.has(controller)) {
|
|
17714
|
+
seen.add(controller);
|
|
17715
|
+
return false;
|
|
17716
|
+
}
|
|
17701
17717
|
const connected = readField(
|
|
17702
17718
|
controller,
|
|
17703
17719
|
"CBasePlayerController",
|
|
@@ -17713,6 +17729,9 @@ function ownHero(entity) {
|
|
|
17713
17729
|
"m_hHeroPawn",
|
|
17714
17730
|
"handle"
|
|
17715
17731
|
);
|
|
17732
|
+
if (connected === void 0 && hero === void 0) {
|
|
17733
|
+
seen.add(controller);
|
|
17734
|
+
}
|
|
17716
17735
|
return hero === entity;
|
|
17717
17736
|
}
|
|
17718
17737
|
function layDown(entity) {
|
|
@@ -19017,27 +19036,57 @@ function onSpawn(handler) {
|
|
|
19017
19036
|
spawns.push(handler);
|
|
19018
19037
|
}
|
|
19019
19038
|
var spawned = /* @__PURE__ */ new Map();
|
|
19020
|
-
|
|
19021
|
-
|
|
19022
|
-
|
|
19023
|
-
|
|
19039
|
+
var seated = /* @__PURE__ */ new Map();
|
|
19040
|
+
var respawnDelay;
|
|
19041
|
+
var unseated = {};
|
|
19042
|
+
var seating;
|
|
19043
|
+
function startSeating() {
|
|
19044
|
+
if (seating) {
|
|
19045
|
+
return;
|
|
19046
|
+
}
|
|
19024
19047
|
const cast = new Cast({
|
|
19025
|
-
join(connection2)
|
|
19026
|
-
|
|
19027
|
-
|
|
19028
|
-
|
|
19029
|
-
|
|
19030
|
-
...respawn === void 0 ? {} : { respawn }
|
|
19031
|
-
});
|
|
19032
|
-
return connection2;
|
|
19048
|
+
join: (connection2) => connection2,
|
|
19049
|
+
leave(member) {
|
|
19050
|
+
if (seated.get(member.player.slot)?.generation === member.generation) {
|
|
19051
|
+
seated.delete(member.player.slot);
|
|
19052
|
+
}
|
|
19033
19053
|
},
|
|
19034
|
-
|
|
19035
|
-
|
|
19054
|
+
want(member) {
|
|
19055
|
+
const held = seated.get(member.player.slot);
|
|
19056
|
+
return held?.generation === member.generation ? held.want : unseated;
|
|
19036
19057
|
},
|
|
19037
|
-
|
|
19058
|
+
bots: "join"
|
|
19038
19059
|
});
|
|
19060
|
+
seating = cast;
|
|
19039
19061
|
onFrame(({ timeSeconds }) => cast.frame(timeSeconds));
|
|
19040
|
-
|
|
19062
|
+
}
|
|
19063
|
+
function wantOf(seating2) {
|
|
19064
|
+
return {
|
|
19065
|
+
hero: seating2.hero ?? "any",
|
|
19066
|
+
...seating2.team === void 0 ? {} : { team: seating2.team },
|
|
19067
|
+
...respawnDelay === void 0 ? {} : { respawn: respawnDelay }
|
|
19068
|
+
};
|
|
19069
|
+
}
|
|
19070
|
+
Player.prototype.connection = function() {
|
|
19071
|
+
return connection(this);
|
|
19072
|
+
};
|
|
19073
|
+
Player.prototype.seat = function(seating2 = {}) {
|
|
19074
|
+
const held = connection(this);
|
|
19075
|
+
if (!held) {
|
|
19076
|
+
return false;
|
|
19077
|
+
}
|
|
19078
|
+
seated.set(this.slot, { generation: held.generation, want: wantOf(seating2) });
|
|
19079
|
+
startSeating();
|
|
19080
|
+
return true;
|
|
19081
|
+
};
|
|
19082
|
+
function setRespawnDelay(seconds) {
|
|
19083
|
+
respawnDelay = seconds;
|
|
19084
|
+
unseated = seconds === void 0 ? {} : { respawn: seconds };
|
|
19085
|
+
for (const held of seated.values()) {
|
|
19086
|
+
const { respawn: _, ...want } = held.want;
|
|
19087
|
+
held.want = { ...want, ...unseated };
|
|
19088
|
+
}
|
|
19089
|
+
startSeating();
|
|
19041
19090
|
}
|
|
19042
19091
|
function watchSpawns() {
|
|
19043
19092
|
const present = /* @__PURE__ */ new Map();
|
|
@@ -19395,13 +19444,13 @@ export {
|
|
|
19395
19444
|
rosterKey,
|
|
19396
19445
|
rosterRows,
|
|
19397
19446
|
route,
|
|
19398
|
-
seatPlayers,
|
|
19399
19447
|
sequence,
|
|
19400
19448
|
serve,
|
|
19401
19449
|
serveMod,
|
|
19402
19450
|
serverCommand,
|
|
19403
19451
|
setFreeForAll,
|
|
19404
19452
|
setOrbitCamera,
|
|
19453
|
+
setRespawnDelay,
|
|
19405
19454
|
setTeamSeating,
|
|
19406
19455
|
settingNumber,
|
|
19407
19456
|
settingOn,
|
package/package.json
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"name": "@modlock/modlock",
|
|
9
9
|
"optionalDependencies": {
|
|
10
|
-
"@modlock/darwin-arm64": "0.1.
|
|
11
|
-
"@modlock/darwin-x64": "0.1.
|
|
12
|
-
"@modlock/linux-arm64": "0.1.
|
|
13
|
-
"@modlock/linux-x64": "0.1.
|
|
14
|
-
"@modlock/win32-x64": "0.1.
|
|
10
|
+
"@modlock/darwin-arm64": "0.1.82",
|
|
11
|
+
"@modlock/darwin-x64": "0.1.82",
|
|
12
|
+
"@modlock/linux-arm64": "0.1.82",
|
|
13
|
+
"@modlock/linux-x64": "0.1.82",
|
|
14
|
+
"@modlock/win32-x64": "0.1.82"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"type": "module",
|
|
22
22
|
"types": "index.d.ts",
|
|
23
|
-
"version": "0.1.
|
|
23
|
+
"version": "0.1.82"
|
|
24
24
|
}
|
package/players.d.ts
CHANGED
|
@@ -7,11 +7,13 @@ export declare function keepPlayers(players: Connection[]): void;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function watchPlayers(watcher: (players: readonly Connection[]) => void): void;
|
|
9
9
|
/**
|
|
10
|
-
* connection returns the connection of one player, given the player
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* connection returns the connection of one player, given the player, their
|
|
11
|
+
* slot as a number or their Steam ID as a bigint: their name, Steam ID,
|
|
12
|
+
* whether they are a bot and whether they finished joining. It returns
|
|
13
|
+
* undefined when nobody holds the slot or the account is not connected. Its
|
|
14
|
+
* player field is the Player to call.
|
|
13
15
|
*/
|
|
14
|
-
export declare function connection(player: Player | number): Connection | undefined;
|
|
16
|
+
export declare function connection(player: Player | number | bigint): Connection | undefined;
|
|
15
17
|
/**
|
|
16
18
|
* players lists the occupied player slots in slot order. It answers from the
|
|
17
19
|
* roster the host last reported, and asks the host until a report arrives.
|
package/strays.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export declare const strayGraceSeconds = 3;
|
|
|
7
7
|
export declare class Strays {
|
|
8
8
|
/** since maps each stray pawn to when it was first seen with no player. */
|
|
9
9
|
private since;
|
|
10
|
+
/**
|
|
11
|
+
* gone holds the controller handles strays name that no longer resolve. A
|
|
12
|
+
* handle carries its entity's serial, so it never resolves again, and each
|
|
13
|
+
* failed read logs on the host: a sweep reads it once.
|
|
14
|
+
*/
|
|
15
|
+
private gone;
|
|
10
16
|
private sweptAt;
|
|
11
17
|
/**
|
|
12
18
|
* sweep lays down each hero pawn that has belonged to no player for
|