Raised This Month: $32 Target: $400
 8% 

Solved SteamWorks - array in POST


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dtn
Junior Member
Join Date: Apr 2018
Old 06-20-2018 , 19:23   SteamWorks - array in POST
Reply With Quote #1

Hello

I am new to SourceMod, and I want to create an array based on the number of clients connected to the server and send it through SteamWorks POST.

But I simply can't figure it out. Can anyone assist me in this?

First, I tried the following, but each line basically replaces the one before, so I would only receive "VAL3".
PHP Code:
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data[]""VAL1");
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data[]""VAL2");
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data[]""VAL3"); 
Then I tried the following, but get error "error 048: array (s do not match":
PHP Code:
char data[3][64];

data[0] = "VAL1";
data[1] = "VAL1";
data[2] = "VAL1";

SteamWorks_SetHTTPRequestGetOrPostParameter(req"data"data); 

Last edited by dtn; 06-22-2018 at 05:41.
dtn is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 06-21-2018 , 05:44   Re: SteamWorks - array in POST
Reply With Quote #2

Quote:
Originally Posted by dtn View Post
Hello

I am new to SourceMod, and I want to create an array based on the number of clients connected to the server and send it through SteamWorks POST.

But I simply can't figure it out. Can anyone assist me in this?

First, I tried the following, but each line basically replaces the one before, so I would only receive "VAL3".
PHP Code:
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data[]""VAL1");
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data[]""VAL2");
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data[]""VAL3"); 

Then I tried the following, but get error "error 048: array (s do not match":
PHP Code:
char data[3][64];

data[0] = "VAL1";
data[1] = "VAL1";
data[2] = "VAL1";

SteamWorks_SetHTTPRequestGetOrPostParameter(req"data"data); 
I'd create a JSON string and the pass it, you could use SMJansson to do so.


EDIT:
You might do something like this:
PHP Code:
    /* We're gonna create this JSON String:
    {
        "data": [
            "VAL1",
            "VAL2",
            "VAL3"
        ]
    } 
    */
    
Handle JSONObj json_object();
    
Handle JSONArr json_array();
    
json_array_append_new(JSONArrjson_string("VAL1"));
    
json_array_append_new(JSONArrjson_string("VAL2"));
    
json_array_append_new(JSONArrjson_string("VAL3"));
    
json_object_set_new(JSONObj"data"JSONArr);
    
    
char sJSON[1024];
    
json_dump(JSONObjsJSONsizeof(sJSON));
    
ReplyToCommand(clientsJSON);
    
    
    
    
    
/* Initialize your request ...*/
    
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data"sJSON);
    
/* ... Send your request */ 
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 06-21-2018 at 06:06. Reason: Added snippet
Papero is offline
dtn
Junior Member
Join Date: Apr 2018
Old 06-22-2018 , 05:41   Re: SteamWorks - array in POST
Reply With Quote #3

Quote:
Originally Posted by Papero View Post
I'd create a JSON string and the pass it, you could use SMJansson to do so.


EDIT:
You might do something like this:
PHP Code:
    /* We're gonna create this JSON String:
    {
        "data": [
            "VAL1",
            "VAL2",
            "VAL3"
        ]
    } 
    */
    
Handle JSONObj json_object();
    
Handle JSONArr json_array();
    
json_array_append_new(JSONArrjson_string("VAL1"));
    
json_array_append_new(JSONArrjson_string("VAL2"));
    
json_array_append_new(JSONArrjson_string("VAL3"));
    
json_object_set_new(JSONObj"data"JSONArr);
    
    
char sJSON[1024];
    
json_dump(JSONObjsJSONsizeof(sJSON));
    
ReplyToCommand(clientsJSON);
    
    
    
    
    
/* Initialize your request ...*/
    
SteamWorks_SetHTTPRequestGetOrPostParameter(req"data"sJSON);
    
/* ... Send your request */ 
This is amazing. Never thought about using SMJansson.

Works like a charm. Thank you so much!
dtn is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 07-03-2018 , 11:10   Re: SteamWorks - array in POST
Reply With Quote #4

Code:
SteamWorks_SetHTTPRequestGetOrPostParameter(hRequest, "data[1]", "VAL1");
SteamWorks_SetHTTPRequestGetOrPostParameter(hRequest, "data[2]", "VAL2");
SteamWorks_SetHTTPRequestGetOrPostParameter(hRequest, "data[3]", "VAL3");
Node server receives:

PHP Code:
{data: [ 'VAL1''VAL2''VAL3' ] } 
__________________
Pelipoika is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:11.


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