Example #1
0
		/// <summary>
		/// (Asynchronous) Returns global achievements overview for a specific game (in percentages)
		/// Throws <see cref="SteamRequestException"/> on failure.
		/// <a href="https://developer.valvesoftware.com/wiki/Steam_Web_API#GetGlobalAchievementPercentagesForApp_.28v0002.29">See official documentation.</a>
		/// </summary>
		/// <param name="client"><see cref="SteamClient"/> instance to use.</param>
		/// <param name="gameID">AppID of the game you want the news of.</param>
		/// <returns>A List of <see cref="GlobalAchievement"/> objects containing the achievement name and percentage.</returns>
		public async static Task<List<GlobalAchievement>> GetGlobalAchievementPercentagesForAppAsync( SteamClient client, int gameID ) {

			SteamRequest request = new SteamRequest( SteamAPIInterface.ISteamUserStats, "GetGlobalAchievementPercentagesForApp", SteamMethodVersion.v0002 );
			request.AddParameter( "gameid", gameID );

			return VerifyAndDeserialize<GetGlobalAchievementPercentagesForAppResponse>( ( await client.ExecuteAsync( request ) ) ).AchievementPercentages.Achievements;

		}
Example #2
0
		/// <summary>
		/// (Asynchronous) Returns the latest of a game specified by its AppID.
		/// Throws <see cref="SteamRequestException"/> on failure.
		/// <a href="https://developer.valvesoftware.com/wiki/Steam_Web_API#GetNewsForApp_.28v0002.29">See official documentation.</a>
		/// </summary>
		/// <param name="client"><see cref="SteamClient"/> instance to use.</param>
		/// <param name="appID">AppID of the game you want the news of.</param>
		/// <param name="count">How many news enties you want to get returned.</param>
		/// <param name="maxLength">Maximum length of each news entry.</param>
		/// <returns>An <see cref="AppNews"/> object.</returns>
		public async static Task<AppNews> GetNewsForAppAsync( SteamClient client, int appID, int count, int maxLength ) {

			SteamRequest request = new SteamRequest( SteamAPIInterface.ISteamNews, "GetNewsForApp", SteamMethodVersion.v0002 );
			request.AddParameter( "appid", appID );
			request.AddParameter( "count", count );
			request.AddParameter( "maxlength", maxLength );

			return VerifyAndDeserialize<GetNewsForAppResponse>( ( await client.ExecuteAsync( request ) ) ).AppNews;

		}
Example #3
0
		/// <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;

		}
Example #4
0
		/// <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;
			}

		}
Example #5
0
		/// <summary>
		/// Sends a message, with text, to the target user.
		/// </summary>
		/// <param name="destinationUser">Targeted receipient for the message.</param>
		/// <param name="text">Message to send.</param>
		/// <returns>Asynchronous task to be used for tracking request completion.</returns>
		public async Task SendMessage( SteamID destinationUser, string text ) {

			SteamRequest request = new SteamRequest( "ISteamWebUserPresenceOAuth", "Message", "v0001", HttpMethod.Post );

			request.AddParameter( "umqid", ChatSession.ChatSessionID, ParameterType.GetOrPost );
			request.AddParameter( "type", ( ( text == null ) ? "typing" : "saytext" ), ParameterType.GetOrPost );
			request.AddParameter( "steamid_dst", destinationUser.ToString(), ParameterType.GetOrPost );

			if( text != null )
				request.AddParameter( "text", text, ParameterType.GetOrPost );

			SteamInterface.VerifyAndDeserialize<SteamChatSendMessageResponse>( ( await ExecuteAsync( request ) ) );

		}
Example #6
0
		/// <summary>
		/// Stops polling and disconnects the client from the Steam server.
		/// </summary>
		public async Task Disconnect() {

			IsManualDisconnection = true;

			if( this.ConnectionStatus == ClientConnectionStatus.Disconnected )
				return;

			Cancellation.Cancel();
			SteamRequest request = new SteamRequest( "ISteamWebUserPresenceOAuth", "Logoff", "v0001", HttpMethod.Post );
			request.AddParameter( "umqid", ChatSession.ChatSessionID, ParameterType.GetOrPost );

			await ExecuteAsync( request );
			
		}
Example #7
0
		/// <summary>
		/// Opens a long-poll modeled connection to retrieve updated information from the Steam server.
		/// </summary>
		private async void BeginPoll() {

			IndicateConnectionState( ClientConnectionStatus.Connecting );

			SteamRequest requestBase = new SteamRequest( "ISteamWebUserPresenceOAuth", "Poll", "v0001", HttpMethod.Post );
			requestBase.AddParameter( "umqid", ChatSession.ChatSessionID, ParameterType.GetOrPost );
			requestBase.AddParameter( "sectimeout", 20, ParameterType.GetOrPost );

			if( Authenticator != null ) {
				Authenticator.Authenticate( this, requestBase );
			}

			try {

				using( var client = new HttpClient() ) {

					Cancellation.Token.Register( () => client.CancelPendingRequests() );
					client.Timeout = TimeSpan.FromSeconds( 25 );

					while( true ) {

						requestBase.AddParameter( "message", LastMessageSentID, ParameterType.GetOrPost );

						using( var httpRequest = BuildHttpRequest( requestBase ) ) {

							try {

								using( var response = await client.SendAsync( httpRequest, HttpCompletionOption.ResponseContentRead ).ConfigureAwait( false ) ) {

									SteamChatPollResult result = SteamInterface.VerifyAndDeserialize<SteamChatPollResult>( ConvertToResponse( requestBase, response, null ) );

									IndicateConnectionState( ClientConnectionStatus.Connected );

									if( result.PollStatus == ChatPollStatus.OK ) {
										LastMessageSentID = result.PollLastMessageSentID;
										if( result.Messages != null )
											ProcessMessagesReceived( result );
									}

									await Task.Delay( 1000, Cancellation.Token );

								}

							} catch( Exception e ) {
								System.Diagnostics.Debug.WriteLine( e.ToString() );
								throw e;
							}

						}

					}

				}

			} catch( Exception e ) {
				System.Diagnostics.Debug.WriteLine( e.ToString() );
				IndicateConnectionState( ClientConnectionStatus.Disconnected );
				if( e is OperationCanceledException || e is TaskCanceledException ) {
					Cancellation.Dispose();
					Cancellation = new CancellationTokenSource();
					return;
				} else if( e is SteamRequestException ) {
					if( ( e as SteamRequestException ).StatusCode == HttpStatusCode.NotFound ) {
						// Network Problem
						return;
					}else if( ( e as SteamRequestException ).StatusCode == HttpStatusCode.Unauthorized ){
						// User is Unauthorized
						throw new SteamAuthenticationException( "SteamChat Client: User is Unauthorized", e );
					}
					// Likely a transient Steam API problem
					System.Diagnostics.Debug.WriteLine( "SteamRequestException Encountered: " + ( e as SteamRequestException ).StatusCode );
				}
				System.Diagnostics.Debug.WriteLine( "Encountered Unexpected Exception: " + e.StackTrace );
				throw e;
			}

		}
Example #8
0
		/// <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;

		}
Example #9
0
		/// <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 )
			};

		}
Example #10
0
		/// <summary>
		/// (Asynchronous) Returns a list of stats for this user by GameID (App ID).
		/// Throws <see cref="SteamRequestException"/> on failure.
		/// <a href="https://developer.valvesoftware.com/wiki/Steam_Web_API#GetUserStatsForGame_.28v0002.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="gameID">AppID of the game you want the news of.</param>
		/// <returns><see cref="PlayerStats"/> object containing game name and list of <see cref="Stat"/> objects.</returns>
		public async static Task<PlayerStats> GetUserStatsForGameAsync( SteamClient client, string steamID, int gameID ) {

			SteamRequest request = new SteamRequest( SteamAPIInterface.ISteamUserStats, "GetUserStatsForGame", SteamMethodVersion.v0002 );
			request.AddParameter( "appid", gameID );
			request.AddParameter( "steamid", steamID );

			return VerifyAndDeserialize<GetUserStatsForGameResponse>( ( await client.ExecuteAsync( request ) ) ).PlayerStats;

		}
Example #11
0
		/// <summary>
		/// (Asynchronous) Returns a list of achievements for the requested user by GameID (AppID)
		/// Throws <see cref="SteamRequestException"/> on failure.
		/// <a href="https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerAchievements_.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="gameID">AppID of the game you want the news of.</param>
		/// <param name="returnLanguage">Desired language for the "name" and "description" properties of returned <see cref="Achievement"/> objects.</param>
		/// <returns><see cref="PlayerAchievements"/> object containing game name and list of <see cref="Achievement"/> objects.</returns>
		public async static Task<PlayerAchievements> GetPlayerAchievementsAsync( SteamClient client, string steamID, int gameID, RequestedLangage returnLanguage ) {

			SteamRequest request = new SteamRequest( SteamAPIInterface.ISteamUserStats, "GetPlayerAchievements", SteamMethodVersion.v0001 );
			request.AddParameter( "appid", gameID );
			request.AddParameter( "steamid", steamID );

			request.AddParameter( "l", GetLanguageFromEnum( returnLanguage ) );

			return VerifyAndDeserialize<GetPlayerAchievementsResponse>( ( await client.ExecuteAsync( request ) ) ).PlayerAchievements;

		}
Example #12
0
		/// <summary>
		/// (Requires Authentication) (Async) Returns a list of games a player has played in the last two weeks.
		/// Throws <see cref="SteamRequestException"/> on failure.
		/// <a href="https://developer.valvesoftware.com/wiki/Steam_Web_API#GetRecentlyPlayedGames_.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="maxSelect">Optionally limit response to a certain number of games. Defaults to -1, meaning no limit is imposed.</param>
		/// <returns><see cref="OwnedGames"/> object containing information about the specified user's game collection.</returns>
		public async static Task<PlayedGames> GetRecentlyPlayedGamesAsync( SteamClient client, string steamID, int maxSelect = -1 ) {

			SteamRequest request = new SteamRequest( SteamAPIInterface.IPlayerService, "GetRecentlyPlayedGames", SteamMethodVersion.v0001 );
			request.AddParameter( "steamid", steamID, ParameterType.QueryString );

			if( maxSelect > 0 ) 
				request.AddParameter( "count", maxSelect, ParameterType.QueryString );

			return VerifyAndDeserialize<GetRecentlyPlayedGamesResponse>( ( await client.ExecuteAsync( request ) ) ).PlayedGames;

		}
Example #13
0
		/// <summary>
		/// (Requires Authentication) (Async) Returns the original owner's SteamID if a borrowing account is currently playing the specified game. Null if not borrowed, or the borrower isn't currently playing the game.
		/// Throws <see cref="SteamRequestException"/> on failure.
		/// <a href="https://developer.valvesoftware.com/wiki/Steam_Web_API#IsPlayingSharedGame_.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="gameID">GameID (AppID) of the game you're interested in querying.</param>
		/// <returns></returns>
		public async static Task<SharedGameData> IsPlayingSharedGameAsync( SteamClient client, string steamID, int gameID ) {

			SteamRequest request = new SteamRequest( SteamAPIInterface.IPlayerService, "IsPlayingSharedGame", SteamMethodVersion.v0001 );
			request.AddParameter( "steamid", steamID, ParameterType.QueryString );
			request.AddParameter( "appid_playing", gameID, ParameterType.QueryString );

			IsPlayingSharedGameObject obj = VerifyAndDeserialize<IsPlayingSharedGameResponse>( ( await client.ExecuteAsync( request ) ) ).IsPlayingSharedGame;

			if( String.IsNullOrEmpty( obj.LenderSteamID ) || obj.LenderSteamID == "0" ) {
				return new SharedGameData {
					IsUserPlayingSharedGame = false,
					GameOwnerSteamID = null,
					GameBorrowerSteamID = null
				};
			} else {
				return new SharedGameData {
					IsUserPlayingSharedGame = true,
					GameOwnerSteamID = obj.LenderSteamID,
					GameBorrowerSteamID = steamID
				};
			}

		}