public void HandlePacket(PacketObject p) { if (p == null) { return; } var handlers = m_callBacks.Get(p._ID); if (handlers == null || handlers.Count < 1 || (!connected && !FightRecordManager.IsRecovering)) // if we lost connection while processing packets, just destroy packets { p.Destroy(); return; } foreach (var h in handlers) { h.Invoke(p); } if (!p.dontDestroyOnRecv) { p.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(); } }
public void OnDestroy() { cache.Destroy(); }