From 0eb3672674cb3a5a685745e10fe44c9c95d6e035 Mon Sep 17 00:00:00 2001 From: kamyker Date: Fri, 28 Aug 2020 13:07:27 +0200 Subject: [PATCH] Added clan chat --- Facepunch.Steamworks/SteamFriends.cs | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Facepunch.Steamworks/SteamFriends.cs b/Facepunch.Steamworks/SteamFriends.cs index e2a8b0b..b6998da 100644 --- a/Facepunch.Steamworks/SteamFriends.cs +++ b/Facepunch.Steamworks/SteamFriends.cs @@ -30,6 +30,7 @@ namespace Steamworks Dispatch.Install( x => OnPersonaStateChange?.Invoke( new Friend( x.SteamID ) ) ); Dispatch.Install( x => OnGameRichPresenceJoinRequested?.Invoke( new Friend( x.SteamIDFriend), x.ConnectUTF8() ) ); Dispatch.Install( OnFriendChatMessage ); + Dispatch.Install( OnGameConnectedClanChatMessage ); Dispatch.Install( x => OnGameOverlayActivated?.Invoke( x.Active != 0 ) ); Dispatch.Install( x => OnGameServerChangeRequested?.Invoke( x.ServerUTF8(), x.PasswordUTF8() ) ); Dispatch.Install( x => OnGameLobbyJoinRequested?.Invoke( new Lobby( x.SteamIDLobby ), x.SteamIDFriend ) ); @@ -43,6 +44,11 @@ namespace Steamworks /// public static event Action OnChatMessage; + /// + /// Called when a chat message has been received in a Steam group chat that we are in. Associated Functions: JoinClanChatRoom. (friend, msgtype, message) + /// + public static event Action OnClanChatMessage; + /// /// called when a friends' status changes /// @@ -104,7 +110,28 @@ namespace Steamworks OnChatMessage( friend, typeName, message ); } - + + static unsafe void OnGameConnectedClanChatMessage( GameConnectedClanChatMsg_t data ) + { + if ( OnClanChatMessage == null ) return; + + var friend = new Friend( data.SteamIDUser ); + + var buffer = Helpers.TakeMemory(); + var type = ChatEntryType.ChatMsg; + SteamId chatter = data.SteamIDUser; + + var len = Internal.GetClanChatMessage( data.SteamIDClanChat, data.MessageID, buffer, Helpers.MemoryBufferSize, ref type, ref chatter ); + + if ( len == 0 && type == ChatEntryType.Invalid ) + return; + + var typeName = type.ToString(); + var message = Helpers.MemoryToString( buffer ); + + OnClanChatMessage( friend, typeName, message ); + } + private static IEnumerable GetFriendsWithFlag(FriendFlags flag) { for ( int i=0; i JoinClanChatRoom( SteamId chatId ) + { + var result = await Internal.JoinClanChatRoom( chatId ); + if ( !result.HasValue ) + return false; + + return result.Value.ChatRoomEnterResponse == RoomEnter.Success ; + } + + public static bool SendClanChatRoomMessage( SteamId chatId, string message ) + { + return Internal.SendClanChatMessage( chatId, message ); + } } }