Esempio n. 1
0
 internal CtcpEventArgs(IrcMessage message)
     : base(message)
 {
     this.From = message.From as IrcPeer;
     this.To = message.Parameters.Count > 0 ? new IrcTarget(message.Parameters[0]) : null;
     this.Command = message.Parameters.Count > 1 ? CtcpCommand.Parse(message.Parameters[1]) : null;
     this.IsResponse = message.Command == "NOTICE";
 }
Esempio n. 2
0
        internal IrcInfoEventArgs(IrcMessage message)
            : base(message)
        {
            int code;
            if (int.TryParse(message.Command, out code))
            {
                this.Code = (IrcCode)code;
            }

            this.Text = message.Parameters.Count > 1 ? string.Join(" ", message.Parameters.Skip(1).ToArray()) : null;
            this.IsError = (int)this.Code >= 400;
        }
Esempio n. 3
0
 internal IrcEventArgs(IrcMessage message)
 {
     this.Message = message;
 }
Esempio n. 4
0
 internal IrcChannelModeEventArgs(IrcMessage message)
     : base(message)
 {
     this.Who = message.From as IrcPeer;
     this.Channel = message.Parameters.Count > 0 ? new IrcTarget(message.Parameters[0]) : null;
     this.Modes = message.Parameters.Count > 1 ? IrcChannelMode.ParseModes(message.Parameters.Skip(1)) : null;
 }
Esempio n. 5
0
 internal IrcTopicEventArgs(IrcMessage message)
     : base(message)
 {
     this.Who = message.From as IrcPeer;
     this.Channel = message.Parameters.Count > 0 ? new IrcTarget(message.Parameters[0]) : null;
     this.Text = message.Parameters.Count > 1 ? message.Parameters[1] : null;
 }
Esempio n. 6
0
 internal IrcJoinEventArgs(IrcMessage message)
     : base(message)
 {
     this.Who     = message.From as IrcPeer;
     this.Channel = message.Parameters.Count > 0 ? new IrcTarget(message.Parameters[0]) : null;
 }
Esempio n. 7
0
 private void OnInvite(IrcMessage message)
 {
     RaiseEvent(Invited, new IrcInviteEventArgs(message));
 }
Esempio n. 8
0
 internal IrcNickEventArgs(IrcMessage message)
     : base(message)
 {
     var peer = message.From as IrcPeer;
     this.OldNickname = peer?.Nickname;
     this.NewNickname = message.Parameters.Count > 0 ? message.Parameters[0] : null;
 }
Esempio n. 9
0
 private void OnQuit(IrcMessage message)
 {
     RaiseEvent(UserQuit, new IrcQuitEventArgs(message));
 }
Esempio n. 10
0
 private void OnTopic(IrcMessage message)
 {
     RaiseEvent(TopicChanged, new IrcTopicEventArgs(message));
 }
Esempio n. 11
0
 internal IrcUserModeEventArgs(IrcMessage message)
     : base(message)
 {
     this.Modes = message.Parameters.Count > 1 ? IrcUserMode.ParseModes(message.Parameters.Skip(1)) : null;
 }
Esempio n. 12
0
 internal IrcInviteEventArgs(IrcMessage message)
     : base(message)
 {
     this.From    = message.From as IrcPeer;
     this.Channel = message.Parameters.Count > 1 ? message.Parameters[1] : null;
 }
Esempio n. 13
0
 internal IrcEventArgs(IrcMessage message)
 {
     this.Message = message;
 }
Esempio n. 14
0
 internal IrcInviteEventArgs(IrcMessage message)
     : base(message)
 {
     this.From = message.From as IrcPeer;
     this.Channel = message.Parameters.Count > 1 ? message.Parameters[1] : null;
 }
Esempio n. 15
0
 private void OnCtcpCommand(IrcMessage message)
 {
     RaiseEvent(CtcpCommandReceived, new CtcpEventArgs(message));
 }
Esempio n. 16
0
 internal IrcKickEventArgs(IrcMessage message)
     : base(message)
 {
     this.Kicker = message.From as IrcPeer;
     this.Channel = message.Parameters.Count > 0 ? new IrcTarget(message.Parameters[0]) : null;
     this.KickeeNickname = message.Parameters.Count > 1 ? message.Parameters[1] : null;
     this.Text = message.Parameters.Count > 2 ? message.Parameters[2] : null;
 }
Esempio n. 17
0
        private async Task SocketLoopAsync(CancellationToken ct)
        {
            try
            {
                byte[] readBuffer = new byte[512];

                while (_tcpClient != null && _tcpClient.Connected && !_wtoken.Token.IsCancellationRequested)
                {
                    var heartBeatTask = Task.Delay(HeartbeatInterval, ct);
                    var readTask      = _stream.ReadAsync(readBuffer, 0, 512, ct);

                    var completed = await Task.WhenAny(heartBeatTask, readTask).ConfigureAwait(false);

                    if (completed == heartBeatTask)
                    {
                        await Socket_OnHeartbeat();
                    }
                    else if (completed == readTask)
                    {
                        var read = await readTask;
                        if (read == 0)
                        {
                            // 0 bytes mean socket close
                            Close();
                        }
                        else
                        {
                            var gotCarriageReturn = false;
                            var input             = new List <byte>();
                            for (int i = 0; i < read; i++)
                            {
                                byte cur = readBuffer[i];
                                switch (cur)
                                {
                                case 0xa:
                                    if (gotCarriageReturn)
                                    {
                                        var incoming = IrcMessage.Parse(Encoding.UTF8.GetString(input.ToArray()));
                                        await OnMessageReceived(new IrcMessageEventArgs(incoming));

                                        input.Clear();
                                    }
                                    break;

                                case 0xd:
                                    break;

                                default:
                                    input.Add(cur);
                                    break;
                                }
                                gotCarriageReturn = cur == 0xd;
                            }
                        }
                    }
                }
                Close();
            }
            catch (Exception e)
            {
                OnConnectionError(new ErrorEventArgs(e));
            }
        }
Esempio n. 18
0
 internal IrcQuitEventArgs(IrcMessage message)
     : base(message)
 {
     this.Who = message.From as IrcPeer;
     this.Text = message.Parameters.Count > 0 ? message.Parameters[0] : null;
 }
Esempio n. 19
0
 private async Task PostMessageAsync(IrcMessage message)
 {
     if (_tcpClient.Connected && _stream != null)
     {
         try
         {
             var writeBuffer = new byte[Encoding.UTF8.GetMaxByteCount(512)];
             var output = message.ToString();
             var count = Encoding.UTF8.GetBytes(output, 0, output.Length, writeBuffer, 0);
             count = Math.Min(510, count);
             writeBuffer[count] = 0xd;
             writeBuffer[count + 1] = 0xa;
             await _stream.WriteAsync(writeBuffer, 0, count + 2, _wtoken.Token).ConfigureAwait(false);
         }
         catch (Exception e)
         {                    
             OnConnectionError(new ErrorEventArgs(e));
         }
     }
 }
Esempio n. 20
0
 internal IrcUserModeEventArgs(IrcMessage message)
     : base(message)
 {
     this.Modes = message.Parameters.Count > 1 ? IrcUserMode.ParseModes(message.Parameters.Skip(1)) : null;
 }
Esempio n. 21
0
 internal IrcQuitEventArgs(IrcMessage message)
     : base(message)
 {
     this.Who  = message.From as IrcPeer;
     this.Text = message.Parameters.Count > 0 ? message.Parameters[0] : null;
 }