@s2script/sdk 0.2.0 → 0.3.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/clients.d.ts CHANGED
@@ -27,6 +27,13 @@ export declare class Client {
27
27
  readonly ip: string;
28
28
  /** Show `reason` (chat + console) once the client is in-game, then kick after `delaySeconds` (default 5). Intended to be called from a Clients.onConnect handler. */
29
29
  kickWithReason(reason: string, delaySeconds?: number): void;
30
+ /**
31
+ * Server-side voice mute: while true, this client's OUTGOING voice is silenced for every receiver.
32
+ * Framework state (not an engine field): cleared automatically on disconnect, persists across map
33
+ * changes while connected. If the voice descriptor is degraded (hook/validation failure — named
34
+ * reason in the server log), setting is an inert no-op and reads stay false.
35
+ */
36
+ voiceMuted: boolean;
30
37
  }
31
38
  export declare const Clients: {
32
39
  /** Fires when a client connects (all clients incl. bots; carries name/xuid). May be async. */
@@ -41,6 +48,12 @@ export declare const Clients: {
41
48
  onDisconnect(handler: (client: Client) => void): void;
42
49
  /** Fires when a client's settings (name/cvars) change. */
43
50
  onSettingsChanged(handler: (client: Client) => void): void;
51
+ /**
52
+ * Fires while a client transmits voice. Throttled to at most one dispatch per client per second;
53
+ * the FIRST packet of a transmission always fires (a lazy mute-on-talk lands immediately).
54
+ * Handlers should be idempotent. Never fires for bots.
55
+ */
56
+ onVoice(handler: (client: Client) => void): void;
44
57
  /** The client in `slot`, or null if the slot is empty. */
45
58
  fromSlot(slot: number): Client | null;
46
59
  /** Every currently-connected client. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s2script/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "s2script SDK — the builtin capability types (imported as @s2script/sdk/entity, …) plus the `s2s` CLI for building Source 2 / CS2 plugins.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -103,6 +103,9 @@
103
103
  "./translations": {
104
104
  "types": "./translations.d.ts"
105
105
  },
106
+ "./transmit": {
107
+ "types": "./transmit.d.ts"
108
+ },
106
109
  "./usercmd": {
107
110
  "types": "./usercmd.d.ts"
108
111
  },
package/transmit.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /** @s2script/transmit — per-client entity visibility filtering (Source2 CheckTransmit).
2
+ * Declarative rules: a plugin says "this entity is visible only to these viewer slots" and the
3
+ * engine-side hook enforces it every snapshot — zero JS runs in the per-client hot path. */
4
+ import type { EntityRef } from "./entity";
5
+
6
+ export interface TransmitStats {
7
+ /** CheckTransmit invocations observed since load/reset. */
8
+ snapshots: number;
9
+ /** Live rule entries in the native table. */
10
+ entries: number;
11
+ /** Total transmit bits cleared since load/reset. */
12
+ bitsCleared: number;
13
+ /** Nanoseconds spent in the post-hook, last invocation. */
14
+ nsLast: number;
15
+ /** Worst single invocation (ns) since load/reset. */
16
+ nsMax: number;
17
+ }
18
+
19
+ export declare const Transmit: {
20
+ /** Replace this plugin's visibility rule for `entity`: it is transmitted ONLY to the given viewer
21
+ * slots (an empty array = hidden from everyone). Multiple plugins AND-merge — an entity reaches a
22
+ * viewer only if every plugin holding a rule on it allows that viewer. Returns false if the ref is
23
+ * stale or the capability is unavailable/disabled. Throws RangeError on a slot outside [0, 64). */
24
+ setVisibleTo(entity: EntityRef, viewers: readonly number[]): boolean;
25
+ /** Remove this plugin's rule for `entity` (visible to all again, as far as this plugin is
26
+ * concerned). Returns false if the ref is stale or the capability is unavailable. */
27
+ reset(entity: EntityRef): boolean;
28
+ /** Remove all of this plugin's rules. */
29
+ resetAll(): void;
30
+ /** Hot-path counters for measurement/debugging. */
31
+ stats(): TransmitStats;
32
+ };
package/usermessages.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { HookResultValue } from "./events";
2
+
1
3
  /** A general protobuf user-message builder. Build then send in one synchronous burst. */
2
4
  export class UserMessage {
3
5
  constructor(name: string);
@@ -12,3 +14,36 @@ export class UserMessage {
12
14
  /** Broadcast to all connected non-bot clients. */
13
15
  sendAll(): boolean;
14
16
  }
17
+
18
+ // --- UserMessage interception (usermsg-hook slice) ---
19
+
20
+ /** A BLOCK-SCOPED view of an intercepted outbound user message — valid only during a
21
+ * UserMessages.onPre handler; across an await (or stashed) all reads return null/[]/"". */
22
+ export interface UserMessageView {
23
+ /** Canonical unscoped message name (e.g. "CMsgTEFireBullets"). */
24
+ readonly name: string;
25
+ /** Numeric network-message id (e.g. 452). */
26
+ readonly id: number;
27
+ /** Recipient slots (0-based) this post targets; a broadcast decodes to all live slots. Read-only in v1. */
28
+ readonly recipients: number[];
29
+ /** protobuf TextFormat dump — the documented FALLBACK for unmapped messages only; prefer typed reads. */
30
+ readonly debugString: string;
31
+ hasField(path: string): boolean;
32
+ /** Scalar int read (int32/uint32/fixed32/enum; bool as 0/1). Dotted nested paths supported
33
+ * ("origin.x" walks sub-messages). null = no such field / repeated / no current message. */
34
+ readInt(path: string): number | null;
35
+ readFloat(path: string): number | null;
36
+ readBool(path: string): boolean | null;
37
+ readString(path: string): string | null;
38
+ }
39
+
40
+ export declare const UserMessages: {
41
+ /** Pre-hook an outbound user message by unscoped name (partial match, SayText2-style; the view
42
+ * carries the canonical name). Runs SYNCHRONOUSLY before delivery. Return >= HookResult.Handled
43
+ * to SUPPRESS the send for every recipient; Continue/undefined passes it through. THROWS at
44
+ * subscribe time on an unresolvable name or a degraded intercept descriptor. */
45
+ onPre(name: string, handler: (msg: UserMessageView) => HookResultValue | void): void;
46
+ /** Removes ALL of the calling plugin's handlers for this name (mux off semantics — handler
47
+ * identity not compared, matching Events.off). */
48
+ off(name: string, handler?: (msg: UserMessageView) => HookResultValue | void): void;
49
+ };