From 818ac0454c4b8e3abe28ed4fab411c50c3421e05 Mon Sep 17 00:00:00 2001 From: turret Date: Sat, 30 Mar 2024 21:25:45 -0500 Subject: ex/hello: identify i PROMISE that there will be a stupid easy way to identify to the websocket, consisting probably of the user just declaring the intents somewhere (since we already have the token) welcome to the true beginnings of DBS (new acronym for this project instead of the lame TDBS since im not that cool) --- example/hello.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'example/hello.c') diff --git a/example/hello.c b/example/hello.c index f192a52..fe208d5 100644 --- a/example/hello.c +++ b/example/hello.c @@ -1,16 +1,40 @@ #include +#include +#include #include +#include #include #include +extern CURL *ws_handle; + int hello(cJSON *data) { - char *string = cJSON_Print(data); - print("hello, world!"); - print("hello data: %s", string); - free(string); + cJSON *ev_payload = cJSON_CreateObject(); + cJSON *ev_data = cJSON_CreateObject(); + cJSON_AddNumberToObject(ev_payload, "op", 2); + cJSON_AddItemToObject(ev_payload, "d", ev_data); + + cJSON_AddStringToObject(ev_data, "token", getenv("TOKEN")); + cJSON_AddNumberToObject(ev_data, "intents", 0); + + cJSON *properties = cJSON_CreateObject(); + cJSON_AddItemToObject(ev_data, "properties", properties); + cJSON_AddStringToObject(properties, "browser", "DBS"); + cJSON_AddStringToObject(properties, "device", "DBS"); + + struct utsname unamed; + uname(&unamed); + cJSON_AddStringToObject(properties, "os", unamed.sysname); + + char *msg = cJSON_PrintUnformatted(ev_payload); + size_t sent; + curl_ws_send(ws_handle, msg, strlen(msg), &sent, 0, CURLWS_TEXT); + free(msg); + cJSON_Delete(ev_payload); + print("hello: sent IDENT"); return 0; } -- cgit v1.2.3