예제 #1
0
파일: Server.cs 프로젝트: KallDrexx/SIS-cs
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        public void SendActivationMessages(IrcClient client)
        {
            var message = new WelcomeReply
            {
                SenderAddress = Server.HostName,
                SenderNickName = client.NickName
            }.FormFullResponseString();

            client.SendMessage(message);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
파일: Channel.cs 프로젝트: KallDrexx/SIS-cs
        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);
            }
        }
예제 #7
0
        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;
            }
        }
예제 #8
0
파일: Channel.cs 프로젝트: KallDrexx/SIS-cs
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
파일: Channel.cs 프로젝트: KallDrexx/SIS-cs
        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);
        }