since there isnt a tutorial on how to post data using sockets i took my time and came up with something simple:
Code:
#include <amxmodx>
#include <json>
#include <sockets>
new socket, error
new const webhook_url[] = "webhook.site"
new const webhook_path[] = "/b616d41a-c1b6-4eaa-bad7-bf045b026161"
public plugin_init()
register_srvcmd("f", "upload_data")
public plugin_end()
socket_close(socket)
public upload_data()
{
new JSON:object = json_init_object()
new JSON:array = json_init_array()
new JSON:player[MAX_PLAYERS + 1]
socket = socket_open(webhook_url, 80, SOCKET_TCP, error)
new hostname[64]
get_cvar_string("hostname", hostname, charsmax(hostname))
json_object_set_string(object, "hostname", hostname)
json_object_set_number(object, "maxplayers", get_maxplayers())
json_object_set_number(object, "online", get_playersnum())
json_object_set_number(object, "admins", admins_num())
json_object_set_value(object, "players", array)
new players[MAX_PLAYERS], num, id
get_players(players, num)
for (new i = 0; i < num; i++)
{
id = players[i]
if (is_user_connected(id))
{
player[i] = json_init_object()
json_object_set_string(player[i], "name", fmt("%n", id))
json_object_set_number(player[i], "kills", get_user_frags(id))
json_object_set_number(player[i], "deaths", get_user_deaths(id))
json_object_set_number(player[i], "time", get_user_time(id))
json_array_append_value(array, player[i])
}
}
new json_data[1024]
json_serial_to_string(object, json_data, charsmax(json_data), true)
new data[2048]
formatex(data, charsmax(data),
"POST %s HTTP/1.1^r^n\
Host: %s^r^n\
Accept: application/json^r^n\
Content-Type: application/json^r^n\
Content-Length: %d^r^n^r^n\
%s", webhook_path, webhook_url, strlen(json_data), json_data
)
socket_send(socket, data, charsmax(data))
}