public void Log(PacketObject rLog, int rFrame, StackTrace rStack) { if (writer == null) { return; } var field = rLog.GetType().GetField("frame"); field?.SetValue(rLog, (ushort)rFrame); var c = Command.Create(); c.Init(rLog, rFrame); c.Serialize(writer); c.Destroy(); if (rStack != null) { var l = PacketObject.Create <LogStack>(); var list = new List <LogMethod>(); for (var i = 0; i < rStack.FrameCount; i++) { var m = PacketObject.Create <LogMethod>(); var methodInfo = rStack.GetFrame(i)?.GetMethod(); var t = methodInfo?.DeclaringType; if (t != null) { if (t.GetInterface("IGameRecordData") != null || t == typeof(Session)) { continue; } m.typeHash = t.Name.GetHashCode(); MethodInfo[] arr = null; if (!typeMethodInfos.TryGetValue(t, out arr)) { arr = t.GetMethods(); typeMethodInfos.Add(t, arr); } m.methodIndex = (ushort)Array.FindIndex(arr, item => item == methodInfo); } list.Add(m); } l.method = list.ToArray(); var com = Command.Create(); com.Init(l, rFrame); com.Serialize(writer); com.Destroy(); } }
public virtual void Send(PacketObject packet) { if (connected && packet != null && !packet.destroyed) { #if UNITY_EDITOR if (LocalServer.instance.AutoHandlePacket(packet.GetType(), this)) { return; } #endif var p = packet.BuildPacket(); #if DEVELOPMENT_BUILD || UNITY_EDITOR var f = ConfigManager.Get <ProtocolLoggerFilter>(packet._ID); if (!f || !f.disabled) { if (!f || !f.noDetail) { try { Logger.Log(LogType.SEND, "Send: [{0}:{1}-{2},{3}] {4}", p.ID, p.dataSize, Level.realTime, packet._name, LitJson.JsonMapper.ToJson(packet, true, 5, true)); } catch (Exception e) { Logger.Log(LogType.SEND, "Send: [{0}:{1}-{2},{3}]", p.ID, p.dataSize, Level.realTime, packet._name); Logger.LogException(e); } } else { Logger.Log(LogType.SEND, "Send: [{0}:{1}-{2},{3}]", p.ID, p.dataSize, Level.realTime, packet._name); } if (f && f.cpp) { packet.LogCppString(); } } #endif m_sender.Send(p); } if (!packet.dontDestroyOnSend) { packet.Destroy(); } }