GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rob5300/SMSocketEvents: Websocket + json based sourcemod event system (source engine)

BranchesTags
Open more actions menu

Latest commit

 

History

23 Commits
23 Commits

Folders and files

NameName
Last commit message
Last commit date
ext
ext
 
 
sp/include
sp/include
 
 
src
src
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
Makefile
Makefile
 
 
PackageScript
PackageScript
 
 
readme.md
readme.md
 
 
sdk.vcxproj
sdk.vcxproj
 
 
sdk.vcxproj.filters
sdk.vcxproj.filters
 
 
sdk.vcxproj.user
sdk.vcxproj.user
 
 
socket_ext.sln
socket_ext.sln
 
 
tcp_readme.md
tcp_readme.md
 
 
vcpkg-configuration.json
vcpkg-configuration.json
 
 
vcpkg.json
vcpkg.json
 
 

Repository files navigation

Sockets Extension

A sourcemod native extension.

Invoke custom events on your soucemod server with custom data via websockets as JSON (or raw TCP) and listen to them from source pawn.

Uses boost beast, boost asio and openssl.

How to use

Websockets

Connect your websocket client to the configured port (443 or 80). Invoke events by sending JSON to the server. Currently only one client is supported at once.

Message format

Events are sent as JSON. The event name is required as event alongwith any arguments as an object args.

int, bool, float, string, objects and arrays are supported as arguments. Example:

{
    "event": "myEventName",
    "args": {
        "someInt": 5,
        "name": "rob5300",
        "subObject": {
            "numbers": [1,2,3]
        }
    },
    "token": "mytoken123"
}

If enabled you must also provide a valid token as token (these are user configured in the extension config).

Response

The websocket server will reply with a message to indicate success or failiure of parsing and processing the last event message in the format:

{
    "success": false,
    "message": "Some error message"
}

Recieving event in SourcePawn

Use AddEventListener() to subscribe to an event with a specific name. The EventArgs object argument contains the data from the event payload similarly to KeyValues.

The event args object has many functions to get your data as a string, int, bool and float. Arrays are also supported. If you have objects within objects then these can be retrieved as EventArg objects. Similarly to KeyValues, you can specify a path as a key to get values quickly from nested objects.

EventArgs objects must be disposed of when no longer used, these are Handles.

Example of listening to an event in sourcepawn and getting data:

public void OnPluginStart()
{
    AddEventListener("my_event", EventCallback1);
}

void EventCallback1(EventArgs args)
{
    char value[256];
    if(args.GetString("string", value, 256))
    {
        LogAction(0, -1, "string: %s", value);
    }

    if(args.GetString("player/name", value, 256))
    {
        LogAction(0, -1, "Player name: %s", value);
    }

    int num = args.GetInt("int");
    IntToString(num, value, 256);
    LogAction(0, -1, "int: %i", num);

    delete args;
}

TCP

Check tcp_readme.md for info on how to use raw TCP mode.

Config

Configuration is read from sourcemod/configs/socketevents.json and is JSON. Below is a sample of the config:

{
    "port": 443,  //Port to bind and listen to
    "websockets": true,  //If websockets should be used
    "eventsPerFrame": 4,  //How many events max per game tick to send to listeners
    "tokens": [
        "mytoken123"
    ]
}

Building

Ensure you have the required dependencies for building Sourcemod. Ambuild is not used by this project.

Metamod, Sourcemod and hl2sdk-tf2 are needed. These need to be in the same directory as this project (../sourcemod, ../hl2sdk-tf2, ../mmsource-1.10)

Linux:

Install/update g++ gcc g++-multilib gcc-multilib libboost-all-dev openssl:i386 via your package manager.

Use the provided make file via make. Requires GCC 8+ (Ambuild cannot be used).

Windows:

Install vcpkg and install from manifest: vcpkg install --triplet x86-windows. This will install boost asio and openssl

Open and build using the solution file (socket_ext.sln) in VS 2022+ with the latest windows 10/11 sdk.

About

Websocket + json based sourcemod event system (source engine)

Topics

cppjsonsource-enginesourcemodsourcemod-extensionvalvewebsockets

Resources

Readme
Activity

Stars

4 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.