Page 1 of 1

SteamID&CommunityID Functions [VB .Net]

Posted: Sat May 14, 2011 11:03 pm
by Blake
Read Steam Community XML

Code: Select all

    Public Class SteamIDInfo
        Public Function GetSteamIDInfo(ByVal Type As String, ByVal ID As String, ByVal Element As String)
            If String.IsNullOrEmpty(ID) Then
                Return Nothing
            End If
            Dim reqUrl As String = "http://steamcommunity.com/" + Type + "/" + ID + "/?xml=1"
            Dim httpReq As HttpWebRequest = TryCast(HttpWebRequest.Create(reqUrl), HttpWebRequest)
            Try
                Dim result As String = String.Empty
                Dim response As HttpWebResponse = TryCast(httpReq.GetResponse(), HttpWebResponse)
                Using reader = New StreamReader(response.GetResponseStream())
                    result = reader.ReadToEnd()
                End Using
                Return ProcessResponse(result, Element)
            Catch ex As Exception
                Throw
            End Try
        End Function

        Private Function ProcessResponse(ByVal strResp As String, ByVal TheElement As String)
            Dim Result As String = Nothing
            Dim sr As New StringReader(strResp)
            Dim respElement As XElement = XElement.Load(sr)
            Dim tmpEle As String = respElement.Element(TheElement)
            Return tmpEle
        End Function
    End Class
SteamID To CommunityID & CommunityID To SteamID

Code: Select all

    Private Shared intBigNum As Long = 76561197960265728

    Private Function GetCommunityId(ByVal pSteamId As String) As String
        pSteamId = Trim(pSteamId)
        pSteamId = UCase(pSteamId)
        Dim strRegEx As String = "\bSTEAM_[0-1]:[0-1]:(\d+)\b"
        If RegularExpressions.Regex.IsMatch(pSteamId, strRegEx) Then
            pSteamId = pSteamId.Substring(6)
            Dim arrParts() As String = pSteamId.Split(":")
            Dim intAuthSvr1 As Integer = arrParts(0)
            Dim intAuthSvr2 As Integer = arrParts(1)
            Dim intClientNum As Long = arrParts(2)
            Return CType(intBigNum + intAuthSvr2 + (intClientNum * 2), String)
        Else
            Return CStr(0)
        End If
    End Function

    Private Function GetSteamId(ByVal pCommunityId As String) As String
        If pCommunityId.Length = 17 And IsNumeric(pCommunityId) = True Then
            Dim intCommunityId As Long = CType(pCommunityId, Long)
            Dim intAuthSvr1 As Integer = 0
            Dim intAuthSvr2 As Integer = Nothing
            If intCommunityId Mod 2 Then
                intAuthSvr2 = 1
            Else
                intAuthSvr2 = 0
            End If
            Dim intClientNum As Long = (intCommunityId - intBigNum - intAuthSvr2) / 2
            Return "STEAM_" & CStr(intAuthSvr1) & ":" & CStr(intAuthSvr2) & ":" & CStr(intClientNum)
        Else
            Return CStr(0)
        End If
    End Function

Re: SteamID&CommunityID Functions [VB .Net]

Posted: Wed May 02, 2012 11:15 pm
by killman2639
Well done smacked.

Re: SteamID&CommunityID Functions [VB .Net]

Posted: Thu May 03, 2012 6:56 am
by ant_8490
killman2639 wrote:Well done smacked.
Almost 1 year later.

Re: SteamID&CommunityID Functions [VB .Net]

Posted: Thu May 03, 2012 2:02 pm
by Ryan
ant_8490 wrote:
killman2639 wrote:Well done smacked.
Almost 1 year later.
12 days out. Seems too coincidental.

Re: SteamID&CommunityID Functions [VB .Net]

Posted: Thu May 03, 2012 9:56 pm
by killman2639
Yeah I know it's old, lol. I was going through the old stuff and found this and accidentally pressed a button, bump I belive, don't remember exactly, that apparently "reactivates" the topic. :P