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

[Help & Request] Steam family sharing without SteamWorks ext.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Moshiko014
Senior Member
Join Date: Apr 2010
Old 07-20-2014 , 15:02   [Help & Request] Steam family sharing without SteamWorks ext.
Reply With Quote #1

Hello guys, i'v few CS:GO server and i tried to block Steam family sharing from my servers, I tried the SteamWorks build for windows, but its not working for me.

So there is any way to use the Steam API with url?

take a look here
Quote:
api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?key=yoursteamdevkeyhere&format=json&steamid=76561198143947702&appid_playing=730
If the player ingame you will see this message:


and if he doesn't use family sharing you will see this message:



you can also get your steam Dev key here:
http://steamcommunity.com/dev/apikey

i want to block and kick users with family sharing, thats all i want.

thanks a lot!
I hope there is someone who can make it.

(CS:GO under windows server 2008 ) .

Last edited by Moshiko014; 07-20-2014 at 15:14.
Moshiko014 is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 07-21-2014 , 18:56   Re: [Help & Request] Steam family sharing without SteamWorks ext.
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=240626
Sreaper is offline
bonbon
Junior Member
Join Date: Jan 2008
Old 07-21-2014 , 23:27   Re: [Help & Request] Steam family sharing without SteamWorks ext.
Reply With Quote #3

Quote:
Originally Posted by Sreaper View Post
Quote:
Originally Posted by Moshiko014 View Post
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:socketany: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_hCvarAPIKeyapikeysizeof(apikey));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
GetCommunityIDString(steamidsteamid64sizeof(steamid64));

    
Format(getsizeof(get),
           
"%s/IPlayerService/IsPlayingSharedGame/v0001/?key=%s&steamid=%s&appid_playing=%d&format=json",
           
HOST_PATHapikeysteamid64GetConVarInt(g_hCvarAppId));

    
Format(requestsizeof(request),
           
"GET http://%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nAccept-Encoding: *\r\n\r\n",
           
getHOST_PATH);

    
SocketSend(socketrequest);
}

public 
OnSocketReceive(Handle:socketString:receiveData[], dataSizeany:userid)
{
    new 
client GetClientOfUserId(userid);

    if (
client 0)
    {
        
StrCat(g_sAPIBuffer[client], 1024receiveData);
    
        if (
StrContains(receiveData"404 Not Found"false) != -1)
        {
            
OnSocketError(socket404404userid);
        }

        else if (
StrContains(receiveData"Unauthorized"false) != -1)
        {
            
OnSocketError(socket403403userid);
        }
    }
}

public 
OnSocketError(Handle:socket, const errorType, const errorNumany:userid)
{
    new 
client GetClientOfUserId(userid);
    if (
client 0)
    {
        
g_hAPISocket[client] = INVALID_HANDLE;
        
LogError("Error checking family sharing for %L -- error %d (%d)"clienterrorTypeerrorNum);
    }

    
CloseHandle(socket);
}

public 
OnSocketDisconnected(Handle:socketany: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(client10BANFLAG_AUTHID"Family sharing is disabled""Family sharing is disabled");
            }
        }
    }

    
CloseHandle(socket);
}

stock CheckFamilySharing(client)
{
    new 
Handle:socket SocketCreate(SOCKET_TCPOnSocketError);

    
g_hAPISocket[client] = socket;
    
g_sAPIBuffer[client][0] = '\0';

    
SocketSetArg(socketGetClientUserId(client));
    
SocketConnect(socketOnSocketConnectedOnSocketReceiveOnSocketDisconnectedHOST_PATH80);
}

// 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":"SteamIDPartssizeof(SteamIDParts), sizeof(SteamIDParts[])) != 3))
    {
        
CommunityID[0] = '\0';
        return 
false;
    }

    new 
CurrentCarryOver = (SteamIDParts[1][0] == '1');
    for (new 
= (CommunityIDSize 2), = (strlen(SteamIDParts[2]) - 1), = (strlen(Identifier) - 1); >= 0i--, j--, k--)
    {
        
Current = (>= ? (* (SteamIDParts[2][j] - '0')) : 0) + CarryOver + (>= ? ((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
Attached Files
File Type: smx familyshare.smx (6.8 KB, 319 views)
__________________
Code:
   ______
   _|___|_
   |¬ ¬|
    \|/
     |
    / \
Feel So Good
Pics of me

Last edited by bonbon; 07-21-2014 at 23:32. Reason: uploaded wrong version
bonbon is offline
Moshiko014
Senior Member
Join Date: Apr 2010
Old 07-22-2014 , 09:30   Re: [Help & Request] Steam family sharing without SteamWorks ext.
Reply With Quote #4

Quote:
Originally Posted by bonbon View Post
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:socketany: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_hCvarAPIKeyapikeysizeof(apikey));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
GetCommunityIDString(steamidsteamid64sizeof(steamid64));

    
Format(getsizeof(get),
           
"%s/IPlayerService/IsPlayingSharedGame/v0001/?key=%s&steamid=%s&appid_playing=%d&format=json",
           
HOST_PATHapikeysteamid64GetConVarInt(g_hCvarAppId));

    
Format(requestsizeof(request),
           
"GET http://%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nAccept-Encoding: *\r\n\r\n",
           
getHOST_PATH);

    
SocketSend(socketrequest);
}

public 
OnSocketReceive(Handle:socketString:receiveData[], dataSizeany:userid)
{
    new 
client GetClientOfUserId(userid);

    if (
client 0)
    {
        
StrCat(g_sAPIBuffer[client], 1024receiveData);
    
        if (
StrContains(receiveData"404 Not Found"false) != -1)
        {
            
OnSocketError(socket404404userid);
        }

        else if (
StrContains(receiveData"Unauthorized"false) != -1)
        {
            
OnSocketError(socket403403userid);
        }
    }
}

public 
OnSocketError(Handle:socket, const errorType, const errorNumany:userid)
{
    new 
client GetClientOfUserId(userid);
    if (
client 0)
    {
        
g_hAPISocket[client] = INVALID_HANDLE;
        
LogError("Error checking family sharing for %L -- error %d (%d)"clienterrorTypeerrorNum);
    }

    
CloseHandle(socket);
}

public 
OnSocketDisconnected(Handle:socketany: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(client10BANFLAG_AUTHID"Family sharing is disabled""Family sharing is disabled");
            }
        }
    }

    
CloseHandle(socket);
}

stock CheckFamilySharing(client)
{
    new 
Handle:socket SocketCreate(SOCKET_TCPOnSocketError);

    
g_hAPISocket[client] = socket;
    
g_sAPIBuffer[client][0] = '\0';

    
SocketSetArg(socketGetClientUserId(client));
    
SocketConnect(socketOnSocketConnectedOnSocketReceiveOnSocketDisconnectedHOST_PATH80);
}

// 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":"SteamIDPartssizeof(SteamIDParts), sizeof(SteamIDParts[])) != 3))
    {
        
CommunityID[0] = '\0';
        return 
false;
    }

    new 
CurrentCarryOver = (SteamIDParts[1][0] == '1');
    for (new 
= (CommunityIDSize 2), = (strlen(SteamIDParts[2]) - 1), = (strlen(Identifier) - 1); >= 0i--, j--, k--)
    {
        
Current = (>= ? (* (SteamIDParts[2][j] - '0')) : 0) + CarryOver + (>= ? ((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
DAMMMN Thank you
Moshiko014 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 08:33.


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