Example #1
0
        public void SendMessage(string msg)
        {
            if (!msg.StartsWith("/"))
            {
                bnetConnection.SendMessage(msg);

                var chatMsg = new BnetEvent();
                chatMsg.EventId   = 0x18;
                chatMsg.Message   = msg;
                chatMsg.Username  = bnetAccount.Username;
                chatMsg.TimeStamp = DateTime.Now;
                ChatMessages.Add(chatMsg);

                Messenger.Default.Send <ScrollDownMessage>(new ScrollDownMessage()
                {
                    Source = this
                });
            }
            else
            {
                if (msg.ToLower() == "/reconnect")
                {
                    ChannelUsers.Clear();
                    ChannelList.Clear();
                    FriendsList.Clear();

                    ChattingStatus = "disconnected";
                    Connect();
                }
                else if (msg.ToLower() == "/version")
                {
                    bnetConnection.SendMessage("/me is using Superiority.NET Beta5 (www.BNET.cc).");
                }
                else
                {
                    bnetConnection.SendMessage(msg);
                }
            }
        }
Example #2
0
        /// <summary>
        /// BnetConnection dispatches a message to us on every Bnet Event.
        /// </summary>
        /// <param name="msg">BnetEvent sent to us by BnetConnection</param>
        public void BnetEventReceived(BnetEvent[] messages)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                foreach (var msg in messages)
                {
                    if (ChatMessages.Count > 120)
                    {
                        var cache = new ObservableCollection <BnetEvent>();
                        for (int i = 100; i < ChatMessages.Count; i++)
                        {
                            cache.Add(ChatMessages[i]);
                        }

                        ChatMessages = new ObservableCollection <BnetEvent>(cache);
                    }

                    if (msg.EventId != 0x01 || msg.EventId != 0x09 || msg.EventId != 0x21 || msg.EventId != 0x22)
                    {
                        ChatMessages.Add(msg);
                        Messenger.Default.Send <ScrollDownMessage>(new ScrollDownMessage()
                        {
                            Source = this
                        });
                    }

                    if (msg.EventId == 0x21)
                    {
                        ChannelUsers.Clear();
                        ChannelList.Clear();
                        FriendsList.Clear();

                        ChattingStatus = "disconnected";
                        Connect();
                    }

                    if (msg.EventId == 0x22) // EID_CHANNELUSER
                    {
                        // We use a List<> because ChannelList is only requested once per connection ..
                        ChannelList.Add(new BnetUser()
                        {
                            Username = msg.Username
                        });
                    }

                    if (msg.EventId == 0x07)
                    {
                        ChattingStatus = string.Format("chatting in {0}", msg.Message.ToLower());

                        ChannelUsers.Clear();
                    }

                    if (msg.EventId == 0x03)
                    {
                        foreach (var user in ChannelUsers)
                        {
                            if (user.Username == msg.Username)
                            {
                                ChannelUsers.Remove(user);
                                break;
                            }
                        }
                    }

                    if (msg.EventId == 0x01 || msg.EventId == 0x02)
                    {
                        BnetProduct p;

                        if (msg.Message.Length == 0)
                        {
                            return;
                        }

                        switch (msg.Message.Substring(0, 4))
                        {
                        case "RATS":
                            p = BnetProduct.Starcraft;
                            break;

                        case "PXES":
                            p = BnetProduct.BroodWar;
                            break;

                        case "NB2W":
                            p = BnetProduct.Warcraft2;
                            break;

                        case "VD2D":
                            p = BnetProduct.Diablo2;
                            break;

                        case "PX2D":
                            p = BnetProduct.LordOfDest;
                            break;

                        case "3RAW":
                            p = BnetProduct.Warcraft3;
                            break;

                        case "PX3W":
                            p = BnetProduct.FrozenThrone;
                            break;

                        default:
                            p = BnetProduct.BroodWar;
                            break;
                        }

                        BnetUser usr    = new BnetUser();
                        usr.Username    = msg.Username;
                        usr.DisplayName = msg.Username.Split('@')[0];
                        usr.Product     = p;
                        usr.Flags       = msg.Flags;

                        ChannelUsers.Add(usr);
                    }

                    if (msg.EventId == 0x09)
                    {
                        // Process flag update
                        foreach (var user in ChannelUsers)
                        {
                            if (user.Username == msg.Username)
                            {
                                user.Flags = msg.Flags;
                                break;
                            }
                        }
                    }
                }
            });
        }