コード例 #1
0
        /// <summary>
        /// Refresh the properties table from the given message.
        /// </summary>
        /// <param name="message">The received message</param>
        internal void ReadFromMessage(IncomingMessage message)
        {
            var changedKeysCount = message.ReadByte();

            for (int i = 0; i < changedKeysCount; i++)
            {
                var key      = message.ReadByte();
                var newValue = new NetBuffer();
                newValue.Write(message.ReadBytes());

                var isNewProperty = !this.internalDictionary.ContainsKey(key);
                this.internalDictionary[key] = newValue;

                if (isNewProperty)
                {
                    this.PropertyAdded?.Invoke(this, key);
                }
                else
                {
                    this.PropertyChanged?.Invoke(this, key);
                }
            }

            var removedKeysCount = message.ReadByte();

            for (int i = 0; i < removedKeysCount; i++)
            {
                var key = message.ReadByte();

                NetBuffer value;
                this.internalDictionary.TryRemove(key, out value);

                this.PropertyRemoved?.Invoke(this, key);
            }
        }
コード例 #2
0
        /// <summary>
        /// Refresh this instance fields based on the given message.
        /// </summary>
        /// <param name="message">The received message</param>
        internal void ReadFromMessage(IncomingMessage message)
        {
            var changedFields = (RoomInfoFieldsFlags)message.ReadByte();

            if (changedFields.HasFlag(RoomInfoFieldsFlags.Name))
            {
                var roomName = message.ReadString();
                if (this.Name == null)
                {
                    this.Name = roomName;
                }
                else if (this.Name != roomName)
                {
                    throw new InvalidOperationException("Invalid incoming message");
                }
            }

            if (changedFields.HasFlag(RoomInfoFieldsFlags.PlayerCount))
            {
                this.playerCount = message.ReadByte();
            }

            if (changedFields.HasFlag(RoomInfoFieldsFlags.MaxPlayers))
            {
                this.maxPlayers = message.ReadByte();
            }

            if (changedFields.HasFlag(RoomInfoFieldsFlags.PropertiesListedInLobby))
            {
                this.PropertiesListedInLobby = new HashSet <string>(message.ReadStringArray());
            }
        }
コード例 #3
0
 /// <summary>
 /// Read this instance fields from an incoming message.
 /// </summary>
 /// <param name="incomingMessage">The incoming message</param>
 internal void Read(IncomingMessage incomingMessage)
 {
     this.RoomName   = incomingMessage.ReadString();
     this.IsVisible  = incomingMessage.ReadBoolean();
     this.MaxPlayers = incomingMessage.ReadByte();
     this.PropertiesListedInLobby = new HashSet <string>(incomingMessage.ReadStringArray());
 }
コード例 #4
0
        /// <summary>
        /// Refresh the player fields based on the given message.
        /// </summary>
        /// <param name="message">The received message</param>
        internal void ReadFromMessage(IncomingMessage message)
        {
            var changedFields = (RoomFieldsFlags)message.ReadByte();

            if (changedFields.HasFlag(RoomFieldsFlags.IsVisible))
            {
                this.IsVisible = message.ReadBoolean();
            }

            if (changedFields.HasFlag(RoomFieldsFlags.MaxPlayers))
            {
                this.MaxPlayers = message.ReadByte();
            }

            if (changedFields.HasFlag(RoomFieldsFlags.CustomProperties))
            {
                this.CustomProperties.ReadFromMessage(message);
            }

            this.OnChange(changedFields);
        }
コード例 #5
0
        /// <summary>
        /// Refresh the player fields based on the given message.
        /// </summary>
        /// <param name="message">The received message</param>
        internal void ReadFromMessage(IncomingMessage message)
        {
            var changedFields = (PlayerFliedsFlags)message.ReadByte();

            if (changedFields.HasFlag(PlayerFliedsFlags.Nickname))
            {
                this.Nickname = message.ReadString();

                this.OnNicknameChanged?.Invoke(this, EventArgs.Empty);
            }

            if (changedFields.HasFlag(PlayerFliedsFlags.CustomProperties))
            {
                this.CustomProperties.ReadFromMessage(message);

                this.OnCustomPropertiesChanged?.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #6
0
        public void OutgoingAndIncoming_Byte()
        {
            byte[]          data            = new byte[256];
            OutgoingMessage outgoingMessage = new OutgoingMessage(data);

            Assert.AreEqual(0, outgoingMessage.Length);
            for (int value = byte.MinValue; value <= byte.MaxValue; value++)
            {
                outgoingMessage.Write((byte)value);
            }
            Assert.AreEqual(data.Length, outgoingMessage.Length);
            IncomingMessage incomingMessage = new IncomingMessage(data);

            for (int value = byte.MinValue; value < byte.MaxValue; value++)
            {
                Assert.AreEqual((byte)value, incomingMessage.ReadByte());
            }
        }
コード例 #7
0
        public void Handle(ClientSession session, IncomingMessage message)
        {
            MultiplayerMatch match = session.MultiplayerMatchSession?.Match;

            if (match != null)
            {
                MatchPlayer matchPlayer = session.MultiplayerMatchSession.MatchPlayer;

                UpdateStatus status = (UpdateStatus)message.ReadUInt();
                if (status.HasFlag(UpdateStatus.X))
                {
                    matchPlayer.X = message.ReadDouble();
                }

                if (status.HasFlag(UpdateStatus.Y))
                {
                    matchPlayer.Y = message.ReadDouble();
                }

                if (status.HasFlag(UpdateStatus.VelX))
                {
                    matchPlayer.VelX = message.ReadFloat();
                }

                if (status.HasFlag(UpdateStatus.VelY))
                {
                    matchPlayer.VelY = message.ReadFloat();
                }

                if (status.HasFlag(UpdateStatus.ScaleX))
                {
                    matchPlayer.ScaleX = message.ReadByte();
                }

                if (status.HasFlag(UpdateStatus.Space))
                {
                    matchPlayer.Space = message.ReadBool();
                }

                if (status.HasFlag(UpdateStatus.Left))
                {
                    matchPlayer.Left = message.ReadBool();
                }

                if (status.HasFlag(UpdateStatus.Right))
                {
                    matchPlayer.Right = message.ReadBool();
                }

                if (status.HasFlag(UpdateStatus.Down))
                {
                    matchPlayer.Down = message.ReadBool();
                }

                if (status.HasFlag(UpdateStatus.Up))
                {
                    matchPlayer.Up = message.ReadBool();
                }

                if (status.HasFlag(UpdateStatus.Speed))
                {
                    matchPlayer.Speed = message.ReadInt();
                }

                if (status.HasFlag(UpdateStatus.Accel))
                {
                    matchPlayer.Accel = message.ReadInt();
                }

                if (status.HasFlag(UpdateStatus.Jump))
                {
                    matchPlayer.Jump = message.ReadInt();
                }

                if (status.HasFlag(UpdateStatus.Rot))
                {
                    matchPlayer.Rot = message.ReadInt();
                }

                if (status.HasFlag(UpdateStatus.Item))
                {
                    matchPlayer.Item = message.ReadString();
                }

                if (status.HasFlag(UpdateStatus.Life))
                {
                    matchPlayer.Life = message.ReadUInt();
                }

                if (status.HasFlag(UpdateStatus.Hurt))
                {
                    matchPlayer.Hurt = message.ReadBool();
                }

                if (status.HasFlag(UpdateStatus.Coins))
                {
                    matchPlayer.Coins = message.ReadUInt();
                }

                match.SendUpdateIfRequired(session, matchPlayer);
            }
        }