Example #1
0
        internal void OnNetworkStream(Network.ByteInStream stream)
        {
#if !DEBUG
            try
            {
#endif
            while (stream.Stream.CanRead)
            {
                byte           handlerId = stream.ReadByte();
                IPacketHandler handler   = packetHandlers[handlerId];

                if (handler == null)
                {
                    log.Error("No packet handler for id #{0} found, can't process byte stream", handlerId);
                    return;
                }

                if (!handler.OnPacket(handlerId, this, stream))
                {
                    log.Error("Handler '{0}' failed processing byte stream", handler.GetType().GetPrettyName());
                    return;
                }
            }
#if !DEBUG
        }

        catch (Exception exn)
        {
            log.Error(exn);
        }
#endif
        }
Example #2
0
        public void Unpack(Network.ByteInStream stream)
        {
            if (compressPosition)
            {
                position = new Vector3(
                    HalfUtilities.Unpack(stream.ReadUShort()),
                    HalfUtilities.Unpack(stream.ReadUShort()),
                    HalfUtilities.Unpack(stream.ReadUShort())
                    );
            }
            else
            {
                position = stream.ReadVector3();
            }

            if (yawOnly)
            {
                yaw      = stream.ReadByte() * 1.40625f;
                rotation = Quaternion.RotationAxis(Vector3.Up, yaw * SlimMath.Single.Deg2Rad);
            }
            else
            {
                rotation = Quaternion.RotationAxis(
                    new Vector3(
                        HalfUtilities.Unpack(stream.ReadUShort()),
                        HalfUtilities.Unpack(stream.ReadUShort()),
                        HalfUtilities.Unpack(stream.ReadUShort())
                        ),
                    (stream.ReadByte() * 1.40625f * SlimMath.Single.Deg2Rad)
                    );
            }

            buffer.Push(Actor.Context.Time.GameTime,
                        new State {
                Position = position, Rotation = rotation
            }
                        );
        }
Example #3
0
 public override void Unpack(SlimNet.Network.ByteInStream stream)
 {
     State = stream.ReadByte();
 }