mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 00:26: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.
68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using EchoHub.Core.Contracts;
|
|
using EchoHub.Core.DTOs;
|
|
|
|
namespace EchoHub.Server.Irc;
|
|
|
|
public class IrcBroadcaster(IrcGatewayService gateway) : IChatBroadcaster
|
|
{
|
|
public async Task SendMessageToChannelAsync(string channelName, MessageDto message)
|
|
{
|
|
var lines = IrcMessageFormatter.FormatMessage(message);
|
|
|
|
foreach (var conn in gateway.GetConnectionsInChannel(channelName))
|
|
{
|
|
// IRC convention: don't echo sender's own message
|
|
if (conn.Nickname == message.SenderUsername)
|
|
continue;
|
|
|
|
foreach (var line in lines)
|
|
await conn.SendAsync(line);
|
|
}
|
|
}
|
|
|
|
public async Task SendUserJoinedAsync(string channelName, string username, string? excludeConnectionId = null)
|
|
{
|
|
foreach (var conn in gateway.GetConnectionsInChannel(channelName))
|
|
{
|
|
if (conn.ConnectionId == excludeConnectionId) continue;
|
|
await conn.SendAsync($":{username}!{username}@echohub JOIN #{channelName}");
|
|
}
|
|
}
|
|
|
|
public async Task SendUserLeftAsync(string channelName, string username)
|
|
{
|
|
foreach (var conn in gateway.GetConnectionsInChannel(channelName))
|
|
{
|
|
if (conn.Nickname == username) continue;
|
|
await conn.SendAsync($":{username}!{username}@echohub PART #{channelName}");
|
|
}
|
|
}
|
|
|
|
public async Task SendChannelUpdatedAsync(ChannelDto channel, string? channelName = null)
|
|
{
|
|
var target = channelName ?? channel.Name;
|
|
if (channel.Topic is null) return;
|
|
|
|
foreach (var conn in gateway.GetConnectionsInChannel(target))
|
|
{
|
|
await conn.SendAsync($":{gateway.Options.ServerName} TOPIC #{channel.Name} :{channel.Topic}");
|
|
}
|
|
}
|
|
|
|
public Task SendUserStatusChangedAsync(List<string> channelNames, UserPresenceDto presence)
|
|
{
|
|
// IRC has no active status broadcast. Clients discover away via WHOIS/WHO.
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public async Task SendErrorAsync(string connectionId, string message)
|
|
{
|
|
if (!connectionId.StartsWith("irc-")) return;
|
|
|
|
if (gateway.Connections.TryGetValue(connectionId, out var conn))
|
|
{
|
|
await conn.SendAsync($":{gateway.Options.ServerName} NOTICE {conn.Nickname ?? "*"} :{message}");
|
|
}
|
|
}
|
|
}
|