I'm experimenting with steamworks, trying to retrieve stats for a game via sourcepawn.
The problem is the buffer size I need to store all the stats. Everything I've tried hasn't worked so far.
Code:
char sBody[20000];
[SM] Exception reported: Not enough space on the stack
Code:
char sBody[30000];
[SM] Exception reported: Instruction contained invalid parameter
Code:
char[] sBody = new char[iBufferSize];
[SM] Exception reported: Not enough space on the heap
The plugin is a
test plugin edited from somewhere else, so excuse the sloppy code. The issue is in the "TimePlayed_OnHTTPResponse" function, trying to declare a character string that has enough space for iBufferSize (which is around 28627 ).
char[] sBody = new char[iBufferSize];
Spoiler
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <SteamWorks>
/*
public void OnClientPutInServer(int client)
{
if(!IsFakeClient(client))
{
Handle request = CreateRequest_TimePlayed(client);
SteamWorks_SendHTTPRequest(request);
}
}
*/
public void OnPluginStart ()
{
for ( int i = 1 ; i <= MaxClients ; i ++)
{
if (! IsClientInGame ( i ) || IsFakeClient ( i )) continue;
char sName [ 32 ];
GetClientName ( i , sName , 32 );
if ( StrEqual ( sName , "dustin" ))
{
Handle request = CreateRequest_TimePlayed ( i );
SteamWorks_SendHTTPRequest ( request );
break;
}
}
}
Handle CreateRequest_TimePlayed ( int client )
{
char steamid [ 64 ];
GetClientAuthId ( client , AuthId_SteamID64 , steamid , sizeof ( steamid ));
char request_url [ 256 ];
char s_Steamapi [ 256 ] = "" ; // steam Dev key
//Format(request_url, sizeof(request_url), "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s",s_Steamapi);
Format ( request_url , sizeof ( request_url ), "https://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v2/?key=%s" , s_Steamapi );
Handle request = SteamWorks_CreateHTTPRequest ( k_EHTTPMethodGET , request_url );
SteamWorks_SetHTTPRequestGetOrPostParameter ( request , "steamid" , steamid );
SteamWorks_SetHTTPRequestGetOrPostParameter ( request , "appid" , "550" );
SteamWorks_SetHTTPRequestContextValue ( request , client );
SteamWorks_SetHTTPCallbacks ( request , TimePlayed_OnHTTPResponse );
return request ;
}
public int TimePlayed_OnHTTPResponse ( Handle request , bool bFailure , bool bRequestSuccessful , EHTTPStatusCode eStatusCode , int client )
{
if (! bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK )
{
if (! bRequestSuccessful )
LogMessage ( "TimePlayed_OnHTTPResponse | if check didn't pass. Returning. -> !bRequestSuccessful" );
if ( eStatusCode != k_EHTTPStatusCode200OK )
LogMessage ( "TimePlayed_OnHTTPResponse | if check didn't pass. Returning. -> eStatusCode != k_EHTTPStatusCode200OK" );
delete request ;
return;
}
int iBufferSize ;
SteamWorks_GetHTTPResponseBodySize ( request , iBufferSize );
PrintToServer ( "iBufferSize = %i" , iBufferSize ); // 28627
char [] sBody = new char [ iBufferSize ]; // issue
//char sBody[20000];
//SteamWorks_GetHTTPResponseBodyData(request, sBody, sizeof(sBody));
//LogMessage("-------------\nResponse data:\n%s", sBody);
/*
int time = StringToInt(sBody, 10) / 60 / 60;
if(time <= 0)
{
KickClient(client, "Please connect with a public steam profile.");
}
else if(time < sm_cac_hourcheck_value.IntValue)
{
KickClient(client, "You do not meet the minimum hour requirement to play here! (%i/%i)", time, sm_cac_hourcheck_value.IntValue);
}
*/
delete request ;
}