sourcemod 1.13 upgrade. moved all plugins from steamworks to ripext. added smjanson and asyncsocket.inc an extra time so its easier to find. updated plugins that would not compile with 1.13
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <SteamWorks>
|
||||
#include <ripext>
|
||||
#include <cstrike>
|
||||
#include <AdvancedTargeting>
|
||||
|
||||
@@ -437,17 +437,14 @@ public void OnClientAuthorized(int client, const char[] auth)
|
||||
char sSteam64ID[32];
|
||||
Steam32IDtoSteam64ID(auth, sSteam64ID, sizeof(sSteam64ID));
|
||||
|
||||
// format=json instead of format=vdf: ripext only exposes the response body
|
||||
// as decoded JSON, so we ask Steam's own API for JSON directly rather than
|
||||
// working around a missing raw-body accessor.
|
||||
static char sRequest[256];
|
||||
FormatEx(sRequest, sizeof(sRequest), "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s&relationship=friend&format=vdf", STEAM_API_KEY, sSteam64ID);
|
||||
FormatEx(sRequest, sizeof(sRequest), "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s&relationship=friend&format=json", STEAM_API_KEY, sSteam64ID);
|
||||
|
||||
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest);
|
||||
if (!hRequest ||
|
||||
!SteamWorks_SetHTTPRequestContextValue(hRequest, client) ||
|
||||
!SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) ||
|
||||
!SteamWorks_SendHTTPRequest(hRequest))
|
||||
{
|
||||
CloseHandle(hRequest);
|
||||
}
|
||||
HTTPRequest hRequest = new HTTPRequest(sRequest);
|
||||
hRequest.Get(OnTransferComplete, client);
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
@@ -458,52 +455,38 @@ public void OnClientDisconnect(int client)
|
||||
g_FriendsArray[client] = INVALID_HANDLE;
|
||||
}
|
||||
|
||||
public int OnTransferComplete(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, int client)
|
||||
public void OnTransferComplete(HTTPResponse response, any client)
|
||||
{
|
||||
if(bFailure || !bRequestSuccessful || eStatusCode != k_EHTTPStatusCode200OK)
|
||||
if(response.Status != HTTPStatus_OK || response.Data == null)
|
||||
{
|
||||
// Private profile or maybe steam down?
|
||||
//LogError("SteamAPI HTTP Response failed: %d", eStatusCode);
|
||||
CloseHandle(hRequest);
|
||||
//LogError("SteamAPI HTTP Response failed: %d", response.Status);
|
||||
return;
|
||||
}
|
||||
|
||||
int Length;
|
||||
SteamWorks_GetHTTPResponseBodySize(hRequest, Length);
|
||||
|
||||
char[] sData = new char[Length];
|
||||
SteamWorks_GetHTTPResponseBodyData(hRequest, sData, Length);
|
||||
//SteamWorks_GetHTTPResponseBodyCallback(hRequest, APIWebResponse, client);
|
||||
|
||||
CloseHandle(hRequest);
|
||||
|
||||
APIWebResponse(sData, client);
|
||||
APIWebResponse(view_as<JSONObject>(response.Data), client);
|
||||
}
|
||||
|
||||
public void APIWebResponse(const char[] sData, int client)
|
||||
public void APIWebResponse(JSONObject Response, int client)
|
||||
{
|
||||
KeyValues Response = new KeyValues("SteamAPIResponse");
|
||||
if(!Response.ImportFromString(sData, "SteamAPIResponse"))
|
||||
if(!Response.HasKey("friendslist"))
|
||||
{
|
||||
LogError("ImportFromString(sData, \"SteamAPIResponse\") failed.");
|
||||
LogError("GetFriendList response missing \"friendslist\" key.");
|
||||
delete Response;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Response.JumpToKey("friends"))
|
||||
JSONObject friendslist = view_as<JSONObject>(Response.Get("friendslist"));
|
||||
|
||||
// No friends, or private profile - Steam returns {"friendslist":{}} in that case.
|
||||
if(!friendslist.HasKey("friends"))
|
||||
{
|
||||
LogError("JumpToKey(\"friends\") failed.");
|
||||
delete friendslist;
|
||||
delete Response;
|
||||
return;
|
||||
}
|
||||
|
||||
// No friends?
|
||||
if(!Response.GotoFirstSubKey())
|
||||
{
|
||||
//LogError("GotoFirstSubKey() failed.");
|
||||
delete Response;
|
||||
return;
|
||||
}
|
||||
JSONArray friends = view_as<JSONArray>(friendslist.Get("friends"));
|
||||
|
||||
if(g_FriendsArray[client] != INVALID_HANDLE)
|
||||
CloseHandle(g_FriendsArray[client]);
|
||||
@@ -511,18 +494,20 @@ public void APIWebResponse(const char[] sData, int client)
|
||||
g_FriendsArray[client] = CreateArray();
|
||||
|
||||
char sCommunityID[32];
|
||||
do
|
||||
int len = friends.Length;
|
||||
for(int i = 0; i < len; i++)
|
||||
{
|
||||
Response.GetString("steamid", sCommunityID, sizeof(sCommunityID));
|
||||
|
||||
PushArrayCell(g_FriendsArray[client], Steam64toSteam3(sCommunityID));
|
||||
JSONObject friendEntry = view_as<JSONObject>(friends.Get(i));
|
||||
if(friendEntry.GetString("steamid", sCommunityID, sizeof(sCommunityID)))
|
||||
PushArrayCell(g_FriendsArray[client], Steam64toSteam3(sCommunityID));
|
||||
delete friendEntry;
|
||||
}
|
||||
while(Response.GotoNextKey());
|
||||
|
||||
delete friends;
|
||||
delete friendslist;
|
||||
delete Response;
|
||||
}
|
||||
|
||||
|
||||
stock bool Steam32IDtoSteam64ID(const char[] sSteam32ID, char[] sSteam64ID, int Size)
|
||||
{
|
||||
if(strlen(sSteam32ID) < 11 || strncmp(sSteam32ID[0], "STEAM_0:", 8))
|
||||
@@ -634,3 +619,4 @@ public int Native_ReadClientFriends(Handle plugin, int numParams)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user