private bool RunCommand(string message, out string notice)
        {
            string username = AccountSession.AccountName;
            bool   ret      = false;

            notice = null;

            if (ADMINS.Contains(username))
            {
                string[] pars = message.Split(' ');
                if (pars.Length > 1)
                {
                    string cmd  = pars[0];
                    string par  = pars[1];
                    string args = "";
                    if (pars.Length > 2)
                    {
                        for (int i = 2; i < pars.Length; i++)
                        {
                            args += pars[i] + " ";
                        }
                    }

                    if (cmd.Equals("/banuser"))
                    {
                        string reason = "Tài khoản {0} bị treo nick, lí do: tuyên truyền website hack";
                        if (!string.IsNullOrEmpty(args))
                        {
                            reason = args;
                        }

                        ret    = ChatFilter.BanUser(par);
                        notice = string.Format(reason, par);
                    }
                    else if (cmd.Equals("/addbadlink"))
                    {
                        ret = ChatFilter.AddBadLink(par);
                    }
                    else if (cmd.Equals("/addbadword"))
                    {
                        if (pars.Length > 2)
                        {
                            for (int i = 2; i < pars.Length; i++)
                            {
                                par += " " + pars[i];
                            }
                        }
                        ret = ChatFilter.AddBadWord(par);
                    }
                    else if (cmd.Equals("/message"))
                    {
                        notice = par + " " + args;
                        ret    = true;
                    }
                }
            }
            return(ret);
        }
        /// <summary>
        /// Gửi message chat
        /// </summary>
        /// <param name="hubCallerContext"></param>
        /// <param name="message"></param>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public bool SendMessage(HubCallerContext hubCallerContext, string message, string channelId)
        {
            NLogManager.LogMessage(">>Start SendMessage");
            try
            {
                if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["CloseChatServer"].ToString()))
                {
                    return(false);
                }

                if (MAX_MESSAGE_LENGTH < message.Length)
                {
                    broadcastMessage(hubCallerContext.ConnectionId, string.Format("Nội dung chát không quá {0} kí tự!", MAX_MESSAGE_LENGTH));
                    return(false);
                }

                //NLogManager.LogMessage(string.Format(">>Statr chat:{0}", channelId));
                LoadListAdmin();
                LoadTimeSendMessage();
                long accountId = GetAccountId(hubCallerContext);
                if (accountId < 1)
                {
                    NLogManager.LogMessage(string.Format("Sending message: not authenticated accountId: {0} - channel: {1} - content={2}", accountId, channelId, message));
                    return(false);
                }
                ChatChannel chatChannel = GetChannel(channelId);
                if (chatChannel == null)
                {
                    NLogManager.LogMessage(string.Format("Sending message: accountId: {0} - not has channel: {1} - content={2}", accountId, channelId, message));
                    return(false);
                }
                if (message.IndexOf('/') == 0)
                {
                    string notice;
                    bool   ret = RunCommand(message, out notice);

                    if (!string.IsNullOrEmpty(notice))
                    {
                        Instance.ClientSystemMessage(channelId, notice, 0);
                    }

                    if (ret)
                    {
                        NLogManager.LogMessage(string.Format("Account: {0} - run command: {1}", accountId, message));
                        return(true);
                    }
                }
                ChatUser chatUser = GetUser(accountId);
                if (chatUser == null)
                {
                    NLogManager.LogMessage(string.Format("Sending message: not chat user: {0} in channel={1} - content={2}", accountId, channelId, message));
                    return(false);
                }
                if (CMSAllGame != "1")
                {
                    if (!ADMINS.Contains(chatUser.UserName))
                    {
                        try
                        {
                            object level = CacheHandler.Get(chatUser.UserName + "_" + channelId);
                            if (level == null)
                            {
                                SetCacheLevel(chatUser.UserName, (int)chatUser.AccountID, channelId);
                            }
                            else if (int.Parse(level.ToString()) == 0)
                            {
                                NLogManager.LogMessage(string.Format("Tổng đặt trong 7 ngày của bạn chưa đủ 2.000.000 Sao để tham gia chat!: {0} ", chatUser.UserName));
                                broadcastMessage(hubCallerContext.ConnectionId, string.Format("Tổng đặt trong 7 ngày của bạn chưa đủ 2.000.000 Sao để tham gia chat!"));
                                return(false);
                            }
                        }
                        catch (Exception ex)
                        {
                            NLogManager.LogMessage(string.Format("{0} Null Cache level", chatUser.UserName));
                            SetCacheLevel(chatUser.UserName, (int)chatUser.AccountID, channelId);
                        }
                    }
                }

                string filteredMessage     = message;
                string tempFilteredMessage = message;
                bool   flag = false;

                //WaitCallback callBack = new WaitCallback(InsertChat);
                //var chatchat = new Insert_Chat();
                //chatchat.AccountID = int.Parse(chatUser.AccountID.ToString());
                //chatchat.UserName = string.Format("{0}({1})", chatUser.UserName, chatUser.NickName);
                //chatchat.channelId = channelId;
                //chatchat.filteredMessage = filteredMessage;
                //ThreadPool.QueueUserWorkItem(callBack, chatchat);

                //khong phai admin thi loc bad link
                if (!ADMINS.Contains(chatUser.UserName))
                {
                    ChatFilter.RemoveBadLinks(tempFilteredMessage, out flag);
                }
                //Check thời gian chát theo quy định

                if (!ADMINS.Contains(chatUser.UserName))
                {
                    try
                    {
                        object value = CacheHandler.Get(chatUser.UserName);
                        if (value == null)
                        {
                            CacheHandler.Add(chatUser.UserName, DateTime.Now.ToString());
                        }
                        else
                        {
                            if (DateTime.Now != DateTime.Parse(value.ToString()))
                            {
                                var lastTime = (DateTime.Now - DateTime.Parse(value.ToString())).TotalSeconds;
                                var a        = MIN_MESSAGE_TIME_SECOND;
                                if (lastTime < int.Parse(MIN_MESSAGE_TIME_SECOND))
                                {
                                    broadcastMessage(hubCallerContext.ConnectionId, string.Format("Chưa hết thời gian chờ {0}s, t/g chờ còn {1}s", MIN_MESSAGE_TIME_SECOND, System.Math.Round((int.Parse(MIN_MESSAGE_TIME_SECOND) - lastTime), 2)));
                                    return(false);
                                }
                            }
                            CacheHandler.Add(chatUser.UserName, DateTime.Now.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        NLogManager.LogMessage(string.Format("{0} Null Cache TimeChat", chatUser.UserName));
                        CacheHandler.Add(chatUser.UserName, DateTime.Now.ToString());
                    }
                }



                if (CheckBanUsers(chatUser.UserName))
                {
                    NLogManager.LogMessage(string.Format(">> {0} - Tài khoản đang bị Block! ", chatUser.UserName));
                    broadcastMessage(hubCallerContext.ConnectionId, ReturnCheckBanUsers(chatUser.UserName));
                    return(false);
                }

                //nếu nội dung chat có bad links thì block gói tin và ghi log
                if (flag)
                {
                    chatUser.CountBadLinks += 1;
                    filteredMessage         = "***";
                    if (chatUser.CountBadLinks > 5)
                    {
                        ChatFilter.BanUser(chatUser.UserName);
                    }

                    NLogManager.LogMessage(string.Format("User sent bad link: accountId={0}, username={1} - channelId={2} - content={3} - \n\rAgent: {4}", chatUser.AccountID, chatUser.UserName, channelId, message, chatUser.UserAgent));
                }
                else
                {
                    //khong phai admin thi loc bad word
                    if (!ADMINS.Contains(chatUser.UserName))
                    {
                        filteredMessage = ChatFilter.RemoveBadWords(message, out flag);
                    }

                    NLogManager.LogMessage(flag
                        ? string.Format(
                                               "User sent bad word: accountId={0}, username={1} - channelId={2} - content={3}",
                                               chatUser.AccountID, chatUser.UserName, channelId, message)
                        : string.Format("User sent message: accountId={0}, username={1} - channelId={2} - content={3}",
                                        chatUser.AccountID, chatUser.UserName, channelId, message));
                }

                //khong phai admin thi loc bad word
                if (!ADMINS.Contains(chatUser.UserName))
                {
                    filteredMessage = RemoveBadWords(message, out flag);
                }

                //Thay thế từ khóa
                if (!ADMINS.Contains(chatUser.UserName))
                {
                    filteredMessage = ReplaceKeyword(filteredMessage);
                }


                //admin thì text chat màu đỏ
                ChatMessage chatMessage = new ChatMessage(channelId, chatUser.AccountID, !ADMINS.Contains(chatUser.UserName) ? chatUser.NickName : string.Format("<span style='color:red; font-weight:bold'>ADMIN ({0})</span>", chatUser.NickName), !ADMINS.Contains(chatUser.UserName) ? filteredMessage : string.Format("{0}", filteredMessage));
                bool        canSend;
                if (!ADMINS.Contains(chatUser.UserName))
                {
                    canSend = chatChannel.AddMessage(chatMessage);
                }
                else
                {
                    canSend = chatChannel.AddMessageAdmin(chatMessage);
                }

                if (canSend)
                {
                    canSend = chatUser.AddMessage(channelId, chatMessage);
                }

                if (canSend)
                {
                    ClientReceiveMessage(chatMessage);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            NLogManager.LogMessage(string.Format(">>Gửi tin nhắn không thành công! "));
            return(false);
        }