AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [AMXX] Server Informations (https://forums.alliedmods.net/showthread.php?t=346231)

EFFx 02-15-2024 17:12

[AMXX] Server Informations
 
2 Attachment(s)
Not sure where it should be located so I posted here.

This plugin passes server informations to your website without a database. It uses Easy HTTP module to pass some basics informations through HTTP Request. It is avaliable both linux and windows.

1. Install serverResponse.php into your website.
2. Install the module
3. Add your website link on the constant

PHP Code:

new const g_szWebsite[] = "http://www.yourwebsite.com" 

4. Compile your plugin and install it
5. Each 60 seconds the plugin makes the request to your website.
6. The PHP file will format the informations as JSON
7. Use it as you wish. More informations can be added.

-

This is just a simple way of using Easy HTTP. It can be used for more useful things such as the Auto Plugin Updater I built before. Also, by using ezhttp_get_data you can get the response of the PHP, opening more doors like being useful to use php API's from your website to get some informations AMXX can't, like Bypass Guard does by getting AS with gRIP.

EasyHTTP can also read json files and parse it flawlessly as well, such an underrated module.

EFFx 02-15-2024 17:13

Re: [AMXX] Server Informations
 
Reserved.

The JSON format will be saved like this:

PHP Code:

{
    
"IP:PORT": {
        
"server""Server Name",
        
"map""de_dust2",
        
"players""0",
        
"playersmax""32",
        
"ip""IP:PORT"
    
}


It can also hold more servers informations than just one. Currently using it for my pug mod to get servers informations, such as mode description (Warmup, Knife Round, Live, etc), also match scoreboard and so on.

----------------

(22.02.2024)

Updated main post with a Full-working PHP example which checks the IP passed to the Web API. Also, a simple way to display the existing informations inside the JSON file for starters.

mlibre 02-28-2024 16:52

Re: [AMXX] Server Informations
 
an alternative method would be the gt API, whose functions return all the data mentioned above. This does not require installing anything on the server, simply that the IP exists in its database.

EFFx 02-29-2024 05:47

Re: [AMXX] Server Informations
 
Quote:

Originally Posted by EFFx (Post 2818092)
This is just a simple way of using Easy HTTP. It can be used for more useful things such as the Auto Plugin Updater I built before. Also, by using ezhttp_get_data you can get the response of the PHP, opening more doors like being useful to use php API's from your website to get some informations AMXX can't, like Bypass Guard does by getting AS with gRIP.

SourceQuery from xPaw or LGSL is way better of getting informations without any third-party files installation in the server, the api you mentioned sucks.

mlibre 02-29-2024 08:04

Re: [AMXX] Server Informations
 
Quote:

Originally Posted by EFFx (Post 2818782)
SourceQuery from xPaw or LGSL is way better...

I think this API gt is easier to use than others, it also uses the JSON method, because I say it is an alternative, because not all hosts allow "Query" or "Sockets" output as a "security" measure, so, if you are limited this could help.

EFFx 02-29-2024 08:47

Re: [AMXX] Server Informations
 
Quote:

Originally Posted by mlibre (Post 2818785)
because not all hosts allow "Query" or "Sockets" output as a "security" measure

That's true, been there.

Problem with gametracker.rs API, not to mention that it is slow af, is that is it not accurate. A lot of servers are displayed as offline and there is no way of contacting them.

bigdaddy424 03-05-2024 13:10

Re: [AMXX] Server Informations
 
you should be able to accomplish this without 3rd party modules, instead parse the json object in header using socekts

bigdaddy424 03-05-2024 21:30

Re: [AMXX] Server Informations
 
since there isnt a tutorial on how to post data using sockets i took my time and came up with something simple:
https://i.ibb.co/CWGk589/Screenshot-...P-requests.png
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)) }

EFFx 03-06-2024 07:10

Re: [AMXX] Server Informations
 
Quote:

Originally Posted by bigdaddy424 (Post 2819018)
you should be able to accomplish this without 3rd party modules, instead parse the json object in header using socekts

As mentioned before, it was not supposed to be just a basic plugin that sends server informations to your website.

Quote:

Originally Posted by bigdaddy424 (Post 2819042)
since there isnt a tutorial on how to post data using sockets i took my time and came up with something simple:
https://i.ibb.co/CWGk589/Screenshot-...P-requests.png
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)) }

JSON tutorials are hard to find, the more, the better.


All times are GMT -4. The time now is 17:51.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.