Lobby Events

This commit is contained in:
Garry Newman 2019-05-01 16:30:28 +01:00
parent e3840a9a3a
commit fbad8b8d6e
4 changed files with 103 additions and 8 deletions

View File

@ -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
{

View File

@ -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;

View File

@ -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 ) );
}
}
}
/// <summary>
/// Someone invited you to a lobby
/// </summary>
public static event Action<Friend, Lobby> OnLobbyInvite;
/// <summary>
/// The lobby metadata has changed
/// </summary>
public static event Action<Lobby> OnLobbyDataChanged;
/// <summary>
/// The lobby member metadata has changed
/// </summary>
public static event Action<Lobby, Friend> OnLobbyMemberDataChanged;
/// <summary>
/// The lobby member joined
/// </summary>
public static event Action<Lobby, Friend> OnLobbyMemberJoined;
/// <summary>
/// The lobby member left the room
/// </summary>
public static event Action<Lobby, Friend> OnLobbyMemberLeft;
/// <summary>
/// The lobby member left the room
/// </summary>
public static event Action<Lobby, Friend> OnLobbyMemberDisconnected;
/// <summary>
/// The lobby member was kicked. The 3rd param is the user that kicked them.
/// </summary>
public static event Action<Lobby, Friend, Friend> OnLobbyMemberKicked;
/// <summary>
/// The lobby member was banned. The 3rd param is the user that banned them.
/// </summary>
public static event Action<Lobby, Friend, Friend> OnLobbyMemberBanned;
/// <summary>
/// A chat message was recieved from a member of a lobby
/// </summary>
public static event Action<Lobby, Friend, string> OnChatMessage;
public static LobbyQuery LobbyList => new LobbyQuery();
/// <summary>

View File

@ -8,6 +8,12 @@ namespace Steamworks.Data
{
public SteamId Id { get; internal set; }
internal Lobby( SteamId id )
{
Id = id;
}
/// <summary>
/// Try to join this room. Will return RoomEnter.Success on success,
/// and anything else is a failure
@ -135,8 +141,10 @@ namespace Steamworks.Data
/// <summary>
/// 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
/// </summary>
public unsafe bool SendChatBytes( byte[] data )
internal unsafe bool SendChatBytes( byte[] data )
{
fixed ( byte* ptr = data )
{