(965c31410a) Unstable v0.10.4.0
This commit is contained in:
@@ -10,42 +10,30 @@ namespace Steamworks
|
||||
/// <summary>
|
||||
/// Undocumented Parental Settings
|
||||
/// </summary>
|
||||
public static class SteamFriends
|
||||
public class SteamFriends : SteamClientClass<SteamFriends>
|
||||
{
|
||||
static ISteamFriends _internal;
|
||||
internal static ISteamFriends Internal
|
||||
internal static ISteamFriends Internal => Interface as ISteamFriends;
|
||||
|
||||
internal override void InitializeInterface( bool server )
|
||||
{
|
||||
get
|
||||
{
|
||||
SteamClient.ValidCheck();
|
||||
SetInterface( server, new ISteamFriends( server ) );
|
||||
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new ISteamFriends();
|
||||
_internal.Init();
|
||||
richPresence = new Dictionary<string, string>();
|
||||
|
||||
richPresence = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal = null;
|
||||
InstallEvents();
|
||||
}
|
||||
|
||||
static Dictionary<string, string> richPresence;
|
||||
|
||||
internal static void InstallEvents()
|
||||
internal void InstallEvents()
|
||||
{
|
||||
FriendStateChange_t.Install( x => OnPersonaStateChange?.Invoke( new Friend( x.SteamID ) ) );
|
||||
GameRichPresenceJoinRequested_t.Install( x => OnGameRichPresenceJoinRequested?.Invoke( new Friend( x.SteamIDFriend), x.ConnectUTF8() ) );
|
||||
GameConnectedFriendChatMsg_t.Install( OnFriendChatMessage );
|
||||
GameOverlayActivated_t.Install( x => OnGameOverlayActivated?.Invoke() );
|
||||
GameServerChangeRequested_t.Install( x => OnGameServerChangeRequested?.Invoke( x.ServerUTF8(), x.PasswordUTF8() ) );
|
||||
GameLobbyJoinRequested_t.Install( x => OnGameLobbyJoinRequested?.Invoke( new Lobby( x.SteamIDLobby ), x.SteamIDFriend ) );
|
||||
FriendRichPresenceUpdate_t.Install( x => OnFriendRichPresenceUpdate?.Invoke( new Friend( x.SteamIDFriend ) ) );
|
||||
Dispatch.Install<PersonaStateChange_t>( x => OnPersonaStateChange?.Invoke( new Friend( x.SteamID ) ) );
|
||||
Dispatch.Install<GameRichPresenceJoinRequested_t>( x => OnGameRichPresenceJoinRequested?.Invoke( new Friend( x.SteamIDFriend), x.ConnectUTF8() ) );
|
||||
Dispatch.Install<GameConnectedFriendChatMsg_t>( OnFriendChatMessage );
|
||||
Dispatch.Install<GameOverlayActivated_t>( x => OnGameOverlayActivated?.Invoke( x.Active != 0 ) );
|
||||
Dispatch.Install<GameServerChangeRequested_t>( x => OnGameServerChangeRequested?.Invoke( x.ServerUTF8(), x.PasswordUTF8() ) );
|
||||
Dispatch.Install<GameLobbyJoinRequested_t>( x => OnGameLobbyJoinRequested?.Invoke( new Lobby( x.SteamIDLobby ), x.SteamIDFriend ) );
|
||||
Dispatch.Install<FriendRichPresenceUpdate_t>( x => OnFriendRichPresenceUpdate?.Invoke( new Friend( x.SteamIDFriend ) ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,7 +58,7 @@ namespace Steamworks
|
||||
/// Posted when game overlay activates or deactivates
|
||||
/// the game can use this to be pause or resume single player games
|
||||
/// </summary>
|
||||
public static event Action OnGameOverlayActivated;
|
||||
public static event Action<bool> OnGameOverlayActivated;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the user tries to join a different game server from their friends list
|
||||
@@ -95,20 +83,25 @@ namespace Steamworks
|
||||
|
||||
var friend = new Friend( data.SteamIDUser );
|
||||
|
||||
var buffer = Helpers.TakeBuffer( 1024 * 32 );
|
||||
var buffer = Helpers.TakeMemory();
|
||||
var type = ChatEntryType.ChatMsg;
|
||||
|
||||
fixed ( byte* ptr = buffer )
|
||||
var len = Internal.GetFriendMessage( data.SteamIDUser, data.MessageID, buffer, Helpers.MemoryBufferSize, ref type );
|
||||
|
||||
if ( len == 0 && type == ChatEntryType.Invalid )
|
||||
return;
|
||||
|
||||
var typeName = type.ToString();
|
||||
var message = Helpers.MemoryToString( buffer );
|
||||
|
||||
OnChatMessage( friend, typeName, message );
|
||||
}
|
||||
|
||||
private static IEnumerable<Friend> GetFriendsWithFlag(FriendFlags flag)
|
||||
{
|
||||
for ( int i=0; i<Internal.GetFriendCount( (int)flag); i++ )
|
||||
{
|
||||
var len = Internal.GetFriendMessage( data.SteamIDUser, data.MessageID, (IntPtr)ptr, buffer.Length, ref type );
|
||||
|
||||
if ( len == 0 && type == ChatEntryType.Invalid )
|
||||
return;
|
||||
|
||||
var typeName = type.ToString();
|
||||
var message = Encoding.UTF8.GetString( buffer, 0, len );
|
||||
|
||||
OnChatMessage( friend, typeName, message );
|
||||
yield return new Friend( Internal.GetFriendByIndex( i, (int)flag ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,18 +112,32 @@ namespace Steamworks
|
||||
|
||||
public static IEnumerable<Friend> GetFriends()
|
||||
{
|
||||
for ( int i=0; i<Internal.GetFriendCount( (int) FriendFlags.Immediate ); i++ )
|
||||
{
|
||||
yield return new Friend( Internal.GetFriendByIndex( i, (int)FriendFlags.Immediate ) );
|
||||
}
|
||||
return GetFriendsWithFlag(FriendFlags.Immediate);
|
||||
}
|
||||
|
||||
public static IEnumerable<Friend> GetBlocked()
|
||||
{
|
||||
for ( int i = 0; i < Internal.GetFriendCount( (int)FriendFlags.Blocked ); i++ )
|
||||
{
|
||||
yield return new Friend( Internal.GetFriendByIndex( i, (int)FriendFlags.Blocked) );
|
||||
}
|
||||
return GetFriendsWithFlag(FriendFlags.Blocked);
|
||||
}
|
||||
|
||||
public static IEnumerable<Friend> GetFriendsRequested()
|
||||
{
|
||||
return GetFriendsWithFlag( FriendFlags.FriendshipRequested );
|
||||
}
|
||||
|
||||
public static IEnumerable<Friend> GetFriendsClanMembers()
|
||||
{
|
||||
return GetFriendsWithFlag( FriendFlags.ClanMember );
|
||||
}
|
||||
|
||||
public static IEnumerable<Friend> GetFriendsOnGameServer()
|
||||
{
|
||||
return GetFriendsWithFlag( FriendFlags.OnGameServer );
|
||||
}
|
||||
|
||||
public static IEnumerable<Friend> GetFriendsRequestingFriendship()
|
||||
{
|
||||
return GetFriendsWithFlag( FriendFlags.RequestingFriendship );
|
||||
}
|
||||
|
||||
public static IEnumerable<Friend> GetPlayedWith()
|
||||
@@ -141,6 +148,22 @@ namespace Steamworks
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<Friend> GetFromSource( SteamId steamid )
|
||||
{
|
||||
for ( int i = 0; i < Internal.GetFriendCountFromSource( steamid ); i++ )
|
||||
{
|
||||
yield return new Friend( Internal.GetFriendFromSourceByIndex( steamid, i ) );
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<Clan> GetClans()
|
||||
{
|
||||
for (int i = 0; i < Internal.GetClanCount(); i++)
|
||||
{
|
||||
yield return new Clan( Internal.GetClanByIndex( i ) );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The dialog to open. Valid options are:
|
||||
/// "friends",
|
||||
@@ -258,8 +281,12 @@ namespace Steamworks
|
||||
/// </summary>
|
||||
public static bool SetRichPresence( string key, string value )
|
||||
{
|
||||
richPresence[key] = value;
|
||||
return Internal.SetRichPresence( key, value );
|
||||
bool success = Internal.SetRichPresence( key, value );
|
||||
|
||||
if ( success )
|
||||
richPresence[key] = value;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -289,5 +316,36 @@ namespace Steamworks
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public static async Task<bool> IsFollowing(SteamId steamID)
|
||||
{
|
||||
var r = await Internal.IsFollowing(steamID);
|
||||
return r.Value.IsFollowing;
|
||||
}
|
||||
|
||||
public static async Task<int> GetFollowerCount(SteamId steamID)
|
||||
{
|
||||
var r = await Internal.GetFollowerCount(steamID);
|
||||
return r.Value.Count;
|
||||
}
|
||||
|
||||
public static async Task<SteamId[]> GetFollowingList()
|
||||
{
|
||||
int resultCount = 0;
|
||||
var steamIds = new List<SteamId>();
|
||||
|
||||
FriendsEnumerateFollowingList_t? result;
|
||||
|
||||
do
|
||||
{
|
||||
if ( (result = await Internal.EnumerateFollowingList((uint)resultCount)) != null)
|
||||
{
|
||||
resultCount += result.Value.ResultsReturned;
|
||||
|
||||
Array.ForEach(result.Value.GSteamID, id => { if (id > 0) steamIds.Add(id); });
|
||||
}
|
||||
} while (result != null && resultCount < result.Value.TotalResultCount);
|
||||
|
||||
return steamIds.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user