private void HandleInboundData(IBuffer buffer, IConnection connection) { if (buffer == default(IBuffer)) { return; } if (buffer.Length < 1) { return; } if (PreProcessHandler != null) { if (!PreProcessHandler.Invoke(connection, buffer.Length)) { return; } } // Incorporate Ceras var data = buffer.ToBytes(); // Get Packet From Data using MessagePack var packet = (IPacket)MessagePacker.Instance.Deserialize(data); if (packet != null) { if (Handler != null) { // Pass packet to handler. Handler(connection, packet); } else { Log.Error("Handler == null, this shouldn't happen! Tell JC"); Disconnect(connection, NetworkStatus.Unknown.ToString()); } } else { Disconnect(connection, NetworkStatus.VersionMismatch.ToString()); } }
private void HandleInboundData(IBuffer buffer, IConnection connection) { if (buffer == default(IBuffer)) { return; } if (buffer.Length < 1) { return; } if (PreProcessHandler != null) { if (!PreProcessHandler.Invoke(connection, buffer.Length)) { return; } } //Incorperate Ceras var data = buffer.ToBytes(); //Get Packet From Data using Ceras var sw = new Stopwatch(); sw.Start(); var packet = (IPacket)connection.Ceras.Deserialize(data); if (sw.ElapsedMilliseconds > 10) { Debug.WriteLine( "Took " + sw.ElapsedMilliseconds + "ms to deserialize packet: " + packet.GetType().Name ); } //Handle any packet identification errors //Pass packet to handler. Handler.Invoke(connection, packet); }