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

external API call from sourcemod


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 02-17-2017 , 15:55   external API call from sourcemod
Reply With Quote #1

Is it possible to call an external api from sourcemod?
I mean, can I do a RPC (remote procedure call).
fragnichtnach is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-17-2017 , 16:26   Re: external API call from sourcemod
Reply With Quote #2

like a post-get API? sure use steam works or some other kind of http request extension.
Mitchell is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 02-17-2017 , 16:43   Re: external API call from sourcemod
Reply With Quote #3

Oh, thanks.
Do you have a link to an example plugin?
fragnichtnach is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-17-2017 , 18:38   Re: external API call from sourcemod
Reply With Quote #4

Quote:
Originally Posted by fragnichtnach View Post
Oh, thanks.
Do you have a link to an example plugin?
I use a SteamWorks request to a php 'man in the middle'. Basically the extensions could only recieve a certain buffer size max, so i use a php script to collect only the information I need from gameMe's API.

The request to the php script: https://github.com/MitchDizzle/GameM...t.sp#L175-L192
The php script: https://github.com/MitchDizzle/GameM...emeconnect.php
Mitchell is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 02-22-2017 , 04:44   Re: external API call from sourcemod
Reply With Quote #5

Okay, thanks. I changed the output of the api-response. Now it is short enough.

But I have still one problem with the callbacks. I need the client from thi intial call. I don't get how to transport the client data.

Code:
#pragma semicolon 1
#include <sourcemod>
#include <SteamWorks>

#define MAX_STEAMID_LENGTH 21
#define MAX_COMMUNITYID_LENGTH 18 

new String:g_address[] = "https://httpapirequest.org/api/user/";
new String:g_complete[256];

public OnPluginStart()
{
	RegConsoleCmd("sm_api", CMD_API);
}

public Action:CMD_API(int client, int args)
{
	new String:SteamID[MAX_STEAMID_LENGTH];
	GetClientAuthId(client, AuthId_Steam2, SteamID, sizeof(SteamID));
	new String:CommunityID[MAX_COMMUNITYID_LENGTH]; 
	GetCommunityIDString(SteamID, CommunityID, sizeof(CommunityID)); 
	Format(g_complete,sizeof(g_complete),"%s%s",g_address,CommunityID);
	ConnectApi(client);
}

public ConnectApi(client)
{
	new Handle:hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, g_Abfragekomplett);
	if (!hRequest || !SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) || !SteamWorks_SendHTTPRequest(hRequest))
	{
		CloseHandle(hRequest);
	}
}

public OnTransferComplete(Handle:hRequest, bool:bFailure, bool:bRequestSuccessful, EHTTPStatusCode:eStatusCode)
{
	if (!bFailure && bRequestSuccessful && eStatusCode == k_EHTTPStatusCode200OK)
	{
		SteamWorks_GetHTTPResponseBodyCallback(hRequest, APIWebResponse);
	}

	CloseHandle(hRequest);
}

public APIWebResponse(const String:sData[])
{
	new iPos = StrContains(sData, "true");
	//in case of sucess the string contains "true"
	if(iPos == -1)
	{
		//false
	}
	else
	{
		//true
	}
	//I need the <client> here
}
Could somebody help me here?
fragnichtnach is offline
fragnichtnach
AlliedModders Donor
Join Date: Oct 2008
Old 02-22-2017 , 05:13   Re: external API call from sourcemod
Reply With Quote #6

Nevermind!!!
I just found my answer in your plugin:
https://github.com/MitchDizzle/GameM...t.sp#L175-L192
Thanks man.
fragnichtnach 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 06:19.


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