-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworking.cs
55 lines (45 loc) · 1.64 KB
/
Networking.cs
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
using System;
using System.Text;
using System.Threading.Tasks;
using Steamworksnt.SteamworksApi;
namespace Steamworksnt
{
public static class Networking
{
private static readonly IntPtr iSteamNetworkingMessages =
Api.SteamAPI_SteamNetworkingMessages_SteamAPI_v002();
private static readonly IntPtr iSteamMatchmaking = Api.SteamAPI_SteamMatchmaking_v009();
/// <summary>
/// This should be called once before using this class.
/// </summary>
public static void Init()
{
// Let Steam know we intend to use their relay network (init early).
// Api.SteamAPI_ISteamNetworkingUtils_InitRelayNetworkAccess(iSteamNetworkingUtils);
}
public static void SendMessage(string message)
{
UnityEngine.Debug.Log($"Sending message \"{message}\"");
byte[] bytes = Encoding.UTF8.GetBytes(message);
EResult result = Api.SteamAPI_ISteamNetworkingMessages_SendMessageToUser(
iSteamNetworkingMessages,
new SteamNetworkingIdentity(),
bytes,
(uint)bytes.Length,
0,
0
);
UnityEngine.Debug.Log($"Got result: {result}");
}
public static async Task CreateLobby()
{
var call = Api.SteamAPI_ISteamMatchmaking_CreateLobby(
iSteamMatchmaking,
ELobbyType.k_ELobbyTypeFriendsOnly,
250
);
LobbyCreated_t result = await call.GetResult();
UnityEngine.Debug.Log($"Got lobby creation result!");
}
}
}