Пример #1
0
 public void RemoveContact(GGContact contact)
 {
     if (this.State == State.Connected)
     {
         NotifyPacket notify = new NotifyPacket(PacketType.NotifyRemove);
         notify.Contacts.Add(contact);
         this.packetManager.AddPacket(notify);
     }
     this.contacts.Remove(contact.Number);
 }
Пример #2
0
 public void AddContact(GGContact contact)
 {
     this.contacts.Add(contact.Number, contact);
     if (this.State == State.Connected)
     {
         NotifyPacket notify = new NotifyPacket(PacketType.NotifyAdd);
         notify.Contacts.Add(contact);
         this.packetManager.AddPacket(notify);
     }
 }
Пример #3
0
        public void BlockContact(GGContact contact)
        {
            NotifyPacket notifyRemove = new NotifyPacket(PacketType.NotifyRemove);

            notifyRemove.Contacts.Add(contact);
            this.packetManager.AddPacket(notifyRemove);

            contact.ContactType = ContactType.Blocked;
            NotifyPacket notifyAdd = new NotifyPacket(PacketType.NotifyAdd);

            notifyRemove.Contacts.Add(contact);
            this.packetManager.AddPacket(notifyAdd);
        }
Пример #4
0
 public TypingEventArgs(ushort value, GGContact contact)
 {
     this.Value   = value;
     this.Contact = contact;
 }
Пример #5
0
 public void NotifyTyping(GGContact contact, ushort count)
 {
     this.NotifyTyping(contact.Number, count);
 }
Пример #6
0
 public void BlockContact(uint number)
 {
     GGContact contact = this.contacts[number];
 }
Пример #7
0
        public void RemoveContact(uint number)
        {
            GGContact contact = this.contacts[number];

            this.RemoveContact(contact);
        }
Пример #8
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;
            }
        }
Пример #9
0
 public GGMessage(GGContact recipient) : this(new GGContact[] { recipient })
 {
 }
Пример #10
0
 public ContactEventArgs(GGContact contact)
 {
     this.Contact = contact;
 }