Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see>UserEventArgs</see> with the specified settings.
        /// </summary>
        /// <param name="eventType">The type of chat event.</param>
        /// <param name="user">A reference to the user involved in the event.</param>
        public UserEventArgs(ChatEventType eventType, ChatUser user)
            : base(eventType)
        {
            Debug.Assert(user != null);

            m_user = user;
        }
        /// <summary>
        /// Requests a Warcraft 3 profile for the specified user, requesting them for the user's 
        /// specific product.
        /// </summary>
        /// <param name="user">The user for whom to request a profile.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="user"/> does 
        /// not on Warcraft III: The Reign of Chaos or The Frozen Throne.</exception>
        public virtual void RequestWarcraft3Profile(ChatUser user)
        {
            if (user.Stats.Product != Product.Warcraft3Expansion && user.Stats.Product != Product.Warcraft3Retail)
                throw new ArgumentOutOfRangeException("user", user.Stats.Product, "Cannot request Warcraft 3 Profile statistics for the specified product.");

            RequestWarcraft3Profile(user.Username, user.Stats.Product == Product.Warcraft3Expansion);
        }
Exemplo n.º 3
0
        public JinxBotDefaultPrincipal(ChatUser user, string defaultGateway)
        {
            Match m = Parser.Match(user.Username);
            if (!m.Success)
                throw new ArgumentException("The specified user had an invalid username.");

            m_userName = m.Groups[ACCTNAME].Value;
            if (m.Groups[GATEWAY].Success)
                m_gateway = m.Groups[GATEWAY].Value;
            else
                m_gateway = defaultGateway;

            if (m.Groups[CHARNAME].Success)
                m_charName = m.Groups[CHARNAME].Value;
        }
Exemplo n.º 4
0
        public IJinxBotPrincipal FindExact(ChatUser user)
        {
            if (System.Diagnostics.Debugger.IsAttached)
                System.Diagnostics.Debugger.Break();

            string accountName, gateway;
            Match m = m_separator.Match(user.Username);
            if (!m.Success)
                throw new InvalidDataException("Could not match the user's username into appropriate parts.");

            accountName = m.Groups["accountName"].Value;
            if (m.Groups["gateway"].Success)
                gateway = m.Groups["gateway"].Value;
            else
                gateway = m_defaultGateway;

            User dbUser = (from u in m_users
                           where u.AccountName.Equals(accountName, StringComparison.OrdinalIgnoreCase) &&
                                   u.Gateway.Equals(gateway, StringComparison.OrdinalIgnoreCase)
                           select u).FirstOrDefault();
            if (dbUser == null)
            {
                dbUser = new User(accountName, gateway, this);
                foreach (Meta meta in m_metas)
                {
                    if (meta.Matcher.IsMatch(accountName))
                    {
                        foreach (string role in meta.Roles)
                            dbUser.AddRole(role);
                    }
                }
                m_users.Add(dbUser);
            }

            return dbUser;
        }
Exemplo n.º 5
0
        private ToolTipPropertySet CreateTip(ChatUser user)
        {
            // get the image to use
            Image icon = null;
            if (m_resourceProvider != null)
            {
                icon = m_resourceProvider.Icons.GetImageFor(user.Stats.Product);
            }

            // get the color to use.
            Color background = Color.Black;
            if (ProductTipColors.ContainsKey(user.Stats.Product))
                background = ProductTipColors[user.Stats.Product];
            
            // generate description
            StringBuilder description = new StringBuilder();
            description.Append("Product:    ");
            description.AppendLine(user.Stats.Product.Name);
            description.Append("Ping:       ");
            description.AppendLine(user.Ping.ToString(CultureInfo.InvariantCulture));
            description.Append("Flags:      ");
            description.AppendLine(user.Flags.ToString());
            description.AppendLine();

            if (user.Stats is StarcraftStats)
            {
                StarcraftStats stats = user.Stats as StarcraftStats;
                description.Append("Wins:       ");
                description.AppendLine(stats.Wins.ToString(CultureInfo.InvariantCulture));
                description.Append("Rank:       ");
                description.AppendLine(stats.LadderRank.ToString(CultureInfo.InvariantCulture));
                description.Append("Rating:     ");
                description.AppendLine(stats.LadderRating.ToString(CultureInfo.InvariantCulture));
            }
            else if (user.Stats is Diablo2Stats)
            {
                Diablo2Stats stats = user.Stats as Diablo2Stats;
                description.AppendLine(stats.IsExpansionCharacter ? "Expansion character" : "Classic character");
                if (stats.IsHardcoreCharacter)
                    description.Append("Hardcore ");
                if (stats.IsLadderCharacter)
                    description.Append("Ladder ");
                description.Append(stats.IsRealmCharacter ? "Realm " : "Open ");
                description.AppendLine("character");
                if (stats.IsRealmCharacter)
                {
                    description.AppendFormat(CultureInfo.InvariantCulture, "Level {0} {1}", stats.Level, stats.CharacterClass);
                    description.AppendLine();
                    description.AppendLine(stats.CharacterName);
                    description.AppendLine(stats.Difficulty.ToString());
                }
            }
            else if (user.Stats is Warcraft3Stats)
            {
                Warcraft3Stats stats = user.Stats as Warcraft3Stats;
                description.Append("Clan:       ");
                description.AppendLine(string.IsNullOrEmpty(stats.ClanTag) ? "(none)" : stats.ClanTag);
                description.AppendFormat(CultureInfo.InvariantCulture, "Level:      {0}", stats.Level);
                description.AppendLine();
            }

            ToolTipPropertySet ttps = new ToolTipPropertySet(user.Username, description.ToString(), background, icon, Color.White, background);
            return ttps;
        }
Exemplo n.º 6
0
        private void NoteTag(string tag, ChatUser chatUser, string currentChannel, ChatEventType action)
        {
            if (string.IsNullOrEmpty(tag))
                return;

            string act = "joining the channel";
            switch (action)
            {
                case ChatEventType.UserInChannel:
                    act = "being seen in the channel";
                    break;
                case ChatEventType.UserFlagsChanged:
                    act = "having flags updated in the channel";
                    break;
                case ChatEventType.UserLeftChannel:
                    act = "leaving the channel";
                    break;
                case ChatEventType.UserJoinedChannel:
                    act = "joining the channel";
                    break;
            }
            using (ClansDataContext dc = ClansDataContext.Create(m_dbPath))
            {
                if (dc.Clans.Where(c => c.Tag.ToUpper() == tag.ToUpper()).Count() == 0)
                {
                    Clan c = new Clan
                    {
                        GatewayID = m_gatewayID,
                        Tag = tag,
                        DiscoverySource = string.Format("{0}, a Warcraft 3 user in {1}, {2}.", chatUser.Username, currentChannel, act)
                    };
                    dc.Clans.InsertOnSubmit(c);

                    try
                    {
                        dc.SubmitChanges();
                        m_client.MainWindow.AddChat(new ChatNode[] {
                            new ChatNode("JinxBot Clan Gnome added ", Color.DarkRed),
                            new ChatNode(c.DiscoverySource, Color.Yellow)
                        });
                    }
                    catch (Exception ex)
                    {
                        m_client.MainWindow.AddChat(new ChatNode[] {
                            new ChatNode("JinxBot Clan Gnome error ", Color.DarkRed),
                            new ChatNode("Error saving a new clan:", Color.Red),
                            ChatNode.NewLine,
                            new ChatNode(ex.ToString(), Color.OrangeRed)
                    });
                    }
                }
                else
                {
                    m_client.MainWindow.AddChat(new ChatNode[] {
                        new ChatNode("JinxBot Clan Gnome note: ", Color.DarkRed),
                        new ChatNode("Already noted clan ", Color.Yellow),
                        new ChatNode(tag, Color.Lime)
                    });
                }
            }
        }
Exemplo n.º 7
0
        private void HandleChatEvent(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);
            ChatEventType type = (ChatEventType)dr.ReadInt32();
            int flags = dr.ReadInt32();
            int ping = dr.ReadInt32();
            dr.Seek(12);
            string user = dr.ReadCString();
            byte[] userInfo = dr.ReadNullTerminatedByteArray();
            string text = Encoding.ASCII.GetString(userInfo);

            switch (type)
            {
                case ChatEventType.UserInChannel:
                case ChatEventType.UserJoinedChannel:
                    ChatUser newUser = new ChatUser(user, ping, (UserFlags)flags, UserStats.Parse(user, userInfo));
                    if (m_namesToUsers.ContainsKey(user))
                    {
                        m_namesToUsers.Remove(user);
                    }
                    m_namesToUsers.Add(user, newUser);
                    UserEventArgs uArgs = new UserEventArgs(type, newUser);
                    HandleUserChatEvent(uArgs);
                    break;
                case ChatEventType.UserFlagsChanged:
                    if (m_namesToUsers.ContainsKey(user))
                    {
                        ChatUser changedUser = m_namesToUsers[user];
                        changedUser.Flags = (UserFlags)flags;
                        UserEventArgs updatedArgs = new UserEventArgs(type, changedUser);
                        HandleUserChatEvent(updatedArgs);
                    }
                    else if (m_channelName.Equals("The Void", StringComparison.OrdinalIgnoreCase))
                    {
                        ChatUser voidUser = new ChatUser(user, ping, (UserFlags)flags, UserStats.Parse(user, userInfo));
                        m_namesToUsers.Add(user, voidUser);
                        UserEventArgs voidArgs = new UserEventArgs(type, voidUser);
                        HandleUserChatEvent(voidArgs);
                    }
                    break;
                case ChatEventType.UserLeftChannel:
                    if (m_namesToUsers.ContainsKey(user))
                    {
                        ChatUser goneUser = m_namesToUsers[user];
                        UserEventArgs leftArgs = new UserEventArgs(type, goneUser);
                        HandleUserChatEvent(leftArgs);
                    }
                    break;
                case ChatEventType.Emote:
                case ChatEventType.Talk:
                case ChatEventType.WhisperReceived:
                case ChatEventType.WhisperSent:
                    ChatMessageEventArgs cmArgs = new ChatMessageEventArgs(type, (UserFlags)flags, user, Encoding.UTF8.GetString(userInfo));
                    HandleChatMessageEvent(cmArgs);
                    break;
                case ChatEventType.NewChannelJoined:
                    ServerChatEventArgs joinArgs = new ServerChatEventArgs(type, flags, text);
                    m_channelName = text;
                    m_namesToUsers.Clear();
                    OnJoinedChannel(joinArgs);
                    break;
                case ChatEventType.Broadcast:
                case ChatEventType.ChannelDNE:
                case ChatEventType.ChannelFull:
                case ChatEventType.ChannelRestricted: 
                case ChatEventType.Error:
                case ChatEventType.Information:
                    ServerChatEventArgs scArgs = new ServerChatEventArgs(type, flags, text);
                    HandleServerChatEvent(scArgs);
                    break;
            }

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
        }