Example #1
0
 public void SendMessage(GGMessage message)
 {
     message.Sender = this.number;
     foreach (uint recipient in message.Recipients)
     {
         List <uint> recipients = message.Recipients.ToList();
         recipients.Remove(recipient);
         SendMessagePacket packet = new SendMessagePacket(recipient, recipients.ToArray(),
                                                          message.HtmlMessage, message.PlainMessage, message.Sequence);
         lock (this.messages)
         {
             this.messages.Add(message.Sequence, message);
         }
         this.packetManager.AddPacket(packet);
     }
 }
Example #2
0
        private void packetManager_PacketReceived(object sender, PacketEventArgs e)
        {
            switch (e.Packet.PacketType)
            {
            case PacketType.Welcome:
                WelcomePacket welcome = e.Packet as WelcomePacket;
                LoginPacket   packet  = new LoginPacket(this.number, this.password, welcome.Seed,
                                                        this.loginStatus, this.channels);
                this.packetManager.AddPacket(packet);
                break;

            // case PacketType.Login80_OK:
            //     this.State = State.Connected;
            //     this.timerPing.Start();
            //     if (this.Connected != null)
            //     {
            //         this.Connected(this, EventArgs.Empty);
            //     }
            //     break;

            case PacketType.Login80_Fail:
                if (this.LoggedFail != null)
                {
                    this.LoggedFail(this, EventArgs.Empty);
                }
                break;

            case PacketType.Disconnect:
                this.State = State.Disconnected;
                this.timerPing.Stop();
                if (this.Disconnected != null)
                {
                    this.Disconnected(this, EventArgs.Empty);
                }
                break;

            case PacketType.Login80_OK:
                this.State = State.Connected;
                this.SendContactList();
                this.timerPing.Start();
                if (this.Connected != null)
                {
                    this.Connected(this, EventArgs.Empty);
                }
                break;

            case PacketType.UserData:
                UserDataPacket userData = e.Packet as UserDataPacket;
                foreach (UserData data in userData.Attributes)
                {
                    if (this.contacts.ContainsKey(data.Number))
                    {
                        this.contacts[data.Number].ExtendedInfo = data.Attributes;
                        if (this.ContactInfoReceived != null)
                        {
                            this.ContactInfoReceived(this, new ContactEventArgs(this.contacts[data.Number]));
                        }
                    }
                }
                break;

            case PacketType.NotifyReply80:
            case PacketType.Status:
                NotifyReplyPacket notify = e.Packet as NotifyReplyPacket;
                foreach (ClientState state in notify.ClientStates)
                {
                    this.contacts[state.Number].State = state;
                    if (this.ContactStateChanged != null)
                    {
                        this.ContactStateChanged(this, new ContactEventArgs(this.contacts[state.Number]));
                    }
                }
                break;

            case PacketType.TypingNotify:
                TypingNotifyPacket typing = e.Packet as TypingNotifyPacket;
                if (this.ContactTyping != null)
                {
                    if (this.contacts.ContainsKey(typing.Number))
                    {
                        GGContact contact = this.contacts[typing.Number];
                        this.ContactTyping(this, new TypingEventArgs(typing.Value, contact));
                    }
                }
                break;

            case PacketType.SendMessageAck:
                SendMessageAckPacket ack = e.Packet as SendMessageAckPacket;
                if (this.messages.ContainsKey(ack.Sequence))
                {
                    GGMessage message = this.messages[ack.Sequence];
                    lock (this.messages)
                    {
                        this.messages.Remove(ack.Sequence);
                    }
                    if (this.MessageStateChanged != null)
                    {
                        this.MessageStateChanged(this, new MessageEventArgs(ack.Status, message));
                    }
                }
                break;

            case PacketType.RecvMessage:
                ReceiveMessagePacket receive = e.Packet as ReceiveMessagePacket;
                GGMessage            msg     = new GGMessage(receive.Recipients);
                msg.Sender       = receive.Sender;
                msg.HtmlMessage  = receive.HtmlMessage;
                msg.PlainMessage = receive.PlainMessage;
                msg.Time         = receive.Time;
                msg.Sequence     = receive.Sequence;

                ReceiveMessageAckPacket confirm = new ReceiveMessageAckPacket(receive.Sequence);
                this.packetManager.AddPacket(confirm);

                if (this.MessageReceived != null)
                {
                    MessageEventArgs args = new MessageEventArgs(MessageStatus.Delivered, msg);
                    this.MessageReceived(this, args);
                }
                break;
            }
        }
Example #3
0
 public MessageEventArgs(MessageStatus status, GGMessage message)
 {
     this.Status  = status;
     this.Message = message;
 }