Skip to content

Use rhai for most protocol implementations - #945

Draft
qdot wants to merge 7 commits into
devfrom
rhai-protocols-2
Draft

Use rhai for most protocol implementations#945
qdot wants to merge 7 commits into
devfrom
rhai-protocols-2

Conversation

@qdot

@qdot qdot commented Sep 2, 2026

Copy link
Copy Markdown
Member

No description provided.

qdot added 7 commits August 31, 2026 23:27
…er plumbing

- Hardened shared rhai engine: no module resolution (import/eval rejected at
  parse time), operation/call-depth/size budgets
- Fail-soft loader with structured per-file load report; duplicate protocol
  names resolve first-file-wins; missing dir is a no-op, unreadable/non-dir
  path errors
- ScriptedProtocolHandler implements ProtocolHandler with per-connection
  state bound to this; strict command-map validation (endpoint, byte range,
  command id UUIDs); missing handlers map to UnhandledCommand, script errors
  to DeviceSpecificError with a stable 'Rhai protocol <name>: ' prefix
- ServerDeviceManagerBuilder.script_protocol_directory option threaded into
  the device manager event loop; scripts override same-name built-ins
- New ButtplugServerError::ScriptProtocolLoadError variant
- ProtocolManager::from_map augmentation constructor
- Unit tests covering registration/override, parity with the Rust aneros/
  jejoue/maxpro impls, fail-soft loading, runtime error containment, op-limit
  termination, per-connection state isolation, and command-id semantics
- Shipped script assets: aneros.rhai, jejoue.rhai, maxpro.rhai
…arness

- DeviceTestCase gains optional script_protocol_directory, resolved relative
  to the crate manifest and applied to the ServerDeviceManagerBuilder in all
  five client version builders (v0-v4)
- aneros and jejoue YAML cases point at the shipped script directory
- new test_maxpro_protocol.yaml (CRC-bearing bytes from the maxpro impl)
- new test_script_protocol.yaml: novel-name script protocol (scripttest) with
  its own test-only device config; no Rust fallback exists, so passing proves
  the script plumbing end to end
- register jejoue/maxpro/script cases in the 8 matrices that run aneros
  (embedded/JSON x v1-v4); v0 blocks keep the multi-vibrator exclusion
… field note

- crates/buttplug_server/docs/script-protocols.md: authoritative v1 script
  contract (metadata, init_state, handlers, command maps, error mapping,
  language subset and engine limits) with the shipped maxpro example
- CHANGELOG: 11.1.0 entry for the rhai-protocols feature and new public APIs
- buttplug_tests CLAUDE.md: document the script_protocol_directory YAML field
- .gitignore: un-ignore crates/buttplug_server/docs (bare 'docs' rule is for
  generated book output)
- cfg(test)-gate the ScriptedProtocolHandler import in the loader
- rely on auto-deref when binding the state guard to this
- drop unused test fixture constant
- Replace the std package's sleep(INT)/sleep(FLOAT) with immediate errors:
  thread-blocking sleep consumes no operations and would bypass every budget
  (tests cover both load-time and handler-time rejection)
- Route print/debug into the server log instead of raw stdout
- Bound loading: max 1 MiB per script file, max 256 files per directory
  (excess skipped with structured reasons)
- Set explicit engine caps for defined functions (1024) and live variables
  (1024)
- Validate init_state() templates recursively against an allowlist of
  deeply-cloning value types, so per-connection state copies can never alias
  through shared cells or function pointers (regression tests: nested state
  isolation, FnPtr rejection)
- Gate the whole script module out of wasm builds (feature + target cfg)
- Record directory-entry inspection errors in the structured report instead
  of dropping them
- Pin remaining conversion branches in tests: multi-command returns, Blob
  data, write_with_response, signed rotate/temperature dispatch,
  position-with-duration, and float-data rejection
- Update docs with the new limits and behaviors
The not(target_arch = "wasm32") predicate on pub mod script was lost to a
formatting cleanup; with it restored, enabling rhai-protocols on wasm no
longer compiles the script module at all (the manager logs and ignores a
configured directory there).
@qdot
qdot marked this pull request as draft September 2, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant