Esempio n. 1
0
        public static TCPOutPacket GetWaitingChatMsg(TCPOutPacketPool pool, int cmdID, int serverLineID)
        {
            List <string>  msgList  = new List <string>();
            Queue <string> msgQueue = ChatMsgManager.GetChatMsgQueue(serverLineID);

            lock (msgQueue)
            {
                while (msgQueue.Count > 0 && msgList.Count < 250)
                {
                    msgList.Add(msgQueue.Dequeue());
                }
            }
            return(DataHelper.ObjectToTCPOutPacket <List <string> >(msgList, pool, cmdID));
        }
Esempio n. 2
0
        public static void AddChatMsg(int serverLineID, string chatMsg)
        {
            LogManager.WriteLog(LogTypes.SQL, string.Format("AddChatMsg:LineID={0},Msg={1}", serverLineID, chatMsg), null, true);
            Queue <string> msgQueue = ChatMsgManager.GetChatMsgQueue(serverLineID);

            lock (msgQueue)
            {
                if (msgQueue.Count > 30000)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("线路{0}的转发消息太多,被丢弃,一共丢弃{1}条,请检查GameServer是否正常", serverLineID, msgQueue.Count), null, true);
                    List <string> cmdList = msgQueue.ToList <string>();
                    msgQueue.Clear();
                    Dictionary <string, int> cmdAnalysis = new Dictionary <string, int>();
                    foreach (string cmd in cmdList)
                    {
                        string szKey = string.Empty;
                        try
                        {
                            szKey = cmd.Split(new char[]
                            {
                                ':'
                            })[5].Split(new char[]
                            {
                                ' '
                            })[0];
                        }
                        catch
                        {
                        }
                        if (!string.IsNullOrEmpty(szKey))
                        {
                            if (cmdAnalysis.ContainsKey(szKey))
                            {
                                Dictionary <string, int> dictionary;
                                string key;
                                (dictionary = cmdAnalysis)[key = szKey] = dictionary[key] + 1;
                            }
                            else
                            {
                                cmdAnalysis[szKey] = 1;
                            }
                            if (szKey.StartsWith("-buyyueka") || szKey.StartsWith("-updateyb") || szKey.StartsWith("-updateBindgold") || szKey.StartsWith("-config"))
                            {
                                msgQueue.Enqueue(cmd);
                            }
                        }
                    }
                    if (msgQueue.Count <string>() >= 15000)
                    {
                        LogManager.WriteLog(LogTypes.Error, string.Format("线路{0}丢失重要命令{1}条", serverLineID, msgQueue.Count <string>()), null, true);
                        msgQueue.Clear();
                    }
                    List <KeyValuePair <string, int> > cmdAnaList = cmdAnalysis.ToList <KeyValuePair <string, int> >();
                    cmdAnaList.Sort((KeyValuePair <string, int> _left, KeyValuePair <string, int> _right) => _right.Value - _left.Value);
                    StringBuilder sb = new StringBuilder();
                    sb.Append("转发消息统计,").AppendFormat("共有{0}类消息:    ", cmdAnaList.Count <KeyValuePair <string, int> >()).AppendLine();
                    for (int i = 0; i < cmdAnaList.Count <KeyValuePair <string, int> >(); i++)
                    {
                        string _cmd = cmdAnaList[i].Key;
                        int    _cnt = cmdAnaList[i].Value;
                        if (_cnt <= 10)
                        {
                            break;
                        }
                        sb.AppendFormat("   cmd={0}, cnt={1}", _cmd, _cnt).AppendLine();
                    }
                    LogManager.WriteLog(LogTypes.Error, string.Format("线路{0}的转发消息太多,丢弃日志分析如下{1}", serverLineID, sb.ToString()), null, true);
                }
                msgQueue.Enqueue(chatMsg);
            }
        }