Port getHWID/getCod2xProtocol and HTTP/WebSocket client functions from cod2x#10
Open
nawaftahir wants to merge 4 commits into
Open
Port getHWID/getCod2xProtocol and HTTP/WebSocket client functions from cod2x#10nawaftahir wants to merge 4 commits into
nawaftahir wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds async HTTP(S) and WebSocket clients callable from GSC, plus the
getHWID/getCod2xProtocolplayer 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
libwebsocketsresolves the conflict but requires a TLS backend, so this adds mbedTLS (https://github.com/Mbed-TLS/mbedtls) statically linked.libwebsocketsis a CMake project, so the build now also requirescmake. 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 httpturns on both HTTP and WebSockets (off by default). Requirescmake+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, updateddoc/setup.md, and added 4 script reference pages under a new Network category. Player methods under existing Player Catergory.