diff --git a/Facepunch.Steamworks/Client/Friends.cs b/Facepunch.Steamworks/Client/Friends.cs index 3dbe954..fcfb094 100644 --- a/Facepunch.Steamworks/Client/Friends.cs +++ b/Facepunch.Steamworks/Client/Friends.cs @@ -22,130 +22,6 @@ public Friends Friends } } - public class SteamFriend - { - /// - /// Steam Id - /// - public ulong Id { get; internal set; } - - - /// - /// Return true if blocked - /// - public bool IsBlocked => relationship == FriendRelationship.Blocked; - - /// - /// Return true if is a friend. Returns false if blocked, request etc. - /// - public bool IsFriend => relationship == FriendRelationship.Friend; - - /// - /// Their current display name - /// - public string Name; - - /// - /// Returns true if this friend is online - /// - public bool IsOnline => personaState != PersonaState.Offline; - - /// - /// Returns true if this friend is marked as away - /// - public bool IsAway => personaState == PersonaState.Away; - - /// - /// Returns true if this friend is marked as busy - /// - public bool IsBusy => personaState == PersonaState.Busy; - - /// - /// Returns true if this friend is marked as snoozing - /// - public bool IsSnoozing => personaState == PersonaState.Snooze; - - /// - /// Returns true if this friend is online and playing this game - /// - public bool IsPlayingThisGame => CurrentAppId == Client.AppId; - - /// - /// Returns true if this friend is online and playing this game - /// - public bool IsPlaying => CurrentAppId != 0; - - /// - /// The AppId this guy is playing - /// - public ulong CurrentAppId { get; internal set; } - - public uint ServerIp { get; internal set; } - public int ServerGamePort { get; internal set; } - public int ServerQueryPort { get; internal set; } - public ulong ServerLobbyId { get; internal set; } - - internal Client Client { get; set; } - private PersonaState personaState; - private FriendRelationship relationship; - - /// - /// Returns null if the value doesn't exist - /// - public string GetRichPresence( string key ) - { - var val = Client.native.friends.GetFriendRichPresence( Id, key ); - if ( string.IsNullOrEmpty( val ) ) return null; - return val; - } - - /// - /// Update this friend, request the latest data from Steam's servers - /// - public void Refresh() - { - Name = Client.native.friends.GetFriendPersonaName( Id ); - - relationship = Client.native.friends.GetFriendRelationship( Id ); - personaState = Client.native.friends.GetFriendPersonaState( Id ); - - CurrentAppId = 0; - ServerIp = 0; - ServerGamePort = 0; - ServerQueryPort = 0; - ServerLobbyId = 0; - - var gameInfo = new SteamNative.FriendGameInfo_t(); - if ( Client.native.friends.GetFriendGamePlayed( Id, ref gameInfo ) && gameInfo.GameID > 0 ) - { - CurrentAppId = gameInfo.GameID; - ServerIp = gameInfo.GameIP; - ServerGamePort = gameInfo.GamePort; - ServerQueryPort = gameInfo.QueryPort; - ServerLobbyId = gameInfo.SteamIDLobby; - } - - Client.native.friends.RequestFriendRichPresence( Id ); - } - - /// - /// This will return null if you don't have the target user's avatar in your cache. - /// Which usually happens for people not on your friends list. - /// - public Image GetAvatar( Friends.AvatarSize size ) - { - return Client.Friends.GetCachedAvatar( size, Id ); - } - - /// - /// Invite this friend to the game that we are playing - /// - public bool InviteToGame(string Text) - { - return Client.native.friends.InviteUserToGame(Id, Text); - } - } - /// /// Handles most interactions with people in Steam, not just friends as the name would suggest. /// diff --git a/Facepunch.Steamworks/Client/SteamFriend.cs b/Facepunch.Steamworks/Client/SteamFriend.cs new file mode 100644 index 0000000..59457ec --- /dev/null +++ b/Facepunch.Steamworks/Client/SteamFriend.cs @@ -0,0 +1,128 @@ +using SteamNative; + +namespace Facepunch.Steamworks +{ + public class SteamFriend + { + /// + /// Steam Id + /// + public ulong Id { get; internal set; } + + + /// + /// Return true if blocked + /// + public bool IsBlocked => relationship == FriendRelationship.Blocked; + + /// + /// Return true if is a friend. Returns false if blocked, request etc. + /// + public bool IsFriend => relationship == FriendRelationship.Friend; + + /// + /// Their current display name + /// + public string Name; + + /// + /// Returns true if this friend is online + /// + public bool IsOnline => personaState != PersonaState.Offline; + + /// + /// Returns true if this friend is marked as away + /// + public bool IsAway => personaState == PersonaState.Away; + + /// + /// Returns true if this friend is marked as busy + /// + public bool IsBusy => personaState == PersonaState.Busy; + + /// + /// Returns true if this friend is marked as snoozing + /// + public bool IsSnoozing => personaState == PersonaState.Snooze; + + /// + /// Returns true if this friend is online and playing this game + /// + public bool IsPlayingThisGame => CurrentAppId == Client.AppId; + + /// + /// Returns true if this friend is online and playing this game + /// + public bool IsPlaying => CurrentAppId != 0; + + /// + /// The AppId this guy is playing + /// + public ulong CurrentAppId { get; internal set; } + + public uint ServerIp { get; internal set; } + public int ServerGamePort { get; internal set; } + public int ServerQueryPort { get; internal set; } + public ulong ServerLobbyId { get; internal set; } + + internal Client Client { get; set; } + private PersonaState personaState; + private FriendRelationship relationship; + + /// + /// Returns null if the value doesn't exist + /// + public string GetRichPresence( string key ) + { + var val = Client.native.friends.GetFriendRichPresence( Id, key ); + if ( string.IsNullOrEmpty( val ) ) return null; + return val; + } + + /// + /// Update this friend, request the latest data from Steam's servers + /// + public void Refresh() + { + Name = Client.native.friends.GetFriendPersonaName( Id ); + + relationship = Client.native.friends.GetFriendRelationship( Id ); + personaState = Client.native.friends.GetFriendPersonaState( Id ); + + CurrentAppId = 0; + ServerIp = 0; + ServerGamePort = 0; + ServerQueryPort = 0; + ServerLobbyId = 0; + + var gameInfo = new SteamNative.FriendGameInfo_t(); + if ( Client.native.friends.GetFriendGamePlayed( Id, ref gameInfo ) && gameInfo.GameID > 0 ) + { + CurrentAppId = gameInfo.GameID; + ServerIp = gameInfo.GameIP; + ServerGamePort = gameInfo.GamePort; + ServerQueryPort = gameInfo.QueryPort; + ServerLobbyId = gameInfo.SteamIDLobby; + } + + Client.native.friends.RequestFriendRichPresence( Id ); + } + + /// + /// This will return null if you don't have the target user's avatar in your cache. + /// Which usually happens for people not on your friends list. + /// + public Image GetAvatar( Friends.AvatarSize size ) + { + return Client.Friends.GetCachedAvatar( size, Id ); + } + + /// + /// Invite this friend to the game that we are playing + /// + public bool InviteToGame(string Text) + { + return Client.native.friends.InviteUserToGame(Id, Text); + } + } +}