[UDF] PSN-Funtionen

  • Hi,

    ich hab hier mal 'ne UDF geschrieben die die API von ps3heroes.de nutzt.
    Damit kann man sich seine allgemeinen Infos und Infos über seine Spiele holen.
    Der Funktionsumfang ist leider relativ begrenzt :D
    Das liegt allerdings an der API die genau 3 Funktionen hat.


    Spoiler anzeigen
    [autoit]


    ; ------------------------------------------------------------------------------
    ;
    ; AutoIt Version: 3.3.6.1
    ; Language: English
    ; Description: ps3heroes api functions
    ; Author(s): jangxx
    ; Requirement(s):
    ; ------------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Gets informations about your pns account
    ; Syntax: _PSN_GetInfo($Username,$Returnvalue)
    ; Parameter(s):
    ; $Username - Your psn-username
    ; $Returnvalue - The value you want to get
    ;
    ; Return Value(s):
    ; Success - Returns a string with the wanted information
    ; Failure - -1 An error occured. Maybe no internet connection
    ; Failure - -2 The $Returnvalue is not valid
    ;
    ;===============================================================================
    Func _PSN_GetInfo($Username,$Returnvalue)
    $mAnswer = BinaryToString(InetRead("http://api.ps3heroes.com/api/hero/" & $Username))
    If $mAnswer = "" Then Return -1
    $Return = StringReplace($mAnswer,"{","")
    $Return = StringReplace($Return,"}","")
    $Return = StringReplace($Return,"\","")
    $oArray = StringSplit($Return,",")
    For $count = 1 to UBound($oArray) - 1 Step 1
    $StringinStr = StringInStr($oArray[$count],$Returnvalue)
    If $StringinStr > 0 Then ExitLoop
    Next
    If $StringinStr <= 0 Then Return -2
    $sArray = StringSplit($oArray[$count],'":"',1)
    $Return = StringTrimRight($sArray[UBound($sArray) - 1],1)
    Return $Return
    EndFunc ;==> _PSN_GetInfo

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Gets a list of all your ps3heroes friends
    ; Syntax: _PSN_GetSidekicks($Username)
    ; Parameter(s):
    ; $Username - Your psn-username
    ;
    ; Return Value(s):
    ; Success - Returns an array containing the names of your sidekicks on ps3heroes.com
    ; Failure - -1 An error occured. Maybe no internet connection
    ;
    ;===============================================================================
    Func _PSN_GetSidekicks($Username)
    $mAnswer = BinaryToString(InetRead("http://api.ps3heroes.com/api/hero/" & $Username & "/sidekicks"))
    If $mAnswer = "" Then Return -1
    $Return = StringTrimLeft($mAnswer,2)
    $Return = StringTrimRight($Return,2)
    $Return = StringSplit($Return,'","',1)
    Return $Return
    EndFunc ;==> _PSN_GetSidekicks

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Gets a list containing the games you've played and informations about it
    ; Syntax: _PSN_GetGames($Username,$Number,$Returnvalue)
    ; Parameter(s):
    ; $Username - Your psn-username
    ; $Number - The Number in the list as returned by _PSN_GetGameNumber
    ; $Returnvalue - The value you want to get
    ;
    ; Return Value(s):
    ; Success - Returns a string with the wanted returnvalue
    ; Failure - -1 An error occured. Maybe no internet connection
    ; Failure - -2 The $Number is invalid
    ;
    ;===============================================================================
    Func _PSN_GetGames($Username,$Number,$Returnvalue)
    $mAnswer = BinaryToString(InetRead("http://api.ps3heroes.com/api/hero/" & $Username & "/games"))
    If $mAnswer = "" Then Return -1
    $Return = StringTrimLeft($mAnswer,2)
    $Return = StringTrimRight($Return,2)
    $Return = StringReplace($Return,"\","")
    $fArray = StringSplit($Return,"},{",1)
    If $Number > UBound($fArray) - 1 Then Return -2
    $zArray = StringSplit($fArray[$Number],",")
    For $count = 1 to UBound($zArray) - 1 Step 1
    $StringinStr = StringInStr($zArray[$count],$Returnvalue)
    If $StringinStr > 0 Then ExitLoop
    Next
    If $StringinStr <= 0 Then Return -2
    $sArray = StringSplit($zArray[$count],'":"',1)
    $Return = StringTrimRight($sArray[UBound($sArray) - 1],1)
    Return $Return
    EndFunc ;==> _PSN_GetGames

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Gets the count of games in your list
    ; Syntax: _PSN_GetGamesCount($Username)
    ; Parameter(s):
    ; $Username - Your psn-username
    ;
    ; Return Value(s):
    ; Success - Returns an integer with the count of your games
    ; Failure - -1 An error occured. Maybe no internet connection
    ;
    ;===============================================================================
    Func _PSN_GetGamesCount($Username)
    $mAnswer = BinaryToString(InetRead("http://api.ps3heroes.com/api/hero/" & $Username & "/games"))
    If $mAnswer = "" Then Return -1
    $Return = StringTrimLeft($mAnswer,2)
    $Return = StringTrimRight($Return,2)
    $fArray = StringSplit($Return,"},{",1)
    $Return = UBound($fArray) - 1
    Return $Return
    EndFunc ;==> _PSN_GetGamesCount

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Gets the number of a specified game
    ; Syntax: _PSN_GetGameNumber($Username,$Type,$Game)
    ; Parameter(s):
    ; $Username - Your psn-username
    ; $Type - Use 1 for Id, 2 for Name or 3 for Trophies contained by the game (see remarks)
    ; $Game - A string or integer containing the selected information by $Type
    ;
    ; Return Value(s):
    ; Success - Returns an integer with the number of the resulted game
    ; Failure - -1 An error occured. Maybe no internet connection
    ; Failure - -2 The $Game does not fit to the selected $Type
    ; Failure - -3 The given $Type is not valid
    ;
    ;Remarks:
    ; If you use 3 for $Type the first game with the selected count of tropies will be returned
    ;===============================================================================
    Func _PSN_GetGameNumber($Username,$Type,$Game)
    $mAnswer = BinaryToString(InetRead("http://api.ps3heroes.com/api/hero/" & $Username & "/games"))
    If $mAnswer = "" Then Return -1
    If $Type < 1 or $Type > 3 Then Return -3
    $Return = StringTrimLeft($mAnswer,2)
    $Return = StringTrimRight($Return,2)
    $fArray = StringSplit($Return,"},{",1)
    For $headcount = 1 to UBound($fArray) - 1 Step 1
    $zArray = StringSplit($fArray[$headcount],",")
    For $count = 1 to UBound($zArray) - 1 Step 1
    Switch $Type
    Case 1
    $StringinStr = StringInStr($zArray[$count],"id")
    Case 2
    $StringinStr = StringInStr($zArray[$count],"name")
    Case 3
    $StringinStr = StringInStr($zArray[$count],"trophies")
    EndSwitch
    If $StringinStr > 0 Then ExitLoop
    Next
    $sArray = StringSplit($zArray[$count],'":"',1)
    $check = StringTrimRight($sArray[UBound($sArray) - 1],1)
    If $check = $Game Then ExitLoop
    Next
    If $headcount > UBound($fArray) - 1 Then Return -2
    Return $headcount
    EndFunc ;==> _PSN_GetGameNumber

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Description: Gets a list of the names or ids of all games you've played
    ; Syntax: _PSN_GetGameList($Username,$Type,$Array = 1)
    ; Parameter(s):
    ; $Username - Your psn-username
    ; $Type - Use 1 for ids and 2 for names
    ;
    ; Return Value(s):
    ; Success - Returns an integer with the conut of your games
    ; Failure - -1 An error occured. Maybe no internet connection
    ;
    ;===============================================================================
    Func _PSN_GetGameList($Username,$Type,$Array = 1)
    $mAnswer = BinaryToString(InetRead("http://api.ps3heroes.com/api/hero/" & $Username & "/games"))
    If $mAnswer = "" Then Return -1
    If $Type < 1 or $Type > 2 Then Return -2
    $ToArray = ""
    $Return = StringTrimLeft($mAnswer,2)
    $Return = StringTrimRight($Return,2)
    $fArray = StringSplit($Return,"},{",1)
    $Return = ""
    For $headcount = 1 to UBound($fArray) - 1 Step 1
    $zArray = StringSplit($fArray[$headcount],",")
    For $count = 1 to UBound($zArray) - 1 Step 1
    Switch $Type
    Case 1
    $StringinStr = StringInStr($zArray[$count],"id")
    Case 2
    $StringinStr = StringInStr($zArray[$count],"name")
    EndSwitch
    If $StringinStr > 0 Then ExitLoop
    Next
    $sArray = StringSplit($zArray[$count],'":"',1)
    $ToArray = StringTrimRight($sArray[UBound($sArray) - 1],1)
    $ToArray = StringReplace($ToArray,"&","&")
    $Return = $Return & $ToArray & "|"
    Next
    If $Array = 1 Then
    $Return = StringSplit($Return,"|")
    EndIf
    Return $Return
    EndFunc ;==> _PSN_GetGameList

    [/autoit]

    Fragen & Anregungen natürlich in die Comments ;)

    Edit: Ich hab die Liste der abfragbaren Infos vergessen :rolleyes:

    Spoiler anzeigen


    psn_username - Der Username des angefragten Users (eigentlich sinnlos)
    url - Die URL zu deinem Profil auf ps3heores.com
    avatar - Die URL zu deinem PSN Avatar. Das Bild ist im .png Format
    level - Dein Trophäenleven
    progress - Der Levelfortschritt
    platinum - Die Anzahl deiner Platinum Trophäen
    gold - Die Anzahl deiner Gold Trophäen
    silver - Die Anzahl deiner Silber Trophäen
    bronze - Die Anzahl deiner Bronze Trophäen
    sidekick_count - Die Anzahl deiner Freunde (ist verbuggt)
    fan_count - Die Anzahl deiner Fans auf ps3heroes.com
    game_count - Die Anzahl deiner Spiele
    comment_count - Die Anzahl, der von dir geschriebenen Kommentare auf ps3heroes.com
    topic_count - Die Anzahl der von dir erstellten Topics auf ps3heroes.com