diff --git a/Facepunch.Steamworks.Test/GameServerTest.cs b/Facepunch.Steamworks.Test/GameServerTest.cs index 0af92b5..6ed4150 100644 --- a/Facepunch.Steamworks.Test/GameServerTest.cs +++ b/Facepunch.Steamworks.Test/GameServerTest.cs @@ -5,9 +5,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Steamworks { [DeploymentItem( "steam_api64.dll" )] - [DeploymentItem( "tier0_s64.dll" )] - [DeploymentItem( "vstdlib_s64.dll" )] - [DeploymentItem( "steamclient64.dll" )] [TestClass] public partial class GameServerTest { diff --git a/Facepunch.Steamworks.Test/SteamMatchmakingTest.cs b/Facepunch.Steamworks.Test/SteamMatchmakingTest.cs index c385b13..484844f 100644 --- a/Facepunch.Steamworks.Test/SteamMatchmakingTest.cs +++ b/Facepunch.Steamworks.Test/SteamMatchmakingTest.cs @@ -45,8 +45,7 @@ namespace Steamworks var lobbyr = await SteamMatchmaking.CreateLobbyAsync( 32 ); if ( !lobbyr.HasValue ) { - Console.WriteLine( "No lobby created!" ); - return; + Assert.Fail(); } var lobby = lobbyr.Value; diff --git a/Facepunch.Steamworks/SteamMatchmaking.cs b/Facepunch.Steamworks/SteamMatchmaking.cs index 3de8d5c..a180305 100644 --- a/Facepunch.Steamworks/SteamMatchmaking.cs +++ b/Facepunch.Steamworks/SteamMatchmaking.cs @@ -31,10 +31,101 @@ namespace Steamworks internal static void InstallEvents() { - //PlaybackStatusHasChanged_t.Install( x => OnPlaybackChanged?.Invoke() ); - //VolumeHasChanged_t.Install( x => OnVolumeChanged?.Invoke( x.NewVolume ) ); + LobbyInvite_t.Install( x => OnLobbyInvite?.Invoke( new Friend( x.SteamIDUser ), new Lobby( x.SteamIDLobby ) ) ); + + LobbyDataUpdate_t.Install( x => + { + if ( x.Success == 0 ) return; + + if ( x.SteamIDLobby == x.SteamIDMember ) + OnLobbyDataChanged?.Invoke( new Lobby( x.SteamIDLobby ) ); + else + OnLobbyMemberDataChanged?.Invoke( new Lobby( x.SteamIDLobby ), new Friend( x.SteamIDMember ) ); + } ); + + LobbyChatUpdate_t.Install( x => + { + if ( (x.GfChatMemberStateChange & (int)ChatMemberStateChange.Entered) != 0 ) + OnLobbyMemberJoined?.Invoke( new Lobby( x.SteamIDLobby ), new Friend( x.SteamIDUserChanged ) ); + + if ( (x.GfChatMemberStateChange & (int)ChatMemberStateChange.Left) != 0 ) + OnLobbyMemberLeft?.Invoke( new Lobby( x.SteamIDLobby ), new Friend( x.SteamIDUserChanged ) ); + + if ( (x.GfChatMemberStateChange & (int)ChatMemberStateChange.Disconnected) != 0 ) + OnLobbyMemberDisconnected?.Invoke( new Lobby( x.SteamIDLobby ), new Friend( x.SteamIDUserChanged ) ); + + if ( (x.GfChatMemberStateChange & (int)ChatMemberStateChange.Kicked) != 0 ) + OnLobbyMemberKicked?.Invoke( new Lobby( x.SteamIDLobby ), new Friend( x.SteamIDUserChanged ), new Friend( x.SteamIDMakingChange ) ); + + if ( (x.GfChatMemberStateChange & (int)ChatMemberStateChange.Banned) != 0 ) + OnLobbyMemberBanned?.Invoke( new Lobby( x.SteamIDLobby ), new Friend( x.SteamIDUserChanged ), new Friend( x.SteamIDMakingChange ) ); + } ); + + LobbyChatMsg_t.Install( OnLobbyChatMessageRecievedAPI ); } + static private unsafe void OnLobbyChatMessageRecievedAPI( LobbyChatMsg_t callback ) + { + SteamId steamid = default; + ChatEntryType chatEntryType = default; + var buffer = Helpers.TakeBuffer( 1024 * 4 ); + + fixed ( byte* p = buffer ) + { + var readData = Internal.GetLobbyChatEntry( callback.SteamIDLobby, (int)callback.ChatID, ref steamid, (IntPtr)p, buffer.Length, ref chatEntryType ); + + if ( readData > 0 ) + { + OnChatMessage?.Invoke( new Lobby( callback.SteamIDLobby ), new Friend( steamid ), Encoding.UTF8.GetString( buffer, 0, readData ) ); + } + } + } + + /// + /// Someone invited you to a lobby + /// + public static event Action OnLobbyInvite; + + /// + /// The lobby metadata has changed + /// + public static event Action OnLobbyDataChanged; + + /// + /// The lobby member metadata has changed + /// + public static event Action OnLobbyMemberDataChanged; + + /// + /// The lobby member joined + /// + public static event Action OnLobbyMemberJoined; + + /// + /// The lobby member left the room + /// + public static event Action OnLobbyMemberLeft; + + /// + /// The lobby member left the room + /// + public static event Action OnLobbyMemberDisconnected; + + /// + /// The lobby member was kicked. The 3rd param is the user that kicked them. + /// + public static event Action OnLobbyMemberKicked; + + /// + /// The lobby member was banned. The 3rd param is the user that banned them. + /// + public static event Action OnLobbyMemberBanned; + + /// + /// A chat message was recieved from a member of a lobby + /// + public static event Action OnChatMessage; + public static LobbyQuery LobbyList => new LobbyQuery(); /// diff --git a/Facepunch.Steamworks/Structs/Lobby.cs b/Facepunch.Steamworks/Structs/Lobby.cs index 3c2fdeb..46a1bcd 100644 --- a/Facepunch.Steamworks/Structs/Lobby.cs +++ b/Facepunch.Steamworks/Structs/Lobby.cs @@ -8,6 +8,12 @@ namespace Steamworks.Data { public SteamId Id { get; internal set; } + + internal Lobby( SteamId id ) + { + Id = id; + } + /// /// Try to join this room. Will return RoomEnter.Success on success, /// and anything else is a failure @@ -135,8 +141,10 @@ namespace Steamworks.Data /// /// Sends bytes the the chat room + /// this isn't exposed because there's no way to read raw bytes atm, + /// and I figure people can send json if they want something more advanced /// - public unsafe bool SendChatBytes( byte[] data ) + internal unsafe bool SendChatBytes( byte[] data ) { fixed ( byte* ptr = data ) {