Skip to content

Port getHWID/getCod2xProtocol and HTTP/WebSocket client functions from cod2x#10

Open
nawaftahir wants to merge 4 commits into
ibuddieat:devfrom
nawaftahir:cod2x
Open

Port getHWID/getCod2xProtocol and HTTP/WebSocket client functions from cod2x#10
nawaftahir wants to merge 4 commits into
ibuddieat:devfrom
nawaftahir:cod2x

Conversation

@nawaftahir

@nawaftahir nawaftahir commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Adds async HTTP(S) and WebSocket clients callable from GSC, plus the getHWID / getCod2xProtocol player functions from cod2x.

  • httpFetch(url, method, data, headers, timeoutSeconds, onDone, onError)
  • webSocketConnect(url, headers, onConnect, onMessage, onClose, onError, [reconnectMs], [pingMs])
  • webSocketSendText(id, msg)
  • webSocketClose(id)
  • <player> getHWID()
  • <player> getCod2xProtocol()

libwebsockets drives network I/O directly from the server frame, keeping all callbacks on the main script thread.

Earlier I used Mongoose (https://github.com/cesanta/mongoose) which was convenient since it has built-in TLS and is easy to vendor, but its GPL-2.0 license conflicted with libcod's MIT license. Switching to libwebsockets resolves the conflict but requires a TLS backend, so this adds mbedTLS (https://github.com/Mbed-TLS/mbedtls) statically linked. libwebsockets is a CMake project, so the build now also requires cmake. It's added as a git submodule pinned to v4.5.8 (Ubuntu lacks an i386 package for it) and is automatically initialized during the build.

It's also optional via doit.sh. Running ./doit.sh http turns on both HTTP and WebSockets (off by default). Requires cmake + libmbedtls-dev:i386. Tested on Ubuntu 24.04 (mbedTLS 2.28).

Testing:
Ran 36 GSC test cases covering HTTP (methods, 404/500, dns/refused/timeout/oversized/bad-url) and WebSockets (echo, 5KB, burst, reconnect, server-close, oversized-drop, self-signed wss). Also ran an adversarial pass with wrong GSC types (structs/entities/arrays), bad IDs, slot exhaustion, 15 concurrent requests, and injection URLs. The server survives it.

For testing there's a GSC script plus a small WebSocket echo server here

Docs:
Added doc/http_websocket.md, updated doc/setup.md, and added 4 script reference pages under a new Network category. Player methods under existing Player Catergory.

@nawaftahir nawaftahir marked this pull request as ready for review July 12, 2026 16:00
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