/// <summary> /// (Async) (Requires UserAuthenticator, APIKeyAuthenticator) /// Returns a list of games a player owns along with some playtime information, if the profile is publicly visible. /// Throws <see cref="SteamRequestException"/> on failure. /// <a href="https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29">See official documentation.</a> /// </summary> /// <param name="client"><see cref="SteamClient"/> instance to use.</param> /// <param name="steamID">SteamID to return friend's list for.</param> /// <param name="getAppInfo">Include game name and logo information in the output?</param> /// <param name="getPlayedFreeGames">By default, free games are excluded (as technically everyone owns them). If flag is true, all games the user has played at some point will be returned.</param> /// <returns><see cref="OwnedGames"/> object containing information about the specified user's game collection.</returns> public async static Task<OwnedGames> GetOwnedGamesAsync( SteamClient client, string steamID, bool getAppInfo = true, bool getPlayedFreeGames = true ) { client.IsAuthorizedCall( new Type[] { typeof( Authenticators.UserAuthenticator ), // Executes in User Context (private) typeof( Authenticators.APIKeyAuthenticator ) // Executes in API context (public) } ); SteamRequest request = new SteamRequest( SteamAPIInterface.IPlayerService, "GetOwnedGames", SteamMethodVersion.v0001 ); request.AddParameter( "steamid", steamID, ParameterType.QueryString ); request.AddParameter( "include_appinfo", ( ( getAppInfo ) ? 1 : 0 ), ParameterType.QueryString ); request.AddParameter( "include_played_free_games", ( ( getPlayedFreeGames ) ? 1 : 0 ), ParameterType.QueryString ); return VerifyAndDeserialize<GetOwnedGamesResponse>( ( await client.ExecuteAsync( request ) ) ).OwnedGames; }
/// <summary> /// (Async) (Requires <see cref="SteamSharp.Authenticators.UserAuthenticator"/>) /// Logs the SteamChatClient on to the Steam Chat Service under the context of the authenticated user (UserAuthenticator attached to the targeted SteamClient). /// </summary> /// <param name="client"><see cref="SteamClient"/> instance to use.</param> /// <returns> /// Logs the SteamClient authenticated user on to the Steam Chat Service. /// </returns> /// <exception cref="SteamRequestException">SteamRequestException</exception> /// <exception cref="SteamAuthenticationException">SteamAuthenticationException</exception> public async Task LogOn( SteamClient client ) { IsManualDisconnection = false; try { IndicateConnectionState( ClientConnectionStatus.Connecting ); client.IsAuthorizedCall( new Type[] { typeof( Authenticators.UserAuthenticator ) } ); SteamRequest request = new SteamRequest( "ISteamWebUserPresenceOAuth", "Logon", "v0001", HttpMethod.Post ); ChatSession = SteamInterface.VerifyAndDeserialize<SteamChatSession>( ( await client.ExecuteAsync( request ) ) ); LastMessageSentID = ChatSession.MessageBaseID; Authenticator = client.Authenticator; // Initialize Friends List FriendsList = await SteamCommunity.GetFriendsListAsync( this, ChatSession.SteamID ); HasInitialized = true; BeginPoll(); } catch( Exception e ) { IndicateConnectionState( ClientConnectionStatus.Disconnected ); if( e is AggregateException && e.InnerException != null ) throw e.InnerException; throw e; } }
/// <summary> /// (Async) (Requires <see cref="SteamSharp.Authenticators.APIKeyAuthenticator"/> or <see cref="SteamSharp.Authenticators.UserAuthenticator"/>) /// Returns basic profile information for a list of 64-bit Steam IDs. /// Throws <see cref="SteamRequestException"/> on failure. /// </summary> /// <param name="client"><see cref="SteamClient"/> instance to use.</param> /// <param name="steamIDs">List of 64 bit Steam IDs to return profile information for. If more than 100 is requested, requests will be executed in batches (API limit of 100 per call).</param> /// <returns> /// Returns a large amount of profile data for the requested users in the form of a <see cref="Player"/> object. /// Some data associated with a Steam account may be hidden if the user has their profile visibility set to "Friends Only" or "Private". In that case, only public data will be returned. /// </returns> public async static Task<List<SteamUser>> GetUsersAsync( SteamClient client, SteamID[] steamIDs ) { client.IsAuthorizedCall( new Type[] { typeof( Authenticators.UserAuthenticator ), typeof( Authenticators.APIKeyAuthenticator ) } ); // GetUsers has an upper bound of 100 users per request, determine if aggregation is needed SteamID[][] chunks = steamIDs.Select( ( v, i ) => new { Value = v, Index = i } ) .GroupBy( x => x.Index / 100 ) .Select( group => group.Select( x => x.Value ).ToArray() ) .ToArray(); List<SteamUser> users = new List<SteamUser>(); SteamRequest request; List<PlayerInfo> players; for( int i = 0; i < chunks.Length; i++ ) { if( client.Authenticator is Authenticators.UserAuthenticator ) { // ISteamUserOAuth provides a higher level of access (with User Authentication), assuming a personal relationship with the target user request = new SteamRequest( "ISteamUserOAuth", "GetUserSummaries", "v0001" ); request.AddParameter( "steamids", String.Join<SteamID>( ",", steamIDs ) ); players = VerifyAndDeserialize<GetPlayerSummariesContainer>( ( await client.ExecuteAsync( request ) ) ).Players; } else { request = new SteamRequest( "ISteamUser", "GetPlayerSummaries", "v0002" ); request.AddParameter( "steamids", String.Join<SteamID>( ",", steamIDs ) ); players = VerifyAndDeserialize<GetPlayerSummariesResponse>( ( await client.ExecuteAsync( request ) ) ).Response.Players; } foreach( var player in players ) { users.Add( new SteamUser { SteamID = player.SteamID, PlayerInfo = player } ); } } return users; }
/// <summary> /// (Async) (Requires <see cref="SteamSharp.Authenticators.APIKeyAuthenticator"/> or <see cref="SteamSharp.Authenticators.UserAuthenticator"/>) /// Returns the friend list of any Steam user, provided the user's Steam Community profile visibility is set to "Public." /// Throws <see cref="SteamRequestException"/> on failure. /// </summary> /// <param name="client"><see cref="SteamClient"/> instance to use.</param> /// <param name="steamID">SteamID to return friend's list for.</param> /// <returns><see cref="SteamFriendsList"/> object containing a list of <see cref="SteamFriend"/> objects mapping to the Friend's list of the target user.</returns> public async static Task<SteamFriendsList> GetFriendsListAsync( SteamClient client, SteamID steamID ) { client.IsAuthorizedCall( new Type[] { typeof( Authenticators.UserAuthenticator ), typeof( Authenticators.APIKeyAuthenticator ) } ); SteamRequest request; List<SteamFriend> response; if( client.Authenticator is Authenticators.UserAuthenticator ) { // ISteamUserOAuth provides a higher level of access (with User Authentication), assuming a personal relationship with the target user request = new SteamRequest( "ISteamUserOAuth", "GetFriendList", "v0001" ); request.AddParameter( "steamID", steamID.ToString() ); response = VerifyAndDeserialize<SteamFriendsListResponse>( ( await client.ExecuteAsync( request ) ) ).Friends; } else { request = new SteamRequest( "ISteamUser", "GetFriendList", "v0001" ); request.AddParameter( "steamID", steamID.ToString() ); response = VerifyAndDeserialize<GetFriendsListResponse>( ( await client.ExecuteAsync( request ) ) ).FriendsList.Friends; } Dictionary<SteamID, SteamUser> users = new Dictionary<SteamID, SteamUser>(); foreach( var friend in response ) { users.Add( friend.SteamID, new SteamUser { SteamID = friend.SteamID, FriendSince = friend.FriendSince, } ); } return new SteamFriendsList { Friends = await GetBulkProfileDataAsync( client, users ) }; }