Raised This Month: $51 Target: $400
 12% 

SteamWorks


Post New Thread Reply   
 
Thread Tools Display Modes
Disowned
Member
Join Date: Oct 2015
Old 01-26-2016 , 20:24   Re: SteamWorks
Reply With Quote #11

Some oddities, SteamTools and SteamWorks have about the same includes, however SteamWorks has better checking for error handling but is vulnerable to exposing server information if you don't get the size of the response before getting the data of it.

An example of this is when I ran
PHP Code:
SteamWorks_GetHTTPResponseBodyData(hRequestbodybuffer10000
I got some server parameters and garbled data back. So you have to make sure to use
PHP Code:
SteamWorks_GetHTTPResponseBodySize(hRequestbodysize
and provide GetHTTPReponseBodyData with the bodysize variable.

There are a lot of other smaller differences and improvements SteamWorks has, here is an example I got working with some error checking.

PHP Code:
#include <sourcemod>
#include <steamworks>

public OnPluginStart()
{
    
RegServerCmd("send"sendRequest);
}

public 
Action sendRequest(args) {
    
char[] sURL "http://asd.overcore.eu/ahoj.php";

    
//Get handle
    
Handle HTTPRequest SteamWorks_CreateHTTPRequest(k_EHTTPMethodGETsURL);

    
//Set timeout to 10 seconds
    
bool setnetwork SteamWorks_SetHTTPRequestNetworkActivityTimeout(HTTPRequest10);
    
//Set a Get parameter, makes URL look like: http://asd.overcore.eu/ahoj.php?parameter=12345
    
bool setparam SteamWorks_SetHTTPRequestGetOrPostParameter(HTTPRequest"parameter""12345");
    
//Set a header value because we can
    
bool setheader SteamWorks_SetHTTPRequestHeaderValue(HTTPRequest"server""TestFuton");
    
//SteamWorks thing, set context value so we know what call we sent for the callback.
    
bool setcontext SteamWorks_SetHTTPRequestContextValue(HTTPRequest5);
    
//Set callback function to get response data
    
bool setcallback SteamWorks_SetHTTPCallbacks(HTTPRequestgetCallback);


    if(!
setnetwork || !setparam || !setheader || !setcontext || !setcallback) {
        
PrintToServer("Error in setting request properties, cannot send request");
        
CloseHandle(HTTPRequest);
        return 
Plugin_Handled;
    }

    
//Initialize the request.
    
bool sentrequest SteamWorks_SendHTTPRequest(HTTPRequest);
    if(!
sentrequest) {
        
PrintToServer("Error in sending request, cannot send request");
        
CloseHandle(HTTPRequest);
        return 
Plugin_Handled;
    }


    
//Send the request to the front of the queue
    
SteamWorks_PrioritizeHTTPRequest(HTTPRequest);
    return 
Plugin_Handled;
}

public 
getCallback(Handle:hRequestbool:bFailurebool:bRequestSuccessfulEHTTPStatusCode:eStatusCodeany:data1) {

    if(!
bRequestSuccessful) {
        
PrintToServer("There was an error in the request");
        
CloseHandle(hRequest);
        return;
    }

    if(
eStatusCode == k_EHTTPStatusCode200OK) {
        
PrintToServer("The request returned new data, http code 200");
        
CloseHandle(hRequest);
    } else if(
eStatusCode == k_EHTTPStatusCode304NotModified) {
        
PrintToServer("The request did not return new data, but did not error, http code 304");
        
CloseHandle(hRequest);
        return;
    } else if(
eStatusCode == k_EHTTPStatusCode404NotFound) {
        
PrintToServer("The requested URL could not be found, http code 404");
        
CloseHandle(hRequest);
        return;
    } else if(
eStatusCode == k_EHTTPStatusCode500InternalServerError) {
        
PrintToServer("The requested URL had an internal error, http code 500");
        
CloseHandle(hRequest);
        return;
    } else {
        
char errmessage[128];
        
Format(errmessage128"The requested returned with an unexpected HTTP Code %d"eStatusCode);
        
PrintToServer(errmessage);
        
CloseHandle(hRequest);
        return;
    }

    
int headersize;
    
bool headerexists SteamWorks_GetHTTPResponseHeaderSize(hRequest"customreceivedheader"headersize);
    if(
headerexists == false) {
        
PrintToServer("received header 'customreceivedheader' does not exist");
    } else {
        
//If header exists, print its value.
        
char buffer[64];
        
bool headerexist2 SteamWorks_GetHTTPResponseHeaderValue(hRequest"customreceivedheader"bufferheadersize);
        if(
headerexist2 == true) {
            
PrintToServer(buffer);
        } else {
            
PrintToServer("some error in getting header after we got size");   
        }
    }

    
int bodysize;
    
bool bodyexists SteamWorks_GetHTTPResponseBodySize(hRequestbodysize);
    if(
bodyexists == false) {
        
PrintToServer("Could not get body response size");
        
CloseHandle(hRequest);
        return;
    }

    
char bodybuffer[10000];
    if(
bodysize 10000) {
        
PrintToServer("The requested URL returned with more data than expected");
        
CloseHandle(hRequest);
        return;
    }

    
bool gotdata SteamWorks_GetHTTPResponseBodyData(hRequestbodybufferbodysize);
    if(
gotdata == false) {
        
PrintToServer("Could not get body data or body data is blank");
        
CloseHandle(hRequest);
        return;
    }

    
//Print successfull response to server.
    
PrintToServer(bodybuffer);
    
CloseHandle(hRequest);

This includes some example functions to play with if you're developing a little api to send data based upon input.

If you're interested in really knowing whats going on behind the scenes and whats available to you, checkout the SteamWorks.inc file under '/addons/sourcemod/scripting/includes', along with looking at the functions from https://github.com/KyleSanderson/SteamWorks which will use functions from
https://github.com/alliedmodders/hl2...3/public/steam that have some amount of documentation. I just use notepad++ and the CTRL+F 'Find in Files' function.

Last edited by Disowned; 01-27-2016 at 16:55.
Disowned is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 01-27-2016 , 00:20   Re: SteamWorks
Reply With Quote #12

Quote:
Originally Posted by Disowned View Post
Some oddities, SteamTools and SteamWorks have about the same includes, however SteamWorks has better checking for error handling but is vulnerable to exposing server information if you don't get the size of the response before getting the data of it.

An example of this is when I ran
PHP Code:
SteamWorks_GetHTTPResponseBodyData(hRequestbodybuffer10000
I got some server parameters and garbled data back. So you have to make sure to use
PHP Code:
SteamWorks_GetHTTPResponseBodySize(hRequestbodysize
and provide GetHTTPReponseBodyData with the bodysize variable.

There are a lot of other smaller differences and improvements SteamWorks has, here is an example I got working with some error checking.

PHP Code:
#include <sourcemod>
#include <steamworks>

public OnPluginStart()
{
    
RegServerCmd("send"sendRequest);
}

public 
Action sendRequest(args) {
    
char[] sURL "http://asd.overcore.eu/ahoj.php";

    
//Get handle
    
Handle HTTPRequest SteamWorks_CreateHTTPRequest(k_EHTTPMethodGETsURL);

    
//Set timeout to 10 seconds
    
bool setnetwork SteamWorks_SetHTTPRequestNetworkActivityTimeout(HTTPRequest10);
    
//Set a Get parameter, makes URL look like: http://asd.overcore.eu/ahoj.php?parameter=12345
    
bool setparam SteamWorks_SetHTTPRequestGetOrPostParameter(HTTPRequest"parameter""12345");
    
//Set a header value because we can
    
bool setheader SteamWorks_SetHTTPRequestHeaderValue(HTTPRequest"server""TestFuton");
    
//SteamWorks thing, set context value so we know what call we sent for the callback.
    
bool setcontext SteamWorks_SetHTTPRequestContextValue(HTTPRequest5);
    
//Set callback function to get response data
    
bool setcallback SteamWorks_SetHTTPCallbacks(HTTPRequestgetCallback);


    if(!
setnetwork || !setparam || !setheader || !setcontext || !setcallback) {
        
PrintToServer("Error in setting request properties, cannot send request");
        
CloseHandle(HTTPRequest);
        return 
Plugin_Handled;
    }

    
//Initialize the request.
    
bool sentrequest SteamWorks_SendHTTPRequest(HTTPRequest);
    if(!
sentrequest) {
        
PrintToServer("Error in sending request, cannot send request");
        
CloseHandle(HTTPRequest);
        return 
Plugin_Handled;
    }


    
//Send the request to the front of the queue
    
SteamWorks_PrioritizeHTTPRequest(HTTPRequest);
    return 
Plugin_Handled;
}

public 
getCallback(Handle:hRequestbool:bFailurebool:bRequestSuccessfulEHTTPStatusCode:eStatusCodeany:data1) {

    if(!
bRequestSuccessful) {
        
PrintToServer("There was an error in the request");
        
CloseHandle(hRequest);
        return;
    }

    if(
eStatusCode == k_EHTTPStatusCode200OK) {
        
PrintToServer("The request returned new data, http code 200");
    } else if(
eStatusCode == k_EHTTPStatusCode304NotModified) {
        
PrintToServer("The request did not return new data, but did not error, http code 304");
        return;
    } else if(
eStatusCode == k_EHTTPStatusCode404NotFound) {
        
PrintToServer("The requested URL could not be found, http code 404");
        return;
    } else if(
eStatusCode == k_EHTTPStatusCode500InternalServerError) {
        
PrintToServer("The requested URL had an internal error, http code 500");
        return;
    } else {
        
char errmessage[128];
        
Format(errmessage128"The requested returned with an unexpected HTTP Code %d"eStatusCode);
        
PrintToServer(errmessage);
        
CloseHandle(hRequest);
        return;
    }

    
int headersize;
    
bool headerexists SteamWorks_GetHTTPResponseHeaderSize(hRequest"customreceivedheader"headersize);
    if(
headerexists == false) {
        
PrintToServer("received header 'customreceivedheader' does not exist");
    } else {
        
//If header exists, print its value.
        
char buffer[64];
        
bool headerexist2 SteamWorks_GetHTTPResponseHeaderValue(hRequest"customreceivedheader"bufferheadersize);
        if(
headerexist2 == true) {
            
PrintToServer(buffer);
        } else {
            
PrintToServer("some error in getting header after we got size");   
        }
    }

    
int bodysize;
    
bool bodyexists SteamWorks_GetHTTPResponseBodySize(hRequestbodysize);
    if(
bodyexists == false) {
        
PrintToServer("Could not get body response size");
        
CloseHandle(hRequest);
        return;
    }

    
char bodybuffer[10000];
    if(
bodysize 10000) {
        
PrintToServer("The requested URL returned with more data than expected");
        
CloseHandle(hRequest);
        return;
    }

    
bool gotdata SteamWorks_GetHTTPResponseBodyData(hRequestbodybufferbodysize);
    if(
gotdata == false) {
        
PrintToServer("Could not get body data or body data is blank");
        
CloseHandle(hRequest);
        return;
    }

    
//Print successfull response to server.
    
PrintToServer(bodybuffer);
    
CloseHandle(hRequest);

This includes some example functions to play with if you're developing a little api to send data based upon input.

If you're interested in really knowing whats going on behind the scenes and whats available to you, checkout the SteamWorks.inc file under '/addons/sourcemod/scripting/includes', along with looking at the functions from https://github.com/KyleSanderson/SteamWorks which will use functions from
https://github.com/alliedmodders/hl2...3/public/steam that have some amount of documentation. I just use notepad++ and the CTRL+F 'Find in Files' function.

Wow guys, I really appreciate it!! And thanks for few examples!!

Edit: Thanks a log guys !! Works !!

Last edited by ESK0; 01-27-2016 at 11:37.
ESK0 is offline
Reply



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 15:07.


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