-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3abdfbc
commit 24ca65e
Showing
72 changed files
with
3,047 additions
and
1,732 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
using System; | ||
|
||
namespace OpenGSQ.Exceptions | ||
{ | ||
/// <summary> | ||
/// Represents errors that occur during application execution. | ||
/// </summary> | ||
public class AuthenticationException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AuthenticationException"/> class with a specified error message. | ||
/// </summary> | ||
/// <param name="message">The error message that explains the reason for the exception.</param> | ||
public AuthenticationException(string message) : base(message) | ||
{ | ||
} | ||
} | ||
} |
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,63 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace OpenGSQ.Exceptions | ||
{ | ||
/// <summary> | ||
/// Represents errors that occur during application execution when a packet is invalid. | ||
/// </summary> | ||
public class InvalidPacketException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InvalidPacketException"/> class with a specified error message. | ||
/// </summary> | ||
/// <param name="message">The message that describes the error.</param> | ||
public InvalidPacketException(string message) : base(message) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Checks if the received value is equal to the expected value. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the values to compare.</typeparam> | ||
/// <param name="received">The received value.</param> | ||
/// <param name="expected">The expected value.</param> | ||
/// <exception cref="InvalidPacketException"> | ||
/// Thrown when the received value does not match the expected value. | ||
/// </exception> | ||
public static void ThrowIfNotEqual<T>(T received, T expected) | ||
{ | ||
if (typeof(T) == typeof(byte[])) | ||
{ | ||
if (!(received as byte[]).SequenceEqual(expected as byte[])) | ||
{ | ||
throw new InvalidPacketException(GetMessage(received, expected)); | ||
} | ||
} | ||
else if (!received.Equals(expected)) | ||
{ | ||
throw new InvalidPacketException(GetMessage(received, expected)); | ||
} | ||
} | ||
|
||
private static string GetMessage<T>(T received, T expected) | ||
{ | ||
string receivedStr; | ||
string expectedStr; | ||
|
||
if (typeof(T) == typeof(byte[])) | ||
{ | ||
receivedStr = BitConverter.ToString(received as byte[]); | ||
expectedStr = BitConverter.ToString(expected as byte[]); | ||
} | ||
else | ||
{ | ||
receivedStr = received.ToString(); | ||
expectedStr = expected.ToString(); | ||
} | ||
|
||
return $"Packet header mismatch. Received: {receivedStr}. Expected: {expectedStr}."; | ||
} | ||
} | ||
} |
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,19 @@ | ||
using System; | ||
|
||
namespace OpenGSQ.Exceptions | ||
{ | ||
/// <summary> | ||
/// Represents errors that occur during application execution when a server is not found. | ||
/// </summary> | ||
public class ServerNotFoundException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ServerNotFoundException"/> class with a specified error message. | ||
/// </summary> | ||
/// <param name="message">The message that describes the error.</param> | ||
public ServerNotFoundException(string message) : base(message) | ||
{ | ||
|
||
} | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
|
||
namespace OpenGSQ.Exceptions | ||
{ | ||
/// <summary> | ||
/// Represents errors that occur during application execution related to timeouts. | ||
/// </summary> | ||
public class TimeoutException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TimeoutException"/> class with a specified error message. | ||
/// </summary> | ||
/// <param name="message">The message that describes the error.</param> | ||
public TimeoutException(string message) : base(message) | ||
{ | ||
} | ||
} | ||
} |
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
Oops, something went wrong.