private void ClientConnected(TcpClient client, int clientNumber) { var user = new IrcClient(client, clientNumber); user.IrcCommandReceived += _commandProcessor.ProcessCommand; user.IrcUserActivated += _controller.SendActivationMessages; _ircClients.Add(user); Console.WriteLine("Client {0} Connected", clientNumber); }
public void SendMessageToChannel(IrcClient sender, string channelName, string message) { var channel = _channels.FirstOrDefault(x => x.Name.Equals(channelName, StringComparison.InvariantCultureIgnoreCase)); if (channel == null) return; channel.BroadcastMessage(sender, message); }
public void SendActivationMessages(IrcClient client) { var message = new WelcomeReply { SenderAddress = Server.HostName, SenderNickName = client.NickName }.FormFullResponseString(); client.SendMessage(message); }
public void PartChannel(IrcClient client, string channelName) { var channel = _channels.FirstOrDefault(x => x.Name.Equals(channelName, StringComparison.InvariantCultureIgnoreCase)); if (channel == null) return; channel.PartClient(client); }
public void JoinChannel(IrcClient client, string channelName) { // If the channel doesn't exist yet, create it var channel = _channels.FirstOrDefault(x => x.Name.Equals(channelName, StringComparison.InvariantCultureIgnoreCase)); if (channel == null) { channel = new Channel(channelName); _channels.Add(channel); } channel.JoinClient(client); }
public void BroadcastMessage(IrcClient source, string message) { foreach (var ircClient in _clients) { if (ircClient == source) continue; new PrivateMessageAnnouncement { SenderMask = source.UserMask, Recipient = "#" + Name, Message = message }.SendMessageToClient(ircClient); } }
public void ProcessCommand(IrcClient client, string command) { var commandDetails = Parse(command); foreach (var pair in _availableCommands) { if (!pair.Key.Equals(commandDetails.Key, StringComparison.InvariantCultureIgnoreCase)) continue; if (!client.UserActivated && _commandProperties[pair.Value].RequiresActivatedUser) continue; pair.Value.ProcessCommand(commandDetails.Value, client, _controller); return; } }
public void JoinClient(IrcClient client) { if (_clients.Contains(client)) return; // already part of this channel _clients.Add(client); // Announce the join to all clients in the channel foreach (var channelClient in _clients) { new UserJoinedChannelAnnouncement { UserMask = client.UserMask, ChannelName = Name }.SendMessageToClient(channelClient); } // Send response messages new ChannelTopicReply { SenderAddress = Server.HostName, RecipientNickName = client.NickName, ChannelName = Name, Topic = Topic }.SendMessageToClient(client); var usersToList = _clients.Where(x => x != client) .Select(x => x.NickName) .ToArray(); new ChannelUserListReply { SenderAddress = Server.HostName, RecipientNickName = client.NickName, ChannelName = Name, Users = usersToList }.SendMessageToClient(client); new ChanneluserListEndReply() { SenderAddress = Server.HostName, ClientNick = client.NickName, ChannelName = Name }.SendMessageToClient(client); }
public void SendPrivateMessageToUser(IrcClient sender, string recipientNickName, string message) { // Find the client with the nickname var client = _clients.FirstOrDefault(x => x.NickName.Equals(recipientNickName)); if (client == null || !client.ConnectionActive) { var errorMessage = new NoSuchNickError { SenderAddress = Server.HostName, SenderNickName = sender.NickName, RecipientNickName = recipientNickName }.FormFullResponseString(); sender.SendMessage(errorMessage); return; } new PrivateMessageAnnouncement { SenderMask = sender.UserMask, Recipient = recipientNickName, Message = message }.SendMessageToClient(client); }
public void PartClient(IrcClient client) { if (!_clients.Contains(client)) return; // Relay the client parting to all clients foreach (var ircClient in _clients) { new UserPartedChannelAnnouncement { SenderMask = client.UserMask, ChannelName = Name }.SendMessageToClient(ircClient); } _clients.Remove(client); }