Beispiel #1
0
        public void Reply(IReceiveMessage message, IMessageTarget sender, ReplyForm replyForm, object result)
        {
            IMessageTarget target = ReplyTarget(message);
            ISendMessage sendMessage = ReplyMessage(message.Connection.MessageSender, target, replyForm, result);

            if(replyForm != ReplyForm.More)
            {
                String[] messages = SplitMessage(sendMessage).ToArray();
                if(messages.Length > _data.ReplyMores)
                {
                    _moreMessages.Remove(sender);
                    _moreMessages.Add(sender, new Queue<String>(messages.Skip(_data.ReplyMores)));
                    _lastMore = sender;
                }

                message.Connection.SendAndForget(messages
                    .Take(_data.ReplyMores)
                    .Select(s => SendMessage(sendMessage, s, sender, replyForm))
                );
            }
            else
            {
                message.Connection.SendAndForget(SendMessage(sendMessage, sendMessage.Contents, sender,
                    _bot.DefaultReplyForm));
            }
        }
        public Boolean Register(IMessageTarget target)
        {
            String id = target.Id;

            if (String.IsNullOrWhiteSpace(id))
            {
                return(false);
            }
            lock (_regedit)
            {
                if (_regedit.ContainsKey(id))
                {
                    throw new InvalidOperationException($"The id {id} has been Existed");
                }
                _regedit.Add(id, target);
            }
            AddinProxy proxy = target as AddinProxy;

            if (proxy != null)
            {
                proxy.MessageService      = this;
                proxy.Owner.DomainUnload += OnDomainUnload;
            }
            target.MessageDispatcher?.Start();
#if DEBUG
            Console.WriteLine($"Register target.{target.Id}");
#endif
            return(true);
        }
        public void Unregister(String id)
        {
            if (String.IsNullOrWhiteSpace(id))
            {
                return;
            }
            IMessageTarget target = null;

            lock (_regedit)
            {
                if (!_regedit.ContainsKey(id))
                {
                    return;
                }
                target = _regedit[id];
                _regedit.Remove(id);
            }
            target.MessageDispatcher?.Stop();
            AddinProxy proxy = target as AddinProxy;

            if (proxy != null)
            {
                proxy.MessageService = null;
            }
#if DEBUG
            Console.WriteLine($"Unregister target.{target.Id}");
#endif
        }
Beispiel #4
0
        // IMessageTarget
        public object SendMessage(LogoContext context, string message, ICollection arguments)
        {
            message = message.ToLower();
            IMessageTarget target = (IMessageTarget)messages[message];

            if (target == null)
            {
                foreach (IMessageStore store in List)
                {
                    IMessageTarget store_target = store as IMessageTarget;
                    if (store_target != null && store.SupportsMessage(message))
                    {
                        target            = store_target;
                        messages[message] = target;
                        break;
                    }
                }
            }

            if (target == null)
            {
                throw new MessageNotSupportedException(message);
            }

            return(target.SendMessage(context, message, arguments));
        }
 public UserItemView(IMessageTarget user)
 {
     User    = user;
     Content = user.Name;
     Icon    = LazuriteUI.Icons.Icon.User;
     Margin  = new System.Windows.Thickness(0, 1, 0, 0);
 }
        private IReceiveMessage ParseDirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line)
        {
            Match results = regex.Match(line);

            if (results.Success && results.Groups[1].Success)
            {
                String         receiverName = results.Groups[1].Value;
                IMessageTarget receiver     = ParseReceiver(receiverName);
                String         message      = String.Empty;
                if (results.Groups[2].Success)
                {
                    message = results.Groups[2].Value;
                }

                IMessageTarget realSender = sender;
                if (sender.Type == MessageTargetType.User && receiver.Type == MessageTargetType.Channel)
                {
                    IChannel channel = receiver as IChannel;
                    realSender = channel.GetUser(sender.Name);
                }
                return(Client.CreateReceiveMessage(Connection, message, DateTime.Now, realSender, receiver, type,
                                                   ReplyType.Unknown));
            }
            return(null);
        }
Beispiel #7
0
        public ISendMessage Mode(IMessageTarget target, String[] newModes, String[] newModeParameters)
        {
            if(newModes == null)
            {
                throw new ArgumentNullException("newModes");
            }
            if(newModeParameters == null)
            {
                throw new ArgumentNullException("newModeParameters");
            }
            if(newModes.Length != newModeParameters.Length)
            {
                throw new ArgumentException("newModes and newModeParameters must have the same size.");
            }

            StringBuilder newMode = new StringBuilder(newModes.Length);
            StringBuilder newModeParameter = new StringBuilder();
            // as per RFC 3.2.3, maximum is 3 modes changes at once
            int maxModeChanges = 3;
            if(newModes.Length > maxModeChanges)
            {
                throw new ArgumentOutOfRangeException(
                    "newModes.Length",
                    newModes.Length,
                    String.Format("Mode change list is too large (> {0}).", maxModeChanges)
                );
            }

            for(int i = 0; i <= newModes.Length; i += maxModeChanges)
            {
                for(int j = 0; j < maxModeChanges; j++)
                {
                    if(i + j >= newModes.Length)
                    {
                        break;
                    }
                    newMode.Append(newModes[i + j]);
                }

                for(int j = 0; j < maxModeChanges; j++)
                {
                    if(i + j >= newModeParameters.Length)
                    {
                        break;
                    }
                    newModeParameter.Append(newModeParameters[i + j]);
                    newModeParameter.Append(" ");
                }
            }
            if(newModeParameter.Length > 0)
            {
                // remove trailing space
                newModeParameter.Length--;
                newMode.Append(" ");
                newMode.Append(newModeParameter.ToString());
            }

            return Mode(target, newMode.ToString());
        }
        public IReceiveMessage Receive(String raw)
        {
            if (raw == null)
            {
                throw new ArgumentNullException("raw");
            }
            if (String.IsNullOrWhiteSpace(raw))
            {
                throw new ArgumentException("Not an IRC line", "raw");
            }

            // Remove first :
            String line = null;

            if (raw[0] == ':')
            {
                line = raw.Substring(1);
            }
            else
            {
                line = raw;
            }

            // Try to parse messages without prefixes.
            IReceiveMessage message = ParseNoPrefixMessage(line);

            if (message != null)
            {
                return(message);
            }

            // Tokenize
            String[] tokens     = line.Split(new [] { ' ' }, 3);
            String   prefix     = tokens[0];
            String   command    = tokens[1];
            String   parameters = String.Empty;

            if (tokens.Length == 3)
            {
                parameters = tokens[2];
            }

            // Parse sender
            IMessageTarget sender = ParseSender(prefix);

            // Parse message type
            Tuple <ReceiveType, ReplyType> type = ParseMessageType(command);

            // Parse message
            if (type.Item1 != ReceiveType.Unknown)
            {
                return(ParseInformationMessage(sender, type.Item1, type.Item2, parameters));
            }
            else
            {
                return(ParseMessage(sender, line.Substring(prefix.Length + 1)));
            }
        }
 /// <summary>
 /// 初始化类型 Tumbler.Addin.Core.MessageDispathcer 实例。
 /// </summary>
 /// <param name="target">实现了 IMessageTarget 接口的类型实例。</param>
 public MessageDispatcher(IMessageTarget target)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     _target    = target;
     _queue     = new Queue <Message>(MaxCount);
     _syncEvent = new ManualResetEventSlim(false);
 }
Beispiel #10
0
        public String More(IMessageTarget sender)
        {
            if(!_moreMessages.ContainsKey(sender))
                throw new InvalidOperationException("No more messages in the buffer.");
            Queue<String> moreMessages = _moreMessages[sender];
            if(moreMessages.Count == 0)
                throw new InvalidOperationException("No more messages in the buffer.");

            return moreMessages.Dequeue();
        }
Beispiel #11
0
 protected NetworkEvent CreateEvent(byte code, object data, IMessageTarget target)
 {
     return(new NetworkEvent
     {
         SenderId = LocalClientRef.ClientId,
         Code = code,
         Data = data,
         Target = target
     });
 }
 public ReceiveMessage(IClientConnection connection, String contents, DateTime date, IMessageTarget sender,
                       IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     Connection = connection;
     Contents   = contents;
     Date       = date;
     Sender     = sender;
     Receiver   = receiver;
     Type       = type;
     ReplyType  = replyType;
 }
Beispiel #13
0
 public ReceiveMessage(IClientConnection connection, String contents, DateTime date, IMessageTarget sender, 
     IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     Connection = connection;
     Contents = contents;
     Date = date;
     Sender = sender;
     Receiver = receiver;
     Type = type;
     ReplyType = replyType;
 }
Beispiel #14
0
        public int RegisterTarget(IMessageTarget target, int groupId)
        {
            // Add the new target

            var context = new TargetContext();

            context.Target  = target;
            context.GroupId = groupId;

            this.Targets.Add(context);

            return(this.NumTargets - 1);
        }
Beispiel #15
0
        public override async Task SendMessage(IMessageTarget target, Message message)
        {
            if (message.Count == 0)
            {
                return;
            }
            long id;

            switch (target)
            {
            case GroupTarget g:
                id = g.id;
                break;

            case UserTarget u:
                id = u.id;
                break;

            default:
                return;
            }
            foreach (var sub in message)
            {
                switch (sub)
                {
                case TextSub textSub:
                    await PostJson("sendMessage", new JsonData {
                        ["chat_id"]    = id,
                        ["text"]       = textSub.text,
                        ["parse_mode"] = "Markdown"
                    });

                    break;

                case LocalImageSub localImageSub:
                    var photoContent = new MultipartFormDataContent();
                    photoContent.Add(new StringContent(id.ToString()), "chat_id");
                    photoContent.Add(new ByteArrayContent(
                                         await File.ReadAllBytesAsync(Path.Join("./Resources/images", localImageSub.resourcePath))
                                         ), "photo", Path.GetFileName(localImageSub.resourcePath));
                    await PostMPF("sendPhoto", photoContent);

                    /*await PostJson("sendPhoto", new JsonData {
                     *  ["chat_id"] = id,
                     *  ["photo"] = new Uri(new Uri(new Uri(_botServiceUrl), "images"), localImageSub.resourcePath).ToString()
                     * });*/
                    break;
                }
            }
        }
        private IReceiveMessage ParseInviteMessage(IMessageTarget sender, String line)
        {
            Match results = InviteRegex.Match(line);

            if (results.Success && results.Groups[1].Success && results.Groups[2].Success)
            {
                String   userName    = results.Groups[1].Value;
                String   channelName = results.Groups[2].Value;
                IChannel channel     = Connection.GetChannel(channelName);

                return(Client.CreateReceiveMessage(Connection, userName, DateTime.Now, sender, channel,
                                                   ReceiveType.Invite, ReplyType.Unknown));
            }
            return(null);
        }
Beispiel #17
0
        protected int[] ResolveClientIds(IMessageTarget target)
        {
            if (target is IClientIdResolvable)
            {
                var resolvable = (IClientIdResolvable)target;
                OneClientIdList[0] = resolvable.ClientId;
                return(OneClientIdList);
            }
            if (target is IClientIdListResolvable)
            {
                var resolvable = (IClientIdListResolvable)target;
                return(resolvable.GetClientIds());
            }

            return(EmptyClientIdList);
        }
Beispiel #18
0
        public override async Task SendMessage(IMessageTarget target, Message message)
        {
            if (message.Count == 0)
            {
                return;
            }
            JsonData msgChain = new JsonData();

            foreach (var sub in message)
            {
                switch (sub)
                {
                case LocalImageSub localImageSub:
                    msgChain.Add(new JsonData {
                        ["type"] = "Image",
                        ["path"] = localImageSub.resourcePath
                    });
                    break;

                case TextSub textSub:
                    msgChain.Add(new JsonData {
                        ["type"] = "Plain",
                        ["text"] = textSub.text
                    });
                    break;

                case AtSub atSub:
                    msgChain.Add(new JsonData {
                        ["type"]   = "At",
                        ["target"] = atSub.target
                    });
                    break;
                }
            }
            switch (target)
            {
            case GroupTarget groupTarget:
                await PostJson("/sendGroupMessage", new JsonData {
                    ["sessionKey"]   = sessionKey,
                    ["target"]       = groupTarget.id,
                    ["messageChain"] = msgChain
                });

                break;
            }
        }
Beispiel #19
0
        private void SendRpc(string name, IMessageTarget target, bool reliable, object[] parameters)
        {
            if (!_rpcMethodLookup.ContainsKey(name))
            {
                throw new InvalidOperationException($"No RPC method with the name {name} is registered on the component." +
                                                    $"Check if you misspelled it or forgot to add the {nameof(NetworkRpcAttribute)} to your method.");
            }

            var call = new RpcCall
            {
                EntityId    = _context.Entity.Id,
                ComponentId = _context.Id,
                RpcCode     = _rpcMethodLookup[name],
                Params      = parameters
            };

            _context.Entity.Manager.SendEvent(DefaultEvents.Rpc, call, target, reliable);
        }
        private IReceiveMessage ParseUndirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line,
                                                       IMessageTarget receiver)
        {
            Match results = regex.Match(line);

            if (results.Success)
            {
                String message = String.Empty;
                if (results.Groups[1].Success)
                {
                    message = results.Groups[1].Value;
                }

                return(Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, receiver, type,
                                                   ReplyType.Unknown));
            }
            return(null);
        }
        private IMessageTarget ParseReceiver(String name)
        {
            IMessageTarget receiver = null;

            switch (name[0])
            {
            case '#':
            case '!':
            case '&':
            case '+':
                receiver = Connection.GetChannel(name);
                break;

            default:
                receiver = Connection.GetUser(name);
                break;
            }
            return(receiver);
        }
        public static Boolean IsFromHost(this IMessageTarget target, Message message)
        {
            if (message.Source == MessageService.AddinHostId)
            {
                return(true);
            }
            String hostActualId = null;

            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                MessageService ms = AppDomain.CurrentDomain.GetData("ms") as MessageService;
                hostActualId = ms?.GetHostActualId();
            }
            else
            {
                AddinProxy proxy = AppDomain.CurrentDomain.GetData("proxy") as AddinProxy;
                hostActualId = proxy?.GetHostActualId();
            }
            return(hostActualId == message.Source);
        }
Beispiel #23
0
        public override void SendEvent(byte code, object data, IMessageTarget target, bool reliable = true)
        {
            if (_photonClient.CurrentRoom == null)
            {
                throw new InvalidOperationException("Cannot send events before joining a room.");
            }

            var evt = CreateEvent(code, data, target);

            ReceiverGroup?receivers = null;

            int[] targetClients = null;
            if (target == null || target == MessageTarget.Others)
            {
                receivers = ReceiverGroup.Others;
            }
            else if (target == MessageTarget.AllPlayers)
            {
                receivers = ReceiverGroup.All;
            }
            else if (target == MessageTarget.Server)
            {
                receivers = ReceiverGroup.MasterClient;
            }
            else
            {
                targetClients = ResolveClientIds(target);
            }

            _raiseEventOptions.TargetActors = targetClients;
            _raiseEventOptions.Receivers    = receivers ?? ReceiverGroup.Others;

            var serialized = Serializer.Serialize(evt, out int length);

            _photonArrayWrapper.Array  = serialized;
            _photonArrayWrapper.Length = length;

            // Send the event over the network
            _photonClient.OpRaiseEvent(PhotonEventCode, evt.Data != null ? _photonArrayWrapper : null,
                                       _raiseEventOptions, reliable ? SendOptions.SendReliable : SendOptions.SendUnreliable);
        }
        private IReceiveMessage ParseKickMessage(IMessageTarget sender, String line)
        {
            Match results = KickRegex.Match(line);

            if (results.Success && results.Groups[1].Success && results.Groups[2].Success)
            {
                String channelName = results.Groups[1].Value;
                String userName    = results.Groups[2].Value;
                String message     = String.Empty;
                if (results.Groups[3].Success)
                {
                    message = results.Groups[3].Value;
                }
                IChannel     channel     = Connection.GetChannel(channelName);
                IChannelUser channelUser = channel.GetUser(userName);

                return(Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, channelUser,
                                                   ReceiveType.Kick, ReplyType.Unknown));
            }
            return(null);
        }
        private IReceiveMessage ParseModeMessage(IMessageTarget sender, String line)
        {
            Match results = ModeRegex.Match(line);

            if (results.Success && results.Groups[1].Success)
            {
                String         receiverName = results.Groups[1].Value;
                IMessageTarget receiver     = ParseReceiver(receiverName);
                String         message      = String.Empty;
                if (results.Groups[2].Success)
                {
                    message = results.Groups[2].Value;
                }

                ReceiveType type = receiver.Type == MessageTargetType.Channel ? ReceiveType.ChannelModeChange :
                                   ReceiveType.UserModeChange;
                return(Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, receiver, type,
                                                   ReplyType.Unknown));
            }
            return(null);
        }
Beispiel #26
0
        public override void SendEvent(byte code, object data, IMessageTarget target, bool reliable = true)
        {
            var evt = CreateEvent(code, data, target);

            // TODO: handle targets properly

            int[] targetClients = ResolveClientIds(target);

            if (target == MessageTarget.AllPlayers || targetClients != null && targetClients.Contains(_isServer ? 1 : 2))
            {
                EventSubject.OnNext(evt);
            }

            _manager.GetPeersNonAlloc(_peers);
            if (target == MessageTarget.AllPlayers || target == MessageTarget.Others ||
                targetClients != null && targetClients.Contains(_isServer ? 2 : 1))
            {
                foreach (var peer in _peers)
                {
                    peer.Send(Serializer.Serialize(evt, out int length), 0, length,
                              reliable ? SendOptions.Unreliable : SendOptions.ReliableOrdered);
                }
            }
        }
        /// <summary>
        /// Sends an action to this target.
        /// </summary>
        ///
        /// <param name="channel">The channel to act on.</param>
        /// <param name="action"> The action.</param>
        public static void SendAction(this IMessageTarget target, String action)
        {
            IClientConnection connection = target.Connection;

            connection.SendAndForget(connection.MessageSender.Action(target, action));
        }
Beispiel #28
0
        private IReceiveMessage ParseDirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line)
        {
            Match results = regex.Match(line);
            if(results.Success && results.Groups[1].Success)
            {
                String receiverName = results.Groups[1].Value;
                IMessageTarget receiver = ParseReceiver(receiverName);
                String message = String.Empty;
                if(results.Groups[2].Success)
                    message = results.Groups[2].Value;

                IMessageTarget realSender = sender;
                if(sender.Type == MessageTargetType.User && receiver.Type == MessageTargetType.Channel)
                {
                    IChannel channel = receiver as IChannel;
                    realSender = channel.GetUser(sender.Name);
                }
                return Client.CreateReceiveMessage(Connection, message, DateTime.Now, realSender, receiver, type,
                    ReplyType.Unknown);
            }
            return null;
        }
Beispiel #29
0
 private IReceiveMessage ParseInformationMessage(IMessageTarget sender, ReceiveType type, ReplyType replyType, 
     String parameters)
 {
     return Client.CreateReceiveMessage(Connection, parameters, DateTime.Now, sender, Connection.Me, type,
         replyType);
 }
Beispiel #30
0
 public ISendMessage Notice(IMessageTarget receiver, String message)
 {
     return Client.CreateSendMessage(Connection, String.Concat("NOTICE ", receiver.Name, " :"), message,
         String.Empty, SendType.Notice, receiver);
 }
Beispiel #31
0
        private IReceiveMessage ParseInviteMessage(IMessageTarget sender, String line)
        {
            Match results = InviteRegex.Match(line);
            if(results.Success && results.Groups[1].Success && results.Groups[2].Success)
            {
                String userName = results.Groups[1].Value;
                String channelName = results.Groups[2].Value;
                IChannel channel = Connection.GetChannel(channelName);

                return Client.CreateReceiveMessage(Connection, userName, DateTime.Now, sender, channel,
                    ReceiveType.Invite, ReplyType.Unknown);
            }
            return null;
        }
Beispiel #32
0
        private IReceiveMessage ParseMessage(IMessageTarget sender, String line)
        {
            IReceiveMessage message = null;

            message = ParseDirectedMessage(ActionRegex, ReceiveType.Action, sender, line);
            if(message != null) return message;
            message = ParseDirectedMessage(MessageRegex, ReceiveType.Message, sender, line);
            if(message != null) return message;
            message = ParseDirectedMessage(NoticeRegex, ReceiveType.Notice, sender, line);
            if(message != null) return message;

            message = ParseDirectedMessage(JoinRegex, ReceiveType.Join, sender, line);
            if(message != null) return message;
            message = ParseDirectedMessage(PartRegex, ReceiveType.Part, sender, line);
            if(message != null) return message;
            message = ParseKickMessage(sender, line);
            if(message != null) return message;
            message = ParseDirectedMessage(TopicRegex, ReceiveType.TopicChange, sender, line);
            if(message != null) return message;

            message = ParseUndirectedMessage(NickRegex, ReceiveType.NickChange, sender, line,
                Connection.Me.Network.Value);
            if(message != null) return message;
            message = ParseUndirectedMessage(QuitRegex, ReceiveType.Quit, sender, line, Connection.Me.Network.Value);
            if(message != null) return message;

            message = ParseModeMessage(sender, line);
            if(message != null) return message;
            message = ParseInviteMessage(sender, line);
            if(message != null) return message;

            return Client.CreateReceiveMessage(Connection, line, DateTime.Now, sender, Connection.Me.Network.Value,
                ReceiveType.Unknown, ReplyType.Unknown);
        }
Beispiel #33
0
        private IReceiveMessage ParseModeMessage(IMessageTarget sender, String line)
        {
            Match results = ModeRegex.Match(line);
            if(results.Success && results.Groups[1].Success)
            {
                String receiverName = results.Groups[1].Value;
                IMessageTarget receiver = ParseReceiver(receiverName);
                String message = String.Empty;
                if(results.Groups[2].Success)
                    message = results.Groups[2].Value;

                ReceiveType type = receiver.Type == MessageTargetType.Channel ? ReceiveType.ChannelModeChange :
                    ReceiveType.UserModeChange;
                return Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, receiver, type,
                    ReplyType.Unknown);
            }
            return null;
        }
Beispiel #34
0
        private IReceiveMessage ParseUndirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line,
            IMessageTarget receiver)
        {
            Match results = regex.Match(line);
            if(results.Success)
            {
                String message = String.Empty;
                if(results.Groups[1].Success)
                    message = results.Groups[1].Value;

                return Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, receiver, type,
                    ReplyType.Unknown);
            }
            return null;
        }
Beispiel #35
0
 private ISendMessage ReplyMessage(IMessageSender messageSender, IMessageTarget target, ReplyForm replyForm, 
     object result)
 {
     switch(replyForm)
     {
         case ReplyForm.Action: return messageSender.Action(target, result.ToString());
         case ReplyForm.Notice: return messageSender.Notice(target, result.ToString());
         default: return messageSender.Message(target, result.ToString());
     }
 }
Beispiel #36
0
Datei: Bot.cs Projekt: Gohla/Veda
 public String More(IMessageTarget sender)
 {
     return _replyHandler.More(sender);
 }
Beispiel #37
0
 private ISendMessage SendMessage(ISendMessage message, String contents, IMessageTarget sender, 
     ReplyForm replyForm)
 {
     if(replyForm == ReplyForm.Reply)
         contents = sender.Name + ": " + contents;
     return message.Connection.Client.CreateSendMessage(message, contents);
 }
Beispiel #38
0
 public ISendMessage Notice(IMessageTarget receiver, String message)
 {
     return Client.CreateSendMessage(Connection, String.Concat("NOTICE ", receiver.Name, " :"), message,
         String.Empty, SendType.Notice, receiver);
 }
Beispiel #39
0
 public IReceiveMessage CreateReceiveMessage(IClientConnection connection, String contents, DateTime date,
     IMessageTarget sender, IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     return new ReceiveMessage(connection, contents, date, sender, receiver, type, replyType);
 }
Beispiel #40
0
        private IReceiveMessage ParseKickMessage(IMessageTarget sender, String line)
        {
            Match results = KickRegex.Match(line);
            if(results.Success && results.Groups[1].Success && results.Groups[2].Success)
            {
                String channelName = results.Groups[1].Value;
                String userName = results.Groups[2].Value;
                String message = String.Empty;
                if(results.Groups[3].Success)
                    message = results.Groups[3].Value;
                IChannel channel = Connection.GetChannel(channelName);
                IChannelUser channelUser = channel.GetUser(userName);

                return Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, channelUser,
                    ReceiveType.Kick, ReplyType.Unknown);
            }
            return null;
        }
Beispiel #41
0
 public ISendMessage Action(IMessageTarget receiver, String action)
 {
     return Client.CreateSendMessage(Connection, String.Concat("PRIVMSG ", receiver.Name, " :"),
         String.Concat('\x001', "ACTION ", action, '\x001'), String.Empty, SendType.Privmsg, receiver);
 }
Beispiel #42
0
 public ISendMessage Message(IMessageTarget receiver, String message)
 {
     return Client.CreateSendMessage(Connection, String.Concat("PRIVMSG ", receiver.Name, " :"), message,
         String.Empty, SendType.Privmsg, receiver);
 }
Beispiel #43
0
 public abstract Task SendMessage(IMessageTarget target, Message message);
Beispiel #44
0
 public ISendMessage Mode(IMessageTarget target)
 {
     return Client.CreateSendMessage(Connection, "MODE ", target.Name, String.Empty, SendType.Mode, target);
 }
Beispiel #45
0
 public IReceiveMessage CreateReceiveMessage(IClientConnection connection, String contents, DateTime date,
                                             IMessageTarget sender, IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     return(new ReceiveMessage(connection, contents, date, sender, receiver, type, replyType));
 }
Beispiel #46
0
 public ISendMessage Mode(IMessageTarget target, String newmode, String newModeParameter)
 {
     return Client.CreateSendMessage(Connection, "MODE ", String.Concat(target.Name, " ", newmode, " ",
         newModeParameter), String.Empty, SendType.Mode, target);
 }
Beispiel #47
0
 public bool ContainsReceiver(IMessageTarget receiver)
 {
     return _receivers.Contains(receiver);
 }
Beispiel #48
0
        public ISendMessage Mode(IMessageTarget target, String[] newModes, String[] newModeParameters)
        {
            if(newModes == null)
            {
                throw new ArgumentNullException("newModes");
            }
            if(newModeParameters == null)
            {
                throw new ArgumentNullException("newModeParameters");
            }
            if(newModes.Length != newModeParameters.Length)
            {
                throw new ArgumentException("newModes and newModeParameters must have the same size.");
            }

            StringBuilder newMode = new StringBuilder(newModes.Length);
            StringBuilder newModeParameter = new StringBuilder();
            // as per RFC 3.2.3, maximum is 3 modes changes at once
            int maxModeChanges = 3;
            if(newModes.Length > maxModeChanges)
            {
                throw new ArgumentOutOfRangeException(
                    "newModes.Length",
                    newModes.Length,
                    String.Format("Mode change list is too large (> {0}).", maxModeChanges)
                );
            }

            for(int i = 0; i <= newModes.Length; i += maxModeChanges)
            {
                for(int j = 0; j < maxModeChanges; j++)
                {
                    if(i + j >= newModes.Length)
                    {
                        break;
                    }
                    newMode.Append(newModes[i + j]);
                }

                for(int j = 0; j < maxModeChanges; j++)
                {
                    if(i + j >= newModeParameters.Length)
                    {
                        break;
                    }
                    newModeParameter.Append(newModeParameters[i + j]);
                    newModeParameter.Append(" ");
                }
            }
            if(newModeParameter.Length > 0)
            {
                // remove trailing space
                newModeParameter.Length--;
                newMode.Append(" ");
                newMode.Append(newModeParameter.ToString());
            }

            return Mode(target, newMode.ToString());
        }
Beispiel #49
0
 public bool ContainsReceiver(IMessageTarget receiver)
 {
     return(_receivers.Contains(receiver));
 }
Beispiel #50
0
 public ISendMessage Action(IMessageTarget receiver, String action)
 {
     return Client.CreateSendMessage(Connection, String.Concat("PRIVMSG ", receiver.Name, " :"),
         String.Concat('\x001', "ACTION ", action, '\x001'), String.Empty, SendType.Privmsg, receiver);
 }
        /// <summary>
        /// Sends a notice to this target.
        /// </summary>
        ///
        /// <param name="channel">The channel to act on.</param>
        /// <param name="notice"> The notice.</param>
        public static void SendNotice(this IMessageTarget target, String notice)
        {
            IClientConnection connection = target.Connection;

            connection.SendAndForget(connection.MessageSender.Notice(target, notice));
        }
Beispiel #52
0
        public void Reply(IReceiveMessage message, IMessageTarget sender, ReplyForm replyForm, Exception e)
        {
            LogUserError(message, e);

            if(!_data.ReplyError)
                return;

            if(_data.ReplyErrorDetailed)
                Reply(message, sender, replyForm, "Error -- " + e.Message);
            else
                Reply(message, sender, replyForm, "An error occurred.");
        }