Skip to content

Commit ec9c821

Browse files
committed
feat: add TLS/SSL configuration, proxy support, and connection statistics
 Major features: - Add TLS/SSL configuration API for WebSocket client, server, and HTTP requests - SetTLSCertAndKey, SetTLSCAFile, SetTLSCiphers methods - HostnameValidation property for certificate verification - Add proxy support (HTTP/HTTPS/SOCKS5) for WebSocket and HTTP clients - SetProxy, ClearProxy methods and HasProxy property - Add connection statistics for WebSocket client (for debug) - MessagesSent/Received, BytesSent/Received, PingsSent/Received, etc. - Add timeout configuration options - PingTimeout, IdleTimeout, SendTimeout, CloseTimeout, HandshakeTimeout - Add HTTP authentication methods (SetBasicAuth, SetBearerAuth, ClearAuth) - Add WebSocket subprotocol support (AddSubProtocol, RemoveSubProtocol, ClearSubProtocols) - Add connection pooling and keep-alive options for HTTP requests - Add write_flg parameter to WriteJSON for JSON formatting control (closes #10)  Build system: - Rebuild OpenSSL static libraries - Add NOMINMAX define for Windows to fix std::min/max conflicts - Add /ignore:4099 linker flag to suppress PDB warnings  Refactoring: - Rename ws_natives.cpp to ws_natives_client.cpp for clarity - Split ws.inc into ws_client.inc and ws_server.inc for better organization - Convert IXWebSocket and zlib to git submodules - Move AMBuilder files for third-party libraries to root third_party directory - Rename WebsocketState enum to WebSocketState for consistency - Replace DisableDeflate/IsDeflateEnabled with PerMessageDeflate property - Change default ping interval to -1 (disabled) for WebSocket server  Documentation: - Update README with proxy support, SSL dependencies, and build instructions - Add comprehensive API documentation for new features - Add WSS (WebSocket Secure) server example script - Note about forked IXWebSocket with core modifications
1 parent 2489932 commit ec9c821

240 files changed

Lines changed: 21028 additions & 52594 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[submodule "third_party/ixwebsocket"]
2+
path = third_party/ixwebsocket
3+
url = https://github.com/ProjectSky/IXWebSocket.git
4+
branch = cpp17-refactor
5+
[submodule "third_party/zlib"]
6+
path = third_party/zlib
7+
url = https://github.com/madler/zlib.git

AMBuildScript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class ExtensionConfig(object):
156156
'user32.lib',
157157
'gdi32.lib',
158158
'advapi32.lib',
159+
'/ignore:4099' # PDB warnings
159160
]
160161

161162
if builder.options.opt == '1':
@@ -186,6 +187,7 @@ class ExtensionConfig(object):
186187
cxx.defines += [
187188
'_WINDOWS',
188189
'_WIN32_WINNT=0x0601',
190+
'NOMINMAX',
189191
]
190192

191193
def Library(self, context, compiler, name):

AMBuilder

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
22
import os
33

4-
ixwebsocket = builder.Build('third_party/ixwebsocket/AMBuilder')
5-
libz = builder.Build('third_party/zlib/AMBuilder')
4+
ixwebsocket = builder.Build('third_party/ixwebsocket.AMBuilder')
5+
libz = builder.Build('third_party/zlib.AMBuilder')
66

77
for cxx in builder.targets:
88
binary = Extension.Library(builder, cxx, 'websocket.ext')
@@ -14,15 +14,15 @@ for cxx in builder.targets:
1414
'src/ws_server.cpp',
1515
'src/http_request.cpp',
1616
'src/http_natives.cpp',
17-
'src/ws_natives.cpp',
17+
'src/ws_natives_client.cpp',
1818
'src/ws_natives_server.cpp',
1919
os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp'),
2020
]
2121

2222
binary.compiler.includes += [
2323
os.path.join(builder.sourcePath, 'src'),
2424
os.path.join(builder.sourcePath, 'public'),
25-
os.path.join(builder.sourcePath, 'third_party', 'ixwebsocket'),
25+
os.path.join(builder.sourcePath, 'third_party', 'ixwebsocket', 'ixwebsocket'),
2626
os.path.join(builder.sourcePath, 'third_party', 'zlib'),
2727
]
2828

PackageScript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ CopyFiles('scripting/include', 'addons/sourcemod/scripting/include',
4444
[ 'websocket.inc']
4545
)
4646
CopyFiles('scripting/include/websocket', 'addons/sourcemod/scripting/include/websocket',
47-
[ 'ws.inc', 'http.inc']
47+
[ 'http.inc', 'ws_client.inc', 'ws_server.inc']
4848
)

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
This is a [SourceMod](http://www.sourcemod.net/) extension that provides some methods for HTTP JSON and websocket communication
55

66
## Features
7-
* Relies on [IXWebSocket](https://github.com/machinezone/IXWebSocket) which is C++ library for WebSocket client and server development. It has minimal dependencies
7+
* Relies on [IXWebSocket](https://github.com/ProjectSky/IXWebSocket/tree/cpp17-refactor) which is C++ library for WebSocket client and server development. It has minimal dependencies
88
* Support TEXT and JSON data
99
* Support client and server
1010
* Support permessage-deflate
1111
* Support SSL
1212
* Support x64
13+
* Support Proxy (HTTP/SOCKS5)
1314
* Support HTTP RESTful API with JSON and form data
1415

1516
## Dependencies
1617
* [sm-ext-json](https://github.com/ProjectSky/sm-ext-json) - **Optional**. Required only for JSON-related features. If not installed, TEXT-based WebSocket communication and non-JSON HTTP features will still work
18+
* **For Linux users** - **Required**: SSL/TLS support requires OpenSSL development packages
19+
- For x64: `libssl-dev`
20+
- For x86: `libssl-dev:i386`
1721

1822
## Installation
1923
1. **(Optional)** If you need JSON functionality, download and install [sm-ext-json](https://github.com/ProjectSky/sm-ext-json/releases) first
@@ -24,8 +28,9 @@ This is a [SourceMod](http://www.sourcemod.net/) extension that provides some me
2428
``` sh
2529
sudo dpkg --add-architecture i386
2630
sudo apt-get update
27-
sudo apt-get install clang g++-multilib zlib1g-dev zlib1g-dev:i386 libssl-dev libssl-dev:i386
28-
clone project
31+
sudo apt-get install clang g++-multilib libssl-dev libssl-dev:i386
32+
git clone --recursive https://github.com/ProjectSky/sm-ext-websocket.git
33+
cd sm-ext-websocket
2934
mkdir build && cd build
3035
python ../configure.py --enable-optimize --symbol-files --sm-path=YOU_SOURCEMOD_PATH --targets=x86,x64
3136
ambuild
@@ -44,9 +49,13 @@ ambuild
4449
- [x] HTTP support
4550
- [x] Use sourcemod extension interface for JSON functionality instead of bundling json library
4651
- [x] Allow JSON library as an optional dependency
52+
- [x] TLS/SSL configuration API
53+
- [x] Proxy support
54+
- [x] Include IXWebSocket and libz via git submodules
4755

4856
## NOTES
4957
* Server will not process data during the hibernation. You can set sv_hibernate_when_empty to 0 to disable hibernation
58+
* This extension uses a [forked version of IXWebSocket](https://github.com/ProjectSky/IXWebSocket/tree/cpp17-refactor) with significant core modifications to support new features (proxy, connection pooling, statistics, timeouts, etc.). The upstream IXWebSocket library is not compatible with this extension
5059

5160
## Example
5261
* [Example Script](https://github.com/ProjectSky/sm-ext-websocket/tree/main/scripting)

scripting/http_test.sp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void OnPluginStart()
2121

2222
Action http_get(int args)
2323
{
24-
HttpRequest request = new HttpRequest("https://httpbin.org/get");
24+
HttpRequest request = new HttpRequest("http://127.0.0.1");
2525
request.AddHeader("User-Agent", "SourceMod HTTP Client");
2626
request.Get(OnHttpResponse);
2727
return Plugin_Handled;

scripting/include/websocket.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <json>
88
#define REQUIRE_EXTENSIONS
99
#include <websocket/http>
10-
#include <websocket/ws>
10+
#include <websocket/ws_client>
11+
#include <websocket/ws_server>
1112

1213
public Extension __ext_websocket = {
1314
name = "websocket",

0 commit comments

Comments
 (0)