-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteamLobbyMetadataHandler.cs
More file actions
66 lines (57 loc) · 2.26 KB
/
SteamLobbyMetadataHandler.cs
File metadata and controls
66 lines (57 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Steamworks;
namespace ContentWarningShop
{
internal static class SteamLobbyMetadataHandler
{
private static bool _initialised = false;
private static Callback<LobbyCreated_t> cb_onLobbyCreated;
private static Callback<LobbyEnter_t> cb_onLobbyEntered;
private static Callback<LobbyDataUpdate_t> cb_onLobbyDataUpdate;
//
internal static event Action? OnLobbyJoined;
internal static event Action? OnLobbyCreated;
internal static event Action? OnLobbyDataUpdate;
/// <summary>
/// The ID of the current lobby, if we are in one.
/// </summary>
/// <remarks>
/// Cleared automatically in <see cref="ShopAPI.Patches.SteamLobbyHandlerPatch.LeaveLobby"/> patch whenever the player clicks Leave.
/// </remarks>
internal static CSteamID CurrentLobby = CSteamID.Nil;
internal static bool InLobby => CurrentLobby != CSteamID.Nil;
internal static bool IsHost => SteamMatchmaking.GetLobbyOwner(CurrentLobby) == SteamUser.GetSteamID();
internal static void RegisterSteamworksCallbacks()
{
if (_initialised) return;
cb_onLobbyCreated = Callback<LobbyCreated_t>.Create(Steam_LobbyCreated);
cb_onLobbyEntered = Callback<LobbyEnter_t>.Create(Steam_LobbyEntered);
cb_onLobbyDataUpdate = Callback<LobbyDataUpdate_t>.Create(Steam_LobbyDataUpdated);
_initialised = true;
}
private static void Steam_LobbyCreated(LobbyCreated_t e)
{
if (e.m_eResult == EResult.k_EResultOK)
{
CurrentLobby = new CSteamID(e.m_ulSteamIDLobby);
OnLobbyCreated?.Invoke();
OnLobbyJoined?.Invoke();
}
}
private static void Steam_LobbyEntered(LobbyEnter_t e)
{
if (InLobby == false)
{
CurrentLobby = new CSteamID(e.m_ulSteamIDLobby);
OnLobbyJoined?.Invoke();
}
}
private static void Steam_LobbyDataUpdated(LobbyDataUpdate_t e)
{
if (e.m_ulSteamIDLobby != e.m_ulSteamIDMember)
{
return;
}
OnLobbyDataUpdate?.Invoke();
}
}
}