예제 #1
0
        private void Parse(byte[] data)
        {
            if (data.Length < 2)
            {
                return;
            }
            OctetsStream stream = new OctetsStream(data);
            uint         Opcode = stream.ReadCUInt();

            if (Enum.IsDefined(typeof(LogType), Opcode))
            {
                stream.ReadCUInt();
                try
                {
                    LogItem item   = new LogItem(stream.ReadInt32(), stream.ReadString(OctetsString.GBK), stream.ReadString(OctetsString.GBK), stream.ReadString(OctetsString.GBK), Opcode);
                    bool    IsChat = Utils.IsChat(item.Msg);
                    if (IsChat)
                    {
                        manager[Services.Chat]?.ProcessChat(item);
                    }
                    Services service = Utils.Cast(item.Servicename);
                    if (manager.ContainsKey(service))
                    {
                        ThreadPool.QueueUserWorkItem(manager[service].Process, item);
                    }
                    else
                    {
                        Program.Logger.Write($"Unknown service {item.Servicename}");
                    }
                    if (IsChat)
                    {
                        plugins.Where(x => x.ReqServices.HasFlag(Services.Chat) || x.ReqServices == Services.All).ToList().ForEach(x =>
                        {
                            try
                            {
                                x.Execute(item);
                            }
                            catch (Exception e)
                            {
                                Program.Logger.Write($"Plugin {x.Name} execute return error: {e.Message} | {e.StackTrace}");
                            }
                        });
                    }
                    else
                    {
                        plugins.Where(x => x.ReqServices.HasFlag(service) || x.ReqServices == Services.All).ToList().ForEach(x =>
                        {
                            try
                            {
                                x.Execute(item);
                            }
                            catch (Exception e)
                            {
                                Program.Logger.Write($"Plugin {x.Name} execute return error: {e.Message} | {e.StackTrace}");
                            }
                        });
                    }
                }
                catch (Exception e)
                {
                    Program.Logger.Write($"Error while reading message with opcode: {Opcode}, error: {e.Message} | {e.StackTrace}");
                }
            }
            else
            {
                Program.Logger.Write($"Error, unknown opcode {Opcode}");
            }
        }