Esempio n. 1
0
        /// <summary>
        /// Reads a <c>UpdatePosition</c> type PositionUpdate message.
        /// </summary>
        /// <param name="buffer">The byte array containing data.</param>
        /// <param name="length">The length of the message.</param>
        /// <returns>The PositionUpdate.</returns>
        public static PositionUpdate ReadUpdatePosition(byte[] buffer, int length)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (buffer.Length < length)
            {
                throw new ArgumentOutOfRangeException("buffer", buffer, "The buffer is not long enough to contain a message of the specified length.");
            }

            if (length < 16)
            {
                return(null);
            }

            float   x          = MessageProcessor.ReadSingle(buffer, 0);
            float   y          = MessageProcessor.ReadSingle(buffer, 4);
            Vector2 coordinate = new Vector2(x, y);
            float   rotation   = MessageProcessor.ReadSingle(buffer, 8);
            int     id         = MessageProcessor.ReadInt32(buffer, 12);

            PositionUpdate update = new PositionUpdate(UpdateType.UpdatePosition, coordinate, rotation, id);

            if (id > 200 || id < 0)
            {
                throw new ArgumentOutOfRangeException("Received message is not sane: " + update);
            }

            return(update);
        }
Esempio n. 2
0
        /// <summary>
        ///   Determines whether the specified <see cref="System.Object"/> is equal to the
        ///   current <see cref="Network.PositionUpdate"/>.
        /// </summary>
        /// <param name="obj">
        ///   The <see cref="System.Object"/> to compare with the current
        ///   <see cref="Network.PositionUpdate"/>.
        /// </param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object"/> is equal to the current
        ///   <see cref="Network.PositionUpdate"/>; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType() != this.GetType())
            {
                return(false);
            }

            PositionUpdate that = obj as PositionUpdate;

            return(this.Type == that.Type &&
                   this.Coordinate.x == that.Coordinate.x &&
                   this.Coordinate.y == that.Coordinate.y &&
                   this.Id == that.Id);
        }