Junior Member
|
07-21-2014
, 23:27
Re: [Help & Request] Steam family sharing without SteamWorks ext.
|
#3
|
Quote:
Originally Posted by Sreaper
|
Quote:
Originally Posted by Moshiko014
I tried the SteamWorks build for windows, but its not working for me.
|
Interesting alternative to SteamWorks, in case it ever breaks for whatever reason. Anyways, here's my go at it. It worked correctly when I was using a family shared account, although I never actually tested it with a non family shared account.
Requires the socket extension
PHP Code:
#include <sourcemod>
#include <socket>
#define HOST_PATH "api.steampowered.com"
#define MAX_STEAMID_LENGTH 21
#define MAX_COMMUNITYID_LENGTH 18
new Handle:g_hCvarAppId = INVALID_HANDLE;
new Handle:g_hCvarAPIKey = INVALID_HANDLE;
// The maximum returned length of 174 occurs when an unauthorized key is provided
// Header length really shouldn't be 900 characters long. But just in case...
new String:g_sAPIBuffer[MAXPLAYERS + 1][1024];
new Handle:g_hAPISocket[MAXPLAYERS + 1];
public Plugin:myinfo =
{
name = "familyshare",
author = "bonbon",
description = "Ban family shared accounts (windows)",
version = "1.0.0.0"
};
public OnPluginStart()
{
g_hCvarAppId = CreateConVar("familysharing_appid", "730", "Application ID of current game. CS:S (240), CS:GO (730), TF2 (440)");
g_hCvarAPIKey = CreateConVar("familysharing_apikey", "XXXXXXXXXXXXXXXXXXXX", "Steam developer web API key");
}
public OnClientAuthorized(client, const String:steamid[])
{
if (!IsFakeClient(client))
{
CheckFamilySharing(client);
}
}
public OnClientDisconnect(client)
{
if (g_hAPISocket[client] != INVALID_HANDLE)
{
CloseHandle(g_hAPISocket[client]);
g_hAPISocket[client] = INVALID_HANDLE;
}
}
public OnSocketConnected(Handle:socket, any:userid)
{
new client = GetClientOfUserId(userid);
if (!client)
{
CloseHandle(socket);
return;
}
decl String:apikey[64];
decl String:get[256];
decl String:request[512];
decl String:steamid[MAX_STEAMID_LENGTH];
decl String:steamid64[MAX_COMMUNITYID_LENGTH];
GetConVarString(g_hCvarAPIKey, apikey, sizeof(apikey));
GetClientAuthString(client, steamid, sizeof(steamid));
GetCommunityIDString(steamid, steamid64, sizeof(steamid64));
Format(get, sizeof(get),
"%s/IPlayerService/IsPlayingSharedGame/v0001/?key=%s&steamid=%s&appid_playing=%d&format=json",
HOST_PATH, apikey, steamid64, GetConVarInt(g_hCvarAppId));
Format(request, sizeof(request),
"GET http://%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nAccept-Encoding: *\r\n\r\n",
get, HOST_PATH);
SocketSend(socket, request);
}
public OnSocketReceive(Handle:socket, String:receiveData[], dataSize, any:userid)
{
new client = GetClientOfUserId(userid);
if (client > 0)
{
StrCat(g_sAPIBuffer[client], 1024, receiveData);
if (StrContains(receiveData, "404 Not Found", false) != -1)
{
OnSocketError(socket, 404, 404, userid);
}
else if (StrContains(receiveData, "Unauthorized", false) != -1)
{
OnSocketError(socket, 403, 403, userid);
}
}
}
public OnSocketError(Handle:socket, const errorType, const errorNum, any:userid)
{
new client = GetClientOfUserId(userid);
if (client > 0)
{
g_hAPISocket[client] = INVALID_HANDLE;
LogError("Error checking family sharing for %L -- error %d (%d)", client, errorType, errorNum);
}
CloseHandle(socket);
}
public OnSocketDisconnected(Handle:socket, any:userid)
{
new client = GetClientOfUserId(userid);
if (client > 0)
{
g_hAPISocket[client] = INVALID_HANDLE;
ReplaceString(g_sAPIBuffer[client], 1024, " ", "");
ReplaceString(g_sAPIBuffer[client], 1024, "\t", "");
new index = StrContains(g_sAPIBuffer[client], "\"lender_steamid\":", false);
if (index == -1)
{
LogError("unexpected error returned in request - %s", g_sAPIBuffer[client]);
}
else
{
index += strlen("\"lender_steamid\":");
if (g_sAPIBuffer[client][index + 1] != '0' ||
g_sAPIBuffer[client][index + 2] != '"')
{
LogMessage("Banning %L for 10 minutes", client);
BanClient(client, 10, BANFLAG_AUTHID, "Family sharing is disabled", "Family sharing is disabled");
}
}
}
CloseHandle(socket);
}
stock CheckFamilySharing(client)
{
new Handle:socket = SocketCreate(SOCKET_TCP, OnSocketError);
g_hAPISocket[client] = socket;
g_sAPIBuffer[client][0] = '\0';
SocketSetArg(socket, GetClientUserId(client));
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, HOST_PATH, 80);
}
// Credit to 11530
// https://forums.alliedmods.net/showthread.php?t=183443&highlight=communityid
stock bool:GetCommunityIDString(const String:SteamID[], String:CommunityID[], const CommunityIDSize)
{
decl String:SteamIDParts[3][11];
new const String:Identifier[] = "76561197960265728";
if ((CommunityIDSize < 1) || (ExplodeString(SteamID, ":", SteamIDParts, sizeof(SteamIDParts), sizeof(SteamIDParts[])) != 3))
{
CommunityID[0] = '\0';
return false;
}
new Current, CarryOver = (SteamIDParts[1][0] == '1');
for (new i = (CommunityIDSize - 2), j = (strlen(SteamIDParts[2]) - 1), k = (strlen(Identifier) - 1); i >= 0; i--, j--, k--)
{
Current = (j >= 0 ? (2 * (SteamIDParts[2][j] - '0')) : 0) + CarryOver + (k >= 0 ? ((Identifier[k] - '0') * 1) : 0);
CarryOver = Current / 10;
CommunityID[i] = (Current % 10) + '0';
}
CommunityID[CommunityIDSize - 1] = '\0';
return true;
}
Just put "familysharing_apikey <Your API key here>" in your server.cfg, as well if you ever run this on a different key make sure to change familysharing_appid as well
__________________
Last edited by bonbon; 07-21-2014 at 23:32.
Reason: uploaded wrong version
|
|