Raised This Month: $ Target: $400
 0% 

Get Data from steam profile page


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_Radon
Junior Member
Join Date: Jan 2010
Old 07-06-2010 , 15:01   Get Data from steam profile page
Reply With Quote #1

Hi

I want to create a sourcemod plugin for tf2 servers.
For this, a player connects to a server.
The server grabs the steam id, calculates the user's 64-Bit steam id (1) and does a http-request to the steam user's profile (2), where the plugin downloads the xml version of the user's profile, xml-parses the data (3) and retrieves the information about how many hours the user played tf2.

Point of all this is, to create newbie servers, where you limit or handicap players of a certain total playtime.
Lets say i only want to allow people with 100 hours or less total playtime on this server.

While the process is generally not a big problem for me, i don't know yet how to make this work with sourcePawn.

(1) For the steamID, i did not find a sourcemod tool yet. Anyone can help me with this? Forum search doesn't give me good results on this
(2) I did find a socket plugin here, but i'd like to ask, if there is no simpler way to do a quick http-request.
(3) if there was a xml-parser around here, this might be perfect. Otherwise i'll have to take a look at regex or string search functions.

An alternative would be, that i redirect this to a script on my webserver which grabs the total playtime and returns only the number upon socket request.

Any help would be highly appreciated.
_Radon is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 07-06-2010 , 16:04   Re: Get Data from steam profile page
Reply With Quote #2

vacbans checks a steam users page - you can look at that to see how its done. and vacbans uses sockets.
dirka_dirka is offline
thresh0ld
Senior Member
Join Date: Sep 2009
Location: Hell
Old 07-07-2010 , 02:23   Re: Get Data from steam profile page
Reply With Quote #3

I have a similar program which is somehow related to what you are trying to achieve here.

What I do is I set up a cron job on my server to regulary fetch/update player statistics and store all these data into the database. I use steam condenser to parse these statistics (really good app library).

You should avoid performing these expensive queries on the game server itself. So I suggest putting up a background script on the webserver side and have that script update the data you need on a database, then use sourcemod to fetch/query this data.

As for the steamid, right now, there is no way for you to convert steamids to it's 64bit equivalent due to some restrictions in sourcemod. Use steamcondenser for converting these ids and store them on your player database.

Last edited by thresh0ld; 07-07-2010 at 02:25.
thresh0ld is offline
thresh0ld
Senior Member
Join Date: Sep 2009
Location: Hell
Old 07-07-2010 , 02:31   Re: Get Data from steam profile page
Reply With Quote #4

if you want to try to implement the conversion yourself, consider this code in php (from steamcondenser).

Code:
/**
* Converts the SteamID as reported by game servers to a 64bit SteamID
* @return String
*/
public static function convertSteamIdToCommunityId($steamId) {
    if($steamId == 'STEAM_ID_LAN' || $steamId == 'BOT') {
        throw new SteamCondenserException("Cannot convert SteamID \"$steamId\" to a community ID.");
    }
    if(preg_match('/^STEAM_[0-1]:[0-1]:[0-9]+$/', $steamId) == 0) {
        throw new SteamCondenserException("SteamID \"$steamId\" doesn't have the correct format.");
    }

    $steamId = explode(':', substr($steamId, 6));
    $steamId = $steamId[1] + $steamId[2] * 2 + 1197960265728;

    return '7656' . $steamId;
}
thresh0ld is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-07-2010 , 07:32   Re: Get Data from steam profile page
Reply With Quote #5

As a possible alternative solution:

You can use the SteamTools extension to request the *.accum.iPlayTime stats for each of the classes (see post here). This will give you the players total time playing TF2 in seconds, which you can then convert to hours and do whatever you like. This method has a lot less overhead than using sockets to grab the community pages and the return is almost instant, the only thing to note is to get the playtime stats in the statsreceived callback, after requesting stats in onclientauthorized, the later is documented in the example plugin included with SteamTools.
__________________

Last edited by asherkin; 07-07-2010 at 07:37.
asherkin is offline
thresh0ld
Senior Member
Join Date: Sep 2009
Location: Hell
Old 07-07-2010 , 08:29   Re: Get Data from steam profile page
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
As a possible alternative solution:

You can use the SteamTools extension to request the *.accum.iPlayTime stats for each of the classes (see post here). This will give you the players total time playing TF2 in seconds, which you can then convert to hours and do whatever you like. This method has a lot less overhead than using sockets to grab the community pages and the return is almost instant, the only thing to note is to get the playtime stats in the statsreceived callback, after requesting stats in onclientauthorized, the later is documented in the example plugin included with SteamTools.
VERY VERY NICE!! I never knew this existed until you posted it here. Thank you man!
thresh0ld is offline
_Radon
Junior Member
Join Date: Jan 2010
Old 07-07-2010 , 11:39   Re: Get Data from steam profile page
Reply With Quote #7

Hi

i finally got what i wanted, i just modified the VAC ban plugin to fix my needs. It uses the socket to create HTTP1.1 requests and returns the XML file which then can be extracted via regular expressions.
Because it has to be performed once a player connects, it's not too bad with the overhead.

Sadly, i was unable to use SteamTools, because on my test server, it somehow was unable to grab the player stats.
I requested game stats, but when i wanted to ask for pyro longest life, it said that the stat data has not yet been requested.

But, if i work on something similar, i'll come back to steamtools again.
_Radon is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-08-2010 , 09:05   Re: Get Data from steam profile page
Reply With Quote #8

Just to see if the problems you were having were caused by SteamTools or your code, could you give this plugin a try?

PHP Code:
#pragma semicolon 1

#include <sourcemod>

#define AUTOLOAD_EXTENSIONS
#define REQUIRE_EXTENSIONS
#include <steamtools>

public Plugin:myinfo = {
    
name        "100 Hours Limit",
    
author      "Asher Baker (asherkin)",
    
description "",
    
version     "",
    
url         "http://limetech.org/"
};

public 
OnClientAuthorized(client, const String:auth[])
{
    if (!
IsFakeClient(client))
    {
        
Steam_RequestStats(client);
    }
}

public 
Action:Steam_StatsReceived(client)
{
    new 
playtime Steam_GetStat(client"Demoman.accum.iPlayTime") + Steam_GetStat(client"Engineer.accum.iPlayTime") + Steam_GetStat(client"Heavy.accum.iPlayTime") + Steam_GetStat(client"Medic.accum.iPlayTime") + Steam_GetStat(client"Pyro.accum.iPlayTime") + Steam_GetStat(client"Scout.accum.iPlayTime") + Steam_GetStat(client"Sniper.accum.iPlayTime") + Steam_GetStat(client"Soldier.accum.iPlayTime") + Steam_GetStat(client"Spy.accum.iPlayTime");
    
//PrintToServer("Client: %N, Time (Seconds): %d, Time (Hours): %d", client, playtime, playtime/3600);
    
if (playtime 360000)
    {
        
KickClient(client"Over 100 hours played");
    }    
    return 
Plugin_Continue;

__________________

Last edited by asherkin; 07-08-2010 at 09:08.
asherkin 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:10.


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