-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Steam Query, and Rcon as data providers
- Loading branch information
1 parent
588bfc9
commit b42f2b7
Showing
7 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ public enum DataProvider | |
SCUM, | ||
MINECRAFT, | ||
BATTLEMETRICS, | ||
RCONClient | ||
RCONClient, | ||
SteamQuery | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using DiscordPlayerCountBot.Services.SteamQuery; | ||
|
||
namespace PlayerCountBot.Providers | ||
{ | ||
[Name("Steam Query")] | ||
public class SteamQueryProvider : ServerInformationProvider | ||
{ | ||
public SteamQueryProvider(BotInformation info) : base(info) | ||
{ | ||
} | ||
|
||
public async override Task<BaseViewModel?> GetServerInformation(BotInformation information, Dictionary<string, string> applicationVariables) | ||
{ | ||
var service = new SteamQueryService(); | ||
|
||
try | ||
{ | ||
var addressAndPort = information.GetAddressAndPort(); | ||
var response = await service.GetQueryResponse(addressAndPort.Item1, addressAndPort.Item2); | ||
|
||
if (response == null) | ||
{ | ||
throw new ApplicationException($" Failed to get a Server Information response from Steam Query."); | ||
} | ||
|
||
HandleLastException(information); | ||
Check failure on line 26 in DiscordPlayerCountBot/Providers/SteamQueryProvider.cs GitHub Actions / dotnet_formatDiscordPlayerCountBot/Providers/SteamQueryProvider.cs#L26
|
||
|
||
return response; | ||
} | ||
catch (Exception e) | ||
{ | ||
HandleException(e); | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
DiscordPlayerCountBot/Services/SteamQuery/ISteamQueryService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using DiscordPlayerCountBot.Enums; | ||
|
||
namespace DiscordPlayerCountBot.Services.SteamQuery | ||
{ | ||
internal interface ISteamQueryService | ||
{ | ||
public Task<BaseViewModel> GetQueryResponse(string address, int port); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
DiscordPlayerCountBot/Services/SteamQuery/SteamQueryService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using SteamServerQuery; | ||
Check failure on line 1 in DiscordPlayerCountBot/Services/SteamQuery/SteamQueryService.cs GitHub Actions / test
|
||
|
||
namespace DiscordPlayerCountBot.Services.SteamQuery | ||
{ | ||
public class SteamQueryService : ISteamQueryService | ||
Check failure on line 5 in DiscordPlayerCountBot/Services/SteamQuery/SteamQueryService.cs GitHub Actions / test
|
||
{ | ||
public async Task<BaseViewModel> GetQueryResponse(string address, int port, string authorizationToken) | ||
{ | ||
var model = new BaseViewModel() | ||
{ | ||
Address = address, | ||
Port = port | ||
}; | ||
|
||
try | ||
{ | ||
var serverInformation = await SteamServer.QueryServerAsync(address, port = 0); | ||
model.MaxPlayers = serverInformation.MaxPlayers; | ||
model.Players = serverInformation.Players; | ||
model.QueuedPlayers = 0; | ||
}catch | ||
Check failure on line 21 in DiscordPlayerCountBot/Services/SteamQuery/SteamQueryService.cs GitHub Actions / dotnet_formatDiscordPlayerCountBot/Services/SteamQuery/SteamQueryService.cs#L21
|
||
{ | ||
throw; | ||
} | ||
|
||
return model; | ||
} | ||
} | ||
} |