コード例 #1
0
ファイル: CommandPool.cs プロジェクト: zhangb12465/AutoCSer
        /// <summary>
        /// 客户端命令池
        /// </summary>
        /// <param name="client"></param>
        /// <param name="freeIndex"></param>
        internal CommandPool(Client client, int freeIndex = ClientCommand.KeepCommand.CommandPoolIndex)
        {
            this.client  = client;
            bitSize      = client.Attribute.GetCommandPoolBitSize;
            bitSize      = bitSize <= maxArrayBitSize ? (bitSize >= minArrayBitSize ? bitSize : minArrayBitSize) : maxArrayBitSize;
            commandCount = 1 << bitSize;
            if ((uint)freeIndex >= commandCount)
            {
                throw new IndexOutOfRangeException();
            }
            Array          = new CommandLink[commandCount];
            arrays         = new CommandLink[4][];
            this.freeIndex = freeIndex;
            arrays[0]      = Array;
            arrayCount     = 1;
            for (int index = freeIndex; index != commandCount; ++index)
            {
                Array[index].Next = index + 1;
            }
            freeEndIndex = arraySizeAnd = commandCount - 1;
            ushort maxTimeoutSeconds = client.MaxTimeoutSeconds;

            if (maxTimeoutSeconds != 0)
            {
                timeout = new TimeoutCount(this, maxTimeoutSeconds);
            }
        }
コード例 #2
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        int GetEffectiveCount(TimeoutCount timeout)
        {
            int curr = timeout.Count;
            int diff = (int)(DateTime.Now - timeout.LastTimeout).TotalMinutes / 15;

            if (diff > 0)
            {
                curr -= diff;
            }

            if (curr < 0)
            {
                curr = 0;
            }

            return(curr);
        }
コード例 #3
0
        int GetEffectiveCount(TimeoutCount timeout)
        {
            int curr = timeout.Count;
            int diff = (int)(DateTime.Now - timeout.LastTimeout).TotalMinutes / 15;

            if (diff > 0)
                curr -= diff;

            if (curr < 0)
                curr = 0;

            return curr;
        }
コード例 #4
0
        private void ClearChat(WinterBot sender, TwitchUser user, string clearReason, int minTimeout=1)
        {
            bool shouldMessage = !string.IsNullOrEmpty(clearReason);
            var now = DateTime.Now;
            TimeoutCount timeout;
            if (!m_timeouts.TryGetValue(user, out timeout))
            {
                timeout = m_timeouts[user] = new TimeoutCount(now);
            }
            else
            {
                shouldMessage &= (DateTime.Now > timeout.LastTimeout) && (DateTime.Now - timeout.LastTimeout).TotalMinutes > 60;
                timeout.Count = GetEffectiveCount(timeout) + 1;
            }

            timeout.LastTimeout = now;
            if (!m_chatOptions.ShouldTimeout(user))
                timeout.Count = 1;

            if (minTimeout < 1)
                minTimeout = 1;

            int duration = 0;
            switch (timeout.Count)
            {
                case 1:
                case 2:
                    duration = 1;
                    break;

                case 3:
                    shouldMessage = !string.IsNullOrEmpty(clearReason);
                    duration = 5 * 60;
                    break;

                case 4:
                    shouldMessage = !string.IsNullOrEmpty(clearReason);
                    duration = 10 * 60;
                    break;

                case 5:
                    shouldMessage = !string.IsNullOrEmpty(clearReason);
                    duration = 8 * 60 * 60;
                    break;
            }

            if (duration < minTimeout)
                duration = minTimeout;

            if (shouldMessage)
            {
                if (duration == 1)
                    sender.Send(MessageType.Timeout, Importance.Med, "{0}: {1} (This is not a timeout.)", user.Name, clearReason);
                else if (duration < 60)
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1}", user.Name, clearReason);
                else if (duration < 3600)
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1} ({2} minute timeout.)", user.Name, clearReason, duration / 60);
                else
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1} ({2} hour timeout.)", user.Name, clearReason, duration / 3600);
            }

            sender.Timeout(user, duration);
            timeout.LastTimeout = now.AddSeconds(duration);
        }
コード例 #5
0
        private void ClearChat(WinterBot sender, TwitchUser user, string clearReason)
        {
            bool shouldMessage = !string.IsNullOrEmpty(clearReason);
            var now = DateTime.Now;
            TimeoutCount timeout;
            if (!m_timeouts.TryGetValue(user, out timeout))
            {
                timeout = m_timeouts[user] = new TimeoutCount(now);
            }
            else
            {
                shouldMessage &= (DateTime.Now > timeout.LastTimeout) && (DateTime.Now - timeout.LastTimeout).TotalMinutes > 60;

                int curr = timeout.Count;
                int diff = (int)(now - timeout.LastTimeout).TotalMinutes / 15;

                if (diff > 0)
                    curr -= diff;

                if (curr < 0)
                    curr = 0;

                timeout.Count = curr + 1;
            }

            timeout.LastTimeout = now;
            if (!m_chatOptions.ShouldTimeout(user))
                timeout.Count = 1;

            int duration = 0;
            switch (timeout.Count)
            {
                case 1:
                case 2:
                    if (shouldMessage)
                        sender.Send(MessageType.Timeout, "{0}: {1} (This is not a timeout.)", user.Name, clearReason);

                    sender.ClearChat(user);
                    break;

                case 3:
                    duration = 5;
                    sender.Send(MessageType.Timeout, "{0}: {1} ({2} minute timeout.)", user.Name, clearReason, duration);
                    sender.Timeout(user, duration * 60);
                    timeout.LastTimeout = now.AddMinutes(duration);
                    break;

                case 4:
                    duration = 10;
                    sender.Send(MessageType.Timeout, "{0}: {1} ({2} minute timeout.)", user.Name, clearReason, duration);
                    sender.Timeout(user, duration * 60);
                    timeout.LastTimeout = now.AddMinutes(duration);
                    break;

                default:
                    Debug.Assert(timeout.Count > 0);
                    sender.Send(MessageType.Timeout, "{0}: {1} (8 hour timeout.)", user.Name, clearReason);
                    sender.Timeout(user, 8 * 60 * 60);
                    timeout.LastTimeout = now.AddHours(8);
                    break;
            }
        }
コード例 #6
0
ファイル: TimeoutController.cs プロジェクト: hasaki/WinterBot
        private void ClearChat(WinterBot sender, TwitchUser user, string clearReason, int minTimeout = 1)
        {
            bool         shouldMessage = !string.IsNullOrEmpty(clearReason);
            var          now           = DateTime.Now;
            TimeoutCount timeout;

            if (!m_timeouts.TryGetValue(user, out timeout))
            {
                timeout = m_timeouts[user] = new TimeoutCount(now);
            }
            else
            {
                shouldMessage &= (DateTime.Now > timeout.LastTimeout) && (DateTime.Now - timeout.LastTimeout).TotalMinutes > 60;
                timeout.Count  = GetEffectiveCount(timeout) + 1;
            }

            timeout.LastTimeout = now;
            if (!m_chatOptions.ShouldTimeout(user))
            {
                timeout.Count = 1;
            }

            if (minTimeout < 1)
            {
                minTimeout = 1;
            }

            int duration = 0;

            switch (timeout.Count)
            {
            case 1:
            case 2:
                duration = 1;
                break;

            case 3:
                shouldMessage = !string.IsNullOrEmpty(clearReason);
                duration      = 5 * 60;
                break;

            case 4:
                shouldMessage = !string.IsNullOrEmpty(clearReason);
                duration      = 10 * 60;
                break;

            case 5:
                shouldMessage = !string.IsNullOrEmpty(clearReason);
                duration      = 8 * 60 * 60;
                break;
            }

            if (duration < minTimeout)
            {
                duration = minTimeout;
            }

            if (shouldMessage)
            {
                if (duration == 1)
                {
                    sender.Send(MessageType.Timeout, Importance.Med, "{0}: {1} (This is not a timeout.)", user.Name, clearReason);
                }
                else if (duration < 60)
                {
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1}", user.Name, clearReason);
                }
                else if (duration < 3600)
                {
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1} ({2} minute timeout.)", user.Name, clearReason, duration / 60);
                }
                else
                {
                    sender.Send(MessageType.Timeout, Importance.High, "{0}: {1} ({2} hour timeout.)", user.Name, clearReason, duration / 3600);
                }
            }

            sender.Timeout(user, duration);
            timeout.LastTimeout = now.AddSeconds(duration);
        }