mirror of
https://github.com/Stone-Red-Code/EchoHub.git
synced 2026-09-04 09:06:07 +02:00
- Add IrcGatewayService to handle IRC connections and commands. - Create IrcMessage class for parsing IRC protocol lines. - Implement IrcMessageFormatter for formatting messages as IRC lines. - Define IrcNumericReply constants for IRC numeric replies. - Add IrcOptions class for configuration settings related to IRC. - Create IrcServiceExtensions for adding IRC services to the application. - Refactor ChannelsController to use IChatService for broadcasting messages and channel updates. - Update ChatHub to utilize IChatService for user connection and message handling. - Introduce ChatService to manage chat-related operations and interactions. - Implement SignalRBroadcaster for broadcasting messages to SignalR clients. - Update PresenceTracker to retrieve usernames for connections. - Modify appsettings.example.json to include IRC configuration options. - Update solution file to include the new IRC project.
70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
namespace EchoHub.Server.Irc;
|
|
|
|
/// <summary>
|
|
/// Parsed representation of an IRC protocol line.
|
|
/// Format: [:prefix] COMMAND [params...] [:trailing]
|
|
/// </summary>
|
|
public sealed class IrcMessage
|
|
{
|
|
public string? Prefix { get; init; }
|
|
public string Command { get; init; } = "";
|
|
public List<string> Parameters { get; init; } = [];
|
|
|
|
public string? Trailing => Parameters.Count > 0 ? Parameters[^1] : null;
|
|
|
|
/// <summary>
|
|
/// Parse a raw IRC line: [:prefix SPACE] command [SPACE params] CRLF
|
|
/// </summary>
|
|
public static IrcMessage Parse(string line)
|
|
{
|
|
var span = line.AsSpan().TrimEnd("\r\n");
|
|
string? prefix = null;
|
|
var pos = 0;
|
|
|
|
// Parse optional prefix
|
|
if (span.Length > 0 && span[0] == ':')
|
|
{
|
|
var spaceIdx = span.IndexOf(' ');
|
|
if (spaceIdx == -1)
|
|
return new IrcMessage { Prefix = span[1..].ToString() };
|
|
|
|
prefix = span[1..spaceIdx].ToString();
|
|
pos = spaceIdx + 1;
|
|
}
|
|
|
|
// Skip whitespace
|
|
while (pos < span.Length && span[pos] == ' ') pos++;
|
|
|
|
// Parse command
|
|
var cmdStart = pos;
|
|
while (pos < span.Length && span[pos] != ' ') pos++;
|
|
var command = span[cmdStart..pos].ToString();
|
|
|
|
// Parse parameters
|
|
var parameters = new List<string>();
|
|
while (pos < span.Length)
|
|
{
|
|
while (pos < span.Length && span[pos] == ' ') pos++;
|
|
if (pos >= span.Length) break;
|
|
|
|
if (span[pos] == ':')
|
|
{
|
|
// Trailing parameter (rest of line)
|
|
parameters.Add(span[(pos + 1)..].ToString());
|
|
break;
|
|
}
|
|
|
|
var paramStart = pos;
|
|
while (pos < span.Length && span[pos] != ' ') pos++;
|
|
parameters.Add(span[paramStart..pos].ToString());
|
|
}
|
|
|
|
return new IrcMessage
|
|
{
|
|
Prefix = prefix,
|
|
Command = command,
|
|
Parameters = parameters,
|
|
};
|
|
}
|
|
}
|