Skip to content

Commit 76ca746

Browse files
committed
Move IServerQuery into .Interfaces namepsace
1 parent f390692 commit 76ca746

File tree

5 files changed

+154
-134
lines changed

5 files changed

+154
-134
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
3232
* Removed `sealed` modifiers from all `SteamQueryNet.Models` namespace.
3333
34+
* `IServerQuery` moved into `SteamQueryNet.Interfaces` namespace.
35+
3436
### 4. Hard-deprecations
3537
3638
* `ServerQuery` constructor parameter `int port` now changed to `ushort` to remove all integer range checks since the UDP port is already literally an `ushort`.
3739
38-
* Removed port range tests.
40+
* Removed port range tests.
41+
42+
* `IServerQuery` moved into `SteamQueryNet.Interfaces` namespace.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using SteamQueryNet.Models;
2+
3+
using System.Collections.Generic;
4+
using System.Net;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamQueryNet.Interfaces
8+
{
9+
public interface IServerQuery
10+
{
11+
/// <summary>
12+
/// Renews the server challenge code of the ServerQuery instance in order to be able to execute further operations.
13+
/// </summary>
14+
/// <returns>The new created challenge.</returns>
15+
int RenewChallenge();
16+
17+
/// <summary>
18+
/// Renews the server challenge code of the ServerQuery instance in order to be able to execute further operations.
19+
/// </summary>
20+
/// <returns>The new created challenge.</returns>
21+
Task<int> RenewChallengeAsync();
22+
23+
/// <summary>
24+
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
25+
/// </summary>
26+
/// <param name="serverAddress">IPAddress or HostName of the server that queries will be sent.</param>
27+
/// <param name="port">Port of the server that queries will be sent.</param>
28+
/// <returns>Connected instance of ServerQuery.</returns>
29+
IServerQuery Connect(string serverAddress, ushort port);
30+
31+
/// <summary>
32+
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
33+
/// </summary>
34+
/// <param name="serverAddressAndPort">IPAddress or HostName of the server and port separated by a colon(:) or a comma(,).</param>
35+
/// <returns>Connected instance of ServerQuery.</returns>
36+
IServerQuery Connect(string serverAddressAndPort);
37+
38+
/// <summary>
39+
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
40+
/// </summary>
41+
/// <param name="customLocalIPEndpoint">Desired local IPEndpoint to bound.</param>
42+
/// <param name="serverAddressAndPort">IPAddress or HostName of the server and port separated by a colon(:) or a comma(,).</param>
43+
/// <returns>Connected instance of ServerQuery.</returns>
44+
IServerQuery Connect(IPEndPoint customLocalIPEndpoint, string serverAddressAndPort);
45+
46+
/// <summary>
47+
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
48+
/// </summary>
49+
/// <param name="customLocalIPEndpoint">Desired local IPEndpoint to bound.</param>
50+
/// <param name="serverAddress">IPAddress or HostName of the server that queries will be sent.</param>
51+
/// <param name="port">Port of the server that queries will be sent.</param>
52+
/// <returns>Connected instance of ServerQuery.</returns>
53+
IServerQuery Connect(IPEndPoint customLocalIPEndpoint, string serverAddress, ushort port);
54+
55+
/// <summary>
56+
/// Requests and serializes the server information.
57+
/// </summary>
58+
/// <returns>Serialized ServerInfo instance.</returns>
59+
ServerInfo GetServerInfo();
60+
61+
/// <summary>
62+
/// Requests and serializes the server information.
63+
/// </summary>
64+
/// <returns>Serialized ServerInfo instance.</returns>
65+
Task<ServerInfo> GetServerInfoAsync();
66+
67+
/// <summary>
68+
/// Requests and serializes the list of player information.
69+
/// </summary>
70+
/// <returns>Serialized list of Player instances.</returns>
71+
List<Player> GetPlayers();
72+
73+
/// <summary>
74+
/// Requests and serializes the list of player information.
75+
/// </summary>
76+
/// <returns>Serialized list of Player instances.</returns>
77+
Task<List<Player>> GetPlayersAsync();
78+
79+
/// <summary>
80+
/// Requests and serializes the list of rules defined by the server.
81+
/// Warning: CS:GO Rules reply is broken since update CSGO 1.32.3.0 (Feb 21, 2014).
82+
/// Before the update rules got truncated when exceeding MTU, after the update rules reply is not sent at all.
83+
/// </summary>
84+
/// <returns>Serialized list of Rule instances.</returns>
85+
List<Rule> GetRules();
86+
87+
/// <summary>
88+
/// Requests and serializes the list of rules defined by the server.
89+
/// Warning: CS:GO Rules reply is broken since update CSGO 1.32.3.0 (Feb 21, 2014).
90+
/// Before the update rules got truncated when exceeding MTU, after the update rules reply is not sent at all.
91+
/// </summary>
92+
/// <returns>Serialized list of Rule instances.</returns>
93+
Task<List<Rule>> GetRulesAsync();
94+
}
95+
}

SteamQueryNet/SteamQueryNet/Interfaces/IUdpClient.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,4 @@ public interface IUdpClient : IDisposable
1717

1818
Task<UdpReceiveResult> ReceiveAsync();
1919
}
20-
21-
internal sealed class UdpWrapper : IUdpClient
22-
{
23-
private readonly UdpClient _udpClient;
24-
25-
public UdpWrapper(IPEndPoint localIpEndPoint, int sendTimeout, int receiveTimeout)
26-
{
27-
_udpClient = new UdpClient(localIpEndPoint);
28-
_udpClient.Client.SendTimeout = sendTimeout;
29-
_udpClient.Client.ReceiveTimeout = receiveTimeout;
30-
}
31-
32-
public bool IsConnected
33-
{
34-
get
35-
{
36-
return this._udpClient.Client.Connected;
37-
}
38-
}
39-
40-
public void Close()
41-
{
42-
this._udpClient.Close();
43-
}
44-
45-
public void Connect(IPEndPoint remoteIpEndpoint)
46-
{
47-
this._udpClient.Connect(remoteIpEndpoint);
48-
}
49-
50-
public void Dispose()
51-
{
52-
this._udpClient.Dispose();
53-
}
54-
55-
public Task<UdpReceiveResult> ReceiveAsync()
56-
{
57-
return this._udpClient.ReceiveAsync();
58-
}
59-
60-
public Task<int> SendAsync(byte[] datagram, int bytes)
61-
{
62-
return this._udpClient.SendAsync(datagram, bytes);
63-
}
64-
}
6520
}

SteamQueryNet/SteamQueryNet/ServerQuery.cs

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using SteamQueryNet.Interfaces;
22
using SteamQueryNet.Models;
3+
using SteamQueryNet.Services;
34
using SteamQueryNet.Utils;
45

56
using System;
@@ -13,94 +14,6 @@
1314
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("SteamQueryNet.Tests")]
1415
namespace SteamQueryNet
1516
{
16-
// This is not really required but imma be a good guy and create this for them people that wants to mock the ServerQuery.
17-
public interface IServerQuery
18-
{
19-
/// <summary>
20-
/// Renews the server challenge code of the ServerQuery instance in order to be able to execute further operations.
21-
/// </summary>
22-
/// <returns>The new created challenge.</returns>
23-
int RenewChallenge();
24-
25-
/// <summary>
26-
/// Renews the server challenge code of the ServerQuery instance in order to be able to execute further operations.
27-
/// </summary>
28-
/// <returns>The new created challenge.</returns>
29-
Task<int> RenewChallengeAsync();
30-
31-
/// <summary>
32-
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
33-
/// </summary>
34-
/// <param name="serverAddress">IPAddress or HostName of the server that queries will be sent.</param>
35-
/// <param name="port">Port of the server that queries will be sent.</param>
36-
/// <returns>Connected instance of ServerQuery.</returns>
37-
IServerQuery Connect(string serverAddress, ushort port);
38-
39-
/// <summary>
40-
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
41-
/// </summary>
42-
/// <param name="serverAddressAndPort">IPAddress or HostName of the server and port separated by a colon(:) or a comma(,).</param>
43-
/// <returns>Connected instance of ServerQuery.</returns>
44-
IServerQuery Connect(string serverAddressAndPort);
45-
46-
/// <summary>
47-
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
48-
/// </summary>
49-
/// <param name="customLocalIPEndpoint">Desired local IPEndpoint to bound.</param>
50-
/// <param name="serverAddressAndPort">IPAddress or HostName of the server and port separated by a colon(:) or a comma(,).</param>
51-
/// <returns>Connected instance of ServerQuery.</returns>
52-
IServerQuery Connect(IPEndPoint customLocalIPEndpoint, string serverAddressAndPort);
53-
54-
/// <summary>
55-
/// Configures and Connects the created instance of SteamQuery UDP socket for Steam Server Query Operations.
56-
/// </summary>
57-
/// <param name="customLocalIPEndpoint">Desired local IPEndpoint to bound.</param>
58-
/// <param name="serverAddress">IPAddress or HostName of the server that queries will be sent.</param>
59-
/// <param name="port">Port of the server that queries will be sent.</param>
60-
/// <returns>Connected instance of ServerQuery.</returns>
61-
IServerQuery Connect(IPEndPoint customLocalIPEndpoint, string serverAddress, ushort port);
62-
63-
/// <summary>
64-
/// Requests and serializes the server information.
65-
/// </summary>
66-
/// <returns>Serialized ServerInfo instance.</returns>
67-
ServerInfo GetServerInfo();
68-
69-
/// <summary>
70-
/// Requests and serializes the server information.
71-
/// </summary>
72-
/// <returns>Serialized ServerInfo instance.</returns>
73-
Task<ServerInfo> GetServerInfoAsync();
74-
75-
/// <summary>
76-
/// Requests and serializes the list of player information.
77-
/// </summary>
78-
/// <returns>Serialized list of Player instances.</returns>
79-
List<Player> GetPlayers();
80-
81-
/// <summary>
82-
/// Requests and serializes the list of player information.
83-
/// </summary>
84-
/// <returns>Serialized list of Player instances.</returns>
85-
Task<List<Player>> GetPlayersAsync();
86-
87-
/// <summary>
88-
/// Requests and serializes the list of rules defined by the server.
89-
/// Warning: CS:GO Rules reply is broken since update CSGO 1.32.3.0 (Feb 21, 2014).
90-
/// Before the update rules got truncated when exceeding MTU, after the update rules reply is not sent at all.
91-
/// </summary>
92-
/// <returns>Serialized list of Rule instances.</returns>
93-
List<Rule> GetRules();
94-
95-
/// <summary>
96-
/// Requests and serializes the list of rules defined by the server.
97-
/// Warning: CS:GO Rules reply is broken since update CSGO 1.32.3.0 (Feb 21, 2014).
98-
/// Before the update rules got truncated when exceeding MTU, after the update rules reply is not sent at all.
99-
/// </summary>
100-
/// <returns>Serialized list of Rule instances.</returns>
101-
Task<List<Rule>> GetRulesAsync();
102-
}
103-
10417
public class ServerQuery : IServerQuery, IDisposable
10518
{
10619
private IPEndPoint _remoteIpEndpoint;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using SteamQueryNet.Interfaces;
2+
3+
using System.Net;
4+
using System.Net.Sockets;
5+
using System.Threading.Tasks;
6+
7+
namespace SteamQueryNet.Services
8+
{
9+
internal sealed class UdpWrapper : IUdpClient
10+
{
11+
private readonly UdpClient _udpClient;
12+
13+
public UdpWrapper(IPEndPoint localIpEndPoint, int sendTimeout, int receiveTimeout)
14+
{
15+
_udpClient = new UdpClient(localIpEndPoint);
16+
_udpClient.Client.SendTimeout = sendTimeout;
17+
_udpClient.Client.ReceiveTimeout = receiveTimeout;
18+
}
19+
20+
public bool IsConnected
21+
{
22+
get
23+
{
24+
return this._udpClient.Client.Connected;
25+
}
26+
}
27+
28+
public void Close()
29+
{
30+
this._udpClient.Close();
31+
}
32+
33+
public void Connect(IPEndPoint remoteIpEndpoint)
34+
{
35+
this._udpClient.Connect(remoteIpEndpoint);
36+
}
37+
38+
public void Dispose()
39+
{
40+
this._udpClient.Dispose();
41+
}
42+
43+
public Task<UdpReceiveResult> ReceiveAsync()
44+
{
45+
return this._udpClient.ReceiveAsync();
46+
}
47+
48+
public Task<int> SendAsync(byte[] datagram, int bytes)
49+
{
50+
return this._udpClient.SendAsync(datagram, bytes);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)