mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-07-20 20:26:23 +03:00
Friends base
This commit is contained in:
parent
6fa147141a
commit
088e9918e0
@ -2,32 +2,49 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Facepunch.Steamworks.Test
|
namespace Steamworks
|
||||||
{
|
{
|
||||||
[DeploymentItem( "steam_api64.dll" )]
|
[DeploymentItem( "steam_api64.dll" )]
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class Friends
|
public class FriendsTest
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void FriendList()
|
public void GetFriends()
|
||||||
{
|
{
|
||||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
foreach ( var friend in Friends.GetFriends() )
|
||||||
{
|
{
|
||||||
Assert.IsTrue( client.IsValid );
|
Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
|
||||||
|
Console.WriteLine( $" {string.Join( ", ", friend.NameHistory)}" );
|
||||||
|
|
||||||
client.Friends.Refresh();
|
// Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
|
||||||
|
}
|
||||||
Assert.IsNotNull( client.Friends.All );
|
|
||||||
|
|
||||||
foreach ( var friend in client.Friends.All )
|
|
||||||
{
|
|
||||||
Console.WriteLine( "{0}: {1} (Friend:{2}) (Blocked:{3})", friend.Id, friend.Name, friend.IsFriend, friend.IsBlocked );
|
|
||||||
|
|
||||||
Assert.IsNotNull(friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void GetBlocked()
|
||||||
|
{
|
||||||
|
foreach ( var friend in Friends.GetBlocked() )
|
||||||
|
{
|
||||||
|
Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
|
||||||
|
Console.WriteLine( $" {string.Join( ", ", friend.NameHistory )}" );
|
||||||
|
|
||||||
|
// Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void GetPlayedWith()
|
||||||
|
{
|
||||||
|
foreach ( var friend in Friends.GetPlayedWith() )
|
||||||
|
{
|
||||||
|
Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
|
||||||
|
Console.WriteLine( $" {string.Join( ", ", friend.NameHistory )}" );
|
||||||
|
|
||||||
|
// Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void FriendListWithoutRefresh()
|
public void FriendListWithoutRefresh()
|
||||||
{
|
{
|
||||||
@ -119,5 +136,6 @@ namespace Facepunch.Steamworks.Test
|
|||||||
Console.WriteLine( str );
|
Console.WriteLine( str );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
73
Facepunch.Steamworks/Redux/Friends.cs
Normal file
73
Facepunch.Steamworks/Redux/Friends.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SteamNative;
|
||||||
|
|
||||||
|
namespace Steamworks
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Undocumented Parental Settings
|
||||||
|
/// </summary>
|
||||||
|
public static class Friends
|
||||||
|
{
|
||||||
|
static Internal.ISteamFriends _internal;
|
||||||
|
internal static Internal.ISteamFriends Internal
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( _internal == null )
|
||||||
|
_internal = new Internal.ISteamFriends();
|
||||||
|
|
||||||
|
return _internal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void InstallEvents()
|
||||||
|
{
|
||||||
|
//new Event<BroadcastUploadStart_t>( x => OnBroadcastStarted?.Invoke() );
|
||||||
|
//new Event<BroadcastUploadStop_t>( x => OnBroadcastStopped?.Invoke( x.Result ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static event Action OnBroadcastStarted;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// returns the local players name - guaranteed to not be NULL.
|
||||||
|
/// this is the same name as on the users community profile page
|
||||||
|
/// </summary>
|
||||||
|
public static string PersonaName => Internal.GetPersonaName();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// gets the status of the current user
|
||||||
|
/// </summary>
|
||||||
|
public static PersonaState PersonaState => Internal.GetPersonaState();
|
||||||
|
|
||||||
|
public static IEnumerable<Friend> GetFriends()
|
||||||
|
{
|
||||||
|
for ( int i=0; i<Internal.GetFriendCount( (int) FriendFlags.Immediate ); i++ )
|
||||||
|
{
|
||||||
|
yield return new Friend( Internal.GetFriendByIndex( i, 0xFFFF ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<Friend> GetBlocked()
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < Internal.GetFriendCount( (int)FriendFlags.Blocked ); i++ )
|
||||||
|
{
|
||||||
|
yield return new Friend( Internal.GetFriendByIndex( i, 0xFFFF ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<Friend> GetPlayedWith()
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < Internal.GetFriendCount( (int)FriendFlags.Blocked ); i++ )
|
||||||
|
{
|
||||||
|
yield return new Friend( Internal.GetFriendByIndex( i, 0xFFFF ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
79
Facepunch.Steamworks/Redux/Structs/Friend.cs
Normal file
79
Facepunch.Steamworks/Redux/Structs/Friend.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using SteamNative;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Steamworks
|
||||||
|
{
|
||||||
|
public struct Friend
|
||||||
|
{
|
||||||
|
public CSteamID Id;
|
||||||
|
|
||||||
|
public Friend( CSteamID steamid )
|
||||||
|
{
|
||||||
|
Id = steamid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsFriend => Relationship == FriendRelationship.Friend;
|
||||||
|
public bool IsBlocked => Relationship == FriendRelationship.Blocked;
|
||||||
|
|
||||||
|
|
||||||
|
public FriendRelationship Relationship => Friends.Internal.GetFriendRelationship( Id );
|
||||||
|
public PersonaState State => Friends.Internal.GetFriendPersonaState( Id );
|
||||||
|
public string Name => Friends.Internal.GetFriendPersonaName( Id );
|
||||||
|
public IEnumerable<string> NameHistory
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
for( int i=0; i<32; i++ )
|
||||||
|
{
|
||||||
|
var n = Friends.Internal.GetFriendPersonaNameHistory( Id, i );
|
||||||
|
if ( string.IsNullOrEmpty( n ) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
yield return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SteamLevel => Friends.Internal.GetFriendSteamLevel( Id );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public FriendGameInfo? GameInfo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
FriendGameInfo_t gameInfo = default( FriendGameInfo_t );
|
||||||
|
if ( !Friends.Internal.GetFriendGamePlayed( Id, ref gameInfo ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return FriendGameInfo.From( gameInfo );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct FriendGameInfo
|
||||||
|
{
|
||||||
|
internal ulong GameID; // m_gameID class CGameID
|
||||||
|
internal uint GameIP; // m_unGameIP uint32
|
||||||
|
internal ushort GamePort; // m_usGamePort uint16
|
||||||
|
internal ushort QueryPort; // m_usQueryPort uint16
|
||||||
|
internal ulong SteamIDLobby; // m_steamIDLobby class CSteamID
|
||||||
|
|
||||||
|
public static FriendGameInfo From( FriendGameInfo_t i )
|
||||||
|
{
|
||||||
|
return new FriendGameInfo
|
||||||
|
{
|
||||||
|
GameID = i.GameID,
|
||||||
|
GameIP = i.GameIP,
|
||||||
|
GamePort = i.GamePort,
|
||||||
|
QueryPort = i.QueryPort,
|
||||||
|
SteamIDLobby = i.SteamIDLobby,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -38,6 +38,9 @@ namespace Steamworks.Internal
|
|||||||
|
|
||||||
internal string GetString( IntPtr p )
|
internal string GetString( IntPtr p )
|
||||||
{
|
{
|
||||||
|
if ( p == IntPtr.Zero )
|
||||||
|
return null;
|
||||||
|
|
||||||
// return Marshal.PtrToStringUTF8( p );
|
// return Marshal.PtrToStringUTF8( p );
|
||||||
lock ( stringbuffer )
|
lock ( stringbuffer )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user