Skip to content

Commit

Permalink
Update Protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 26, 2024
1 parent 81b2700 commit 1a20b60
Show file tree
Hide file tree
Showing 30 changed files with 96 additions and 87 deletions.
20 changes: 15 additions & 5 deletions OpenGSQ/Protocols/EOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class EOS : ProtocolBase
/// </summary>
/// <param name="host">The host name of the server.</param>
/// <param name="port">The port number of the server.</param>
/// <param name="timeout">The timeout value for the connection, in milliseconds. Default is 5000.</param>
/// <param name="deploymentId">The deployment ID for the application.</param>
/// <param name="accessToken">The access token for the application.</param>
/// <param name="timeout">The timeout value for the connection, in milliseconds. Default is 5000.</param>
/// <exception cref="ArgumentException">Thrown when either deploymentId or accessToken is null.</exception>
public EOS(string host, int port, int timeout = 5000, string deploymentId = null, string accessToken = null) : base(host, port, timeout)
public EOS(string host, int port, string deploymentId,string accessToken, int timeout = 5000) : base(host, port, timeout)
{
if (deploymentId == null || accessToken == null)
{
Expand Down Expand Up @@ -82,7 +82,12 @@ public static async Task<string> GetAccessTokenAsync(string clientId, string cli

var data = await response.Content.ReadFromJsonAsync<Dictionary<string, object>>();

return data["access_token"].ToString();
if (data == null || !data.TryGetValue("access_token", out var accessToken))
{
throw new Exception($"Failed to get access token from {url}");
}

return accessToken.ToString()!;
}
}

Expand Down Expand Up @@ -126,7 +131,12 @@ public static async Task<string> GetExternalAuthTokenAsync(string clientId, stri

var data = await response.Content.ReadFromJsonAsync<Dictionary<string, object>>();

return data["access_token"].ToString();
if (data == null || !data.TryGetValue("access_token", out var accessToken))
{
throw new Exception($"Failed to get access token from {url}");
}

return accessToken.ToString()!;
}
}

Expand Down Expand Up @@ -171,7 +181,7 @@ public static async Task<Matchmaking> GetMatchmakingAsync(string deploymentId, s

var responseData = await response.Content.ReadFromJsonAsync<Matchmaking>();

return responseData;
return responseData ?? throw new Exception($"Failed to load data from {url}"); ;
}
}

Expand Down
2 changes: 1 addition & 1 deletion OpenGSQ/Protocols/FiveM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private async Task<T> GetAsync<T>(string filename)
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<T>();
return await response.Content.ReadFromJsonAsync<T>() ?? throw new Exception($"Failed to load data from {url}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion OpenGSQ/Protocols/Scum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Scum(string host, int port, int timeout = 5000) : base(host, port, timeou
/// <returns>The status of the server.</returns>
/// <exception cref="TimeoutException">Thrown when the operation times out.</exception>
/// <exception cref="ServerNotFoundException">Thrown when the server is not found in the list of master servers.</exception>
public async Task<Status> GetStatus(List<Status> masterServers = null)
public async Task<Status> GetStatus(List<Status>? masterServers = null)
{
var ip = await GetIPAddress();

Expand Down
2 changes: 1 addition & 1 deletion OpenGSQ/RconProtocols/SourceRcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace OpenGSQ.RconProtocols
/// </summary>
public class SourceRcon : ProtocolBase, IDisposable
{
private System.Net.Sockets.TcpClient _tcpClient;
private System.Net.Sockets.TcpClient? _tcpClient;

/// <inheritdoc/>
public override string FullName => "Source RCON Protocol";
Expand Down
6 changes: 3 additions & 3 deletions OpenGSQ/Responses/ASE/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ public class Player
/// <summary>
/// Gets or sets the name of the player.
/// </summary>
public string Name { get; set; }
public string Name { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the team of the player.
/// </summary>
public string Team { get; set; }
public string Team { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the skin of the player.
/// </summary>
public string Skin { get; set; }
public string Skin { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the score of the player.
Expand Down
14 changes: 7 additions & 7 deletions OpenGSQ/Responses/ASE/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Status
/// <summary>
/// Gets or sets the name of the game.
/// </summary>
public string GameName { get; set; }
public string GameName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the port of the game.
Expand All @@ -20,22 +20,22 @@ public class Status
/// <summary>
/// Gets or sets the host name of the game.
/// </summary>
public string Hostname { get; set; }
public string Hostname { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the type of the game.
/// </summary>
public string GameType { get; set; }
public string GameType { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the map of the game.
/// </summary>
public string Map { get; set; }
public string Map { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the version of the game.
/// </summary>
public string Version { get; set; }
public string Version { get; set; } = string.Empty;

/// <summary>
/// Gets or sets a value indicating whether a password is required.
Expand All @@ -55,11 +55,11 @@ public class Status
/// <summary>
/// Gets or sets the rules of the game.
/// </summary>
public Dictionary<string, string> Rules { get; set; }
public Dictionary<string, string> Rules { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Gets or sets the players in the game.
/// </summary>
public List<Player> Players { get; set; }
public List<Player> Players { get; set; } = new List<Player>();
}
}
24 changes: 12 additions & 12 deletions OpenGSQ/Responses/Battlefield/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Info
/// <summary>
/// Gets or sets the hostname of the game server.
/// </summary>
public string Hostname { get; set; }
public string Hostname { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the number of players in the game.
Expand All @@ -25,12 +25,12 @@ public class Info
/// <summary>
/// Gets or sets the type of the game.
/// </summary>
public string GameType { get; set; }
public string GameType { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the current map of the game.
/// </summary>
public string Map { get; set; }
public string Map { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the number of rounds played.
Expand All @@ -45,7 +45,7 @@ public class Info
/// <summary>
/// Gets or sets the list of teams.
/// </summary>
public List<float> Teams { get; set; }
public List<float> Teams { get; set; } = new List<float>();

/// <summary>
/// Gets or sets the target score.
Expand All @@ -55,7 +55,7 @@ public class Info
/// <summary>
/// Gets or sets the status of the game.
/// </summary>
public string Status { get; set; }
public string Status { get; set; } = string.Empty;

/// <summary>
/// Gets or sets a value indicating whether the game is ranked.
Expand Down Expand Up @@ -87,17 +87,17 @@ public class Info
/// <summary>
/// Gets or sets the game mod. This property is optional.
/// </summary>
public string Mod { get; set; }
public string Mod { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the IP port of the game server. This property is optional.
/// </summary>
public string IpPort { get; set; }
public string IpPort { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the version of PunkBuster. This property is optional.
/// </summary>
public string PunkBusterVersion { get; set; }
public string? PunkBusterVersion { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the join queue is enabled. This property is optional.
Expand All @@ -107,17 +107,17 @@ public class Info
/// <summary>
/// Gets or sets the region of the game server. This property is optional.
/// </summary>
public string Region { get; set; }
public string? Region { get; set; }

/// <summary>
/// Gets or sets the ping site of the game server. This property is optional.
/// </summary>
public string PingSite { get; set; }
public string? PingSite { get; set; }

/// <summary>
/// Gets or sets the country of the game server. This property is optional.
/// </summary>
public string Country { get; set; }
public string? Country { get; set; }

/// <summary>
/// Gets or sets the number of players in the Blaze game state. This property is optional.
Expand All @@ -127,7 +127,7 @@ public class Info
/// <summary>
/// Gets or sets the Blaze game state. This property is optional.
/// </summary>
public string BlazeGameState { get; set; }
public string? BlazeGameState { get; set; }

/// <summary>
/// Gets or sets a value indicating whether quick match is enabled. This property is optional.
Expand Down
4 changes: 2 additions & 2 deletions OpenGSQ/Responses/Battlefield/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public class VersionInfo
/// <summary>
/// Gets or sets the mod of the game.
/// </summary>
public string Mod { get; set; }
public string Mod { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the version of the mod.
/// </summary>
public string Version { get; set; }
public string Version { get; set; } = string.Empty;
}
}
2 changes: 1 addition & 1 deletion OpenGSQ/Responses/EOS/Matchmaking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Matchmaking
/// Gets or sets the list of sessions returned by the matchmaking request.
/// Each session is represented as a dictionary of string keys and object values.
/// </summary>
public List<Dictionary<string, object>> Sessions { get; set; }
public List<Dictionary<string, object>> Sessions { get; set; } = new List<Dictionary<string, object>>();

/// <summary>
/// Gets or sets the count of sessions returned by the matchmaking request.
Expand Down
6 changes: 3 additions & 3 deletions OpenGSQ/Responses/GameSpy1/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class Status
/// Server's Info
/// <para>If <see cref="IsXServerQuery"/> is <see langword="true"/>, then it includes \info\xserverquery\rules\xserverquery, else \basic\\info\\rules\\</para>
/// </summary>
public Dictionary<string, string> Info { get; set; }
public Dictionary<string, string> Info { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Server's Players
/// </summary>
public List<Dictionary<string, string>> Players { get; set; }
public List<Dictionary<string, string>> Players { get; set; } = new List<Dictionary<string, string>>();

/// <summary>
/// Server's Teams (Only when <see cref="IsXServerQuery"/> is <see langword="true"/>)
/// </summary>
public List<Dictionary<string, string>> Teams { get; set; }
public List<Dictionary<string, string>> Teams { get; set; } = new List<Dictionary<string, string>>();
}
}
6 changes: 3 additions & 3 deletions OpenGSQ/Responses/GameSpy2/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public class Status
/// <summary>
/// Gets or sets the server information.
/// </summary>
public Dictionary<string, string> Info { get; set; }
public Dictionary<string, string> Info { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Gets or sets the list of players.
/// </summary>
public List<Dictionary<string, string>> Players { get; set; }
public List<Dictionary<string, string>> Players { get; set; } = new List<Dictionary<string, string>>();

/// <summary>
/// Gets or sets the list of teams.
/// </summary>
public List<Dictionary<string, string>> Teams { get; set; }
public List<Dictionary<string, string>> Teams { get; set; } = new List<Dictionary<string, string>>();
}
}
6 changes: 3 additions & 3 deletions OpenGSQ/Responses/Minecraft/StatusPre17.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ public class StatusPre17
/// <summary>
/// Gets or sets the protocol of the game.
/// </summary>
public string Protocol { get; set; }
public string Protocol { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the version of the game.
/// </summary>
public string Version { get; set; }
public string Version { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the message of the day.
/// </summary>
public string Motd { get; set; }
public string Motd { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the number of players in the game.
Expand Down
4 changes: 2 additions & 2 deletions OpenGSQ/Responses/Quake1/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public class Player
/// <summary>
/// Gets or sets the player's name.
/// </summary>
public string Name { get; set; }
public string Name { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the player's skin.
/// </summary>
public string Skin { get; set; }
public string Skin { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the player's first color.
Expand Down
4 changes: 2 additions & 2 deletions OpenGSQ/Responses/Quake1/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class Status
/// <summary>
/// Gets or sets the server information.
/// </summary>
public Dictionary<string, string> Info { get; set; }
public Dictionary<string, string> Info { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Gets or sets the list of players.
/// </summary>
public List<Player> Players { get; set; }
public List<Player> Players { get; set; } = new List<Player>();
}
}
4 changes: 2 additions & 2 deletions OpenGSQ/Responses/Quake2/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class Player
/// <summary>
/// Gets or sets the player's name.
/// </summary>
public string Name { get; set; }
public string? Name { get; set; }

/// <summary>
/// Gets or sets the player's address.
/// </summary>
public string Address { get; set; }
public string? Address { get; set; }
}
}
4 changes: 2 additions & 2 deletions OpenGSQ/Responses/Quake2/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class Status
/// <summary>
/// Gets or sets the server information.
/// </summary>
public Dictionary<string, string> Info { get; set; }
public Dictionary<string, string> Info { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Gets or sets the list of players.
/// </summary>
public List<Player> Players { get; set; }
public List<Player> Players { get; set; } = new List<Player>();
}
}
Loading

0 comments on commit 1a20b60

Please sign in to comment.