forked from FoxCouncil/Steamworks.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteamMatchmakingServers.cs
345 lines (233 loc) · 15 KB
/
SteamMatchmakingServers.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
// !! // Steamworks.Core - SteamMatchmakingServers.cs
// *.-". // Created: 2016-10-20 [6:41 PM]
// | | // Copyright 2016 // MIT License // The Fox Council
// Modified by: Fox Diller on 2016-10-22 @ 3:03 PM
#region Usings
using System;
using System.Runtime.InteropServices;
#endregion
namespace Steamworks.Core
{
public class SteamMatchmakingServers : ISteamMatchmakingServers
{
private readonly IntPtr m_instancePtr;
public SteamMatchmakingServers(IntPtr c_instancePtr)
{
m_instancePtr = c_instancePtr;
}
private void CheckIfUsable()
{
if (m_instancePtr == IntPtr.Zero)
{
throw new InvalidOperationException("Steam MatchmakingServers Not Initialized!");
}
}
#region Native Methods
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestInternetServerList")]
private static extern uint SteamAPI_ISteamMatchmakingServers_RequestInternetServerList(IntPtr c_instancePtr, uint c_iApp, [In, Out] IntPtr[] c_ppchFilters, uint c_nFilters, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestLANServerList")]
private static extern uint SteamAPI_ISteamMatchmakingServers_RequestLANServerList(IntPtr c_instancePtr, uint c_iApp, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestFriendsServerList")]
private static extern uint SteamAPI_ISteamMatchmakingServers_RequestFriendsServerList(IntPtr c_instancePtr, uint c_iApp, [In, Out] IntPtr[] c_ppchFilters, uint c_nFilters, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestFavoritesServerList")]
private static extern uint SteamAPI_ISteamMatchmakingServers_RequestFavoritesServerList(IntPtr c_instancePtr, uint c_iApp, [In, Out] IntPtr[] c_ppchFilters, uint c_nFilters, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestHistoryServerList")]
private static extern uint SteamAPI_ISteamMatchmakingServers_RequestHistoryServerList(IntPtr c_instancePtr, uint c_iApp, [In, Out] IntPtr[] c_ppchFilters, uint c_nFilters, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RequestSpectatorServerList")]
private static extern uint SteamAPI_ISteamMatchmakingServers_RequestSpectatorServerList(IntPtr c_instancePtr, uint c_iApp, [In, Out] IntPtr[] c_ppchFilters, uint c_nFilters, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_ReleaseRequest")]
private static extern void SteamAPI_ISteamMatchmakingServers_ReleaseRequest(IntPtr c_instancePtr, uint c_hServerListRequest);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_GetServerDetails")]
private static extern IntPtr SteamAPI_ISteamMatchmakingServers_GetServerDetails(IntPtr c_instancePtr, uint c_hRequest, int c_iServer);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_CancelQuery")]
private static extern void SteamAPI_ISteamMatchmakingServers_CancelQuery(IntPtr c_instancePtr, uint c_hRequest);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RefreshQuery")]
private static extern void SteamAPI_ISteamMatchmakingServers_RefreshQuery(IntPtr c_instancePtr, uint c_hRequest);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_IsRefreshing")]
private static extern bool SteamAPI_ISteamMatchmakingServers_IsRefreshing(IntPtr c_instancePtr, uint c_hRequest);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_GetServerCount")]
private static extern int SteamAPI_ISteamMatchmakingServers_GetServerCount(IntPtr c_instancePtr, uint c_hRequest);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_RefreshServer")]
private static extern void SteamAPI_ISteamMatchmakingServers_RefreshServer(IntPtr c_instancePtr, uint c_hRequest, int c_iServer);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_PingServer")]
private static extern uint SteamAPI_ISteamMatchmakingServers_PingServer(IntPtr c_instancePtr, uint c_unIp, char c_usPort, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_PlayerDetails")]
private static extern uint SteamAPI_ISteamMatchmakingServers_PlayerDetails(IntPtr c_instancePtr, uint c_unIp, char c_usPort, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_ServerRules")]
private static extern uint SteamAPI_ISteamMatchmakingServers_ServerRules(IntPtr c_instancePtr, uint c_unIp, char c_usPort, IntPtr c_pRequestServersResponse);
[DllImport(SteamApi.STEAMWORKS_MODULE_NAME, EntryPoint = "SteamAPI_ISteamMatchmakingServers_CancelServerQuery")]
private static extern void SteamAPI_ISteamMatchmakingServers_CancelServerQuery(IntPtr c_instancePtr, uint c_hServerQuery);
#endregion
#region Overrides of ISteamMatchmakingServers
public override IntPtr GetIntPtr()
{
return m_instancePtr;
}
public override uint RequestInternetServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_RequestInternetServerList(m_instancePtr, c_iApp, c_ppchFilters, 0, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingServerListResponse(a_objPtr);
return a_result;
}
public override uint RequestLanServerList(uint c_iApp, ISteamMatchmakingServerListResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_RequestLANServerList(m_instancePtr, c_iApp, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingServerListResponse(a_objPtr);
return a_result;
}
public override uint RequestFriendsServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_RequestFriendsServerList(m_instancePtr, c_iApp, c_ppchFilters, 0, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingServerListResponse(a_objPtr);
return a_result;
}
public override uint RequestFavoritesServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_RequestFavoritesServerList(m_instancePtr, c_iApp, c_ppchFilters, 0, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingServerListResponse(a_objPtr);
return a_result;
}
public override uint RequestHistoryServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_RequestHistoryServerList(m_instancePtr, c_iApp, c_ppchFilters, 0, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingServerListResponse(a_objPtr);
return a_result;
}
public override uint RequestSpectatorServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_RequestSpectatorServerList(m_instancePtr, c_iApp, c_ppchFilters, 0, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingServerListResponse(a_objPtr);
return a_result;
}
public override void ReleaseRequest(uint c_hServerListRequest)
{
CheckIfUsable();
SteamAPI_ISteamMatchmakingServers_ReleaseRequest(m_instancePtr, c_hServerListRequest);
}
public override GameServerItem GetServerDetails(uint c_hRequest, int c_iServer)
{
CheckIfUsable();
var a_result = SteamAPI_ISteamMatchmakingServers_GetServerDetails(m_instancePtr, c_hRequest, c_iServer);
return Marshal.PtrToStructure<GameServerItem>(a_result);
}
public override void CancelQuery(uint c_hRequest)
{
CheckIfUsable();
SteamAPI_ISteamMatchmakingServers_CancelQuery(m_instancePtr, c_hRequest);
}
public override void RefreshQuery(uint c_hRequest)
{
CheckIfUsable();
SteamAPI_ISteamMatchmakingServers_RefreshQuery(m_instancePtr, c_hRequest);
}
public override bool IsRefreshing(uint c_hRequest)
{
CheckIfUsable();
var a_result = SteamAPI_ISteamMatchmakingServers_IsRefreshing(m_instancePtr, c_hRequest);
return a_result;
}
public override int GetServerCount(uint c_hRequest)
{
CheckIfUsable();
var a_result = SteamAPI_ISteamMatchmakingServers_GetServerCount(m_instancePtr, c_hRequest);
return a_result;
}
public override void RefreshServer(uint c_hRequest, int c_iServer)
{
CheckIfUsable();
SteamAPI_ISteamMatchmakingServers_RefreshServer(m_instancePtr, c_hRequest, c_iServer);
}
public override uint PingServer(uint c_unIp, char c_usPort, ISteamMatchmakingPingResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_PingServer(m_instancePtr, c_unIp, c_usPort, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingPingResponse(a_objPtr);
return a_result;
}
public override uint PlayerDetails(uint c_unIp, char c_usPort, ISteamMatchmakingPlayersResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_PlayerDetails(m_instancePtr, c_unIp, c_usPort, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingPlayersResponse(a_objPtr);
return a_result;
}
public override uint ServerRules(uint c_unIp, char c_usPort, ISteamMatchmakingRulesResponse c_pRequestServersResponse)
{
CheckIfUsable();
var a_objPtr = IntPtr.Zero;
var a_result = SteamAPI_ISteamMatchmakingServers_ServerRules(m_instancePtr, c_unIp, c_usPort, a_objPtr);
c_pRequestServersResponse = new SteamMatchmakingRulesResponse(a_objPtr);
return a_result;
}
public override void CancelServerQuery(uint c_hServerQuery)
{
CheckIfUsable();
SteamAPI_ISteamMatchmakingServers_CancelServerQuery(m_instancePtr, c_hServerQuery);
}
#endregion
}
public abstract class ISteamMatchmakingServers
{
public abstract IntPtr GetIntPtr();
public abstract uint RequestInternetServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse);
public abstract uint RequestLanServerList(uint c_iApp, ISteamMatchmakingServerListResponse c_pRequestServersResponse);
public abstract uint RequestFriendsServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse);
public abstract uint RequestFavoritesServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse);
public abstract uint RequestHistoryServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse);
public abstract uint RequestSpectatorServerList(uint c_iApp, IntPtr[] c_ppchFilters, ISteamMatchmakingServerListResponse c_pRequestServersResponse);
public abstract void ReleaseRequest(uint c_hServerListRequest);
public abstract GameServerItem GetServerDetails(uint c_hRequest, int c_iServer);
public abstract void CancelQuery(uint c_hRequest);
public abstract void RefreshQuery(uint c_hRequest);
public abstract bool IsRefreshing(uint c_hRequest);
public abstract int GetServerCount(uint c_hRequest);
public abstract void RefreshServer(uint c_hRequest, int c_iServer);
public abstract uint PingServer(uint c_unIp, char c_usPort, ISteamMatchmakingPingResponse c_pRequestServersResponse);
public abstract uint PlayerDetails(uint c_unIp, char c_usPort, ISteamMatchmakingPlayersResponse c_pRequestServersResponse);
public abstract uint ServerRules(uint c_unIp, char c_usPort, ISteamMatchmakingRulesResponse c_pRequestServersResponse);
public abstract void CancelServerQuery(uint c_hServerQuery);
}
[StructLayout(LayoutKind.Sequential)]
public struct GameServerItem
{
public ServerNetAdr NetAdr;
public int Ping;
[MarshalAs(UnmanagedType.I1)] public bool HadSuccessfulResponse;
[MarshalAs(UnmanagedType.I1)] public bool DoNotRefresh;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string GameDir; //char[32]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string Map; //char[32]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string GameDescription; //char[64]
public uint AppId;
public int Players;
public int MaxPlayers;
public int BotPlayers;
[MarshalAs(UnmanagedType.I1)] public bool Password;
[MarshalAs(UnmanagedType.I1)] public bool Secure;
public uint TimeLastPlayed;
public int ServerVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string ServerName; //char[64]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string GameTags; //char[128]
public ulong SteamId;
}
[StructLayout(LayoutKind.Sequential)]
public struct ServerNetAdr
{
public char ConnectionPort;
public char QueryPort;
public uint Ip;
}
}