示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SetPropertiesRequest"/> class.
        /// </summary>
        /// <param name="protocol">
        /// The protocol.
        /// </param>
        /// <param name="operationRequest">
        /// Operation request containing the operation parameters.
        /// </param>
        public SetPropertiesRequest(IRpcProtocol protocol, OperationRequest operationRequest)
            : base(protocol, operationRequest)
        {
            if (!this.IsValid)
            {
                return;
            }

            // special handling for game and actor properties send by AS3/Flash (Amf3 protocol) or JSON clients
            if (protocol.ProtocolType == ProtocolType.Amf3V16 || protocol.ProtocolType == ProtocolType.Json)
            {
                if (this.UpdatingGameProperties)
                {
                    Utilities.ConvertAs3WellKnownPropertyKeys(this.Properties, null);
                    Utilities.ConvertAs3WellKnownPropertyKeys(this.ExpectedValues, null);
                }
                else
                {
                    Utilities.ConvertAs3WellKnownPropertyKeys(null, this.Properties);
                    Utilities.ConvertAs3WellKnownPropertyKeys(null, this.ExpectedValues);
                }
            }

            if (this.UpdatingGameProperties)
            {
                this.isValid = GameParameterReader.TryGetProperties(this.Properties, out this.newMaxPlayer,
                                                                    out this.newIsOpen, out this.newIsVisible,
                                                                    out this.newLobbyProperties, out this.MasterClientId,
                                                                    out this.ExpectedUsers, out this.errorMessage);
            }
        }
示例#2
0
        public void SetupRequest()
        {
            //TBD - set GameProperties to new Hashtable() instead of checking for null everywhere?
            this.properties = this.GameProperties ?? new Hashtable();

            if (this.properties != null && this.properties.Count > 0)
            {
                string[] expectedUsers;
                this.isValid = GameParameterReader.TryGetProperties(
                    this.properties,
                    out this.newMaxPlayer,
                    out this.newIsOpen,
                    out this.newIsVisible,
                    out this.newLobbyProperties,
                    out expectedUsers,
                    out this.errorMessage);
            }

            if (this.IsValid && this.AddUsers != null)
            {
                if (this.newMaxPlayer.HasValue && this.newMaxPlayer != 0 && this.AddUsers.Length >= this.newMaxPlayer)
                {
                    this.isValid      = false;
                    this.errorMessage = "Reserved slots count is more then max player value";
                    return;
                }

                if (this.AddUsers.Any(string.IsNullOrEmpty))
                {
                    this.isValid      = false;
                    this.errorMessage = "slot name can not be empty";
                    return;
                }
            }
        }
示例#3
0
        public bool TrySetProperties(Hashtable gameProperties, out bool changed, out string debugMessage)
        {
            changed = false;

            byte?maxPlayer;
            bool?isOpen;
            bool?isVisible;

            object[] propertyFilter;
            string[] expectedUsers;

            if (!GameParameterReader.TryGetProperties(gameProperties, out maxPlayer, out isOpen,
                                                      out isVisible, out propertyFilter, out expectedUsers, out debugMessage))
            {
                return(false);
            }

            if (maxPlayer.HasValue && maxPlayer.Value != this.MaxPlayer)
            {
                this.MaxPlayer = maxPlayer.Value;
                this.properties[(byte)GameParameter.MaxPlayers] = (byte)this.MaxPlayer;
                changed = true;
            }

            if (isOpen.HasValue && isOpen.Value != this.IsOpen)
            {
                this.IsOpen = isOpen.Value;
                this.properties[(byte)GameParameter.IsOpen] = this.MaxPlayer;
                changed = true;
            }

            if (isVisible.HasValue && isVisible.Value != this.IsVisible)
            {
                this.IsVisible = isVisible.Value;
                changed        = true;
            }

            this.properties.Clear();
            foreach (DictionaryEntry entry in gameProperties)
            {
                if (entry.Value != null)
                {
                    this.properties[entry.Key] = entry.Value;
                }
            }

            debugMessage    = string.Empty;
            this.IsJoinable = this.CheckIsGameJoinable();
            return(true);
        }
示例#4
0
        public SetPropertiesRequest(int actorNr, Hashtable properties, Hashtable expected, bool broadcast)
        {
            this.ActorNumber    = actorNr;
            this.Properties     = properties;
            this.ExpectedValues = expected;
            this.Broadcast      = broadcast;

            if (this.UpdatingGameProperties)
            {
                this.isValid = GameParameterReader.TryGetProperties(this.Properties, out this.newMaxPlayer,
                                                                    out this.newIsOpen, out this.newIsVisible, out this.newLobbyProperties,
                                                                    out this.MasterClientId, out this.ExpectedUsers, out this.errorMessage);
            }
        }
示例#5
0
        private static bool TryParseDefaultProperties(
            LitePeer peer, Operation operation, Hashtable propertyTable, SendParameters sendParameters, out byte?maxPlayer, out bool?isOpen, out bool?isVisible, out object[] properties)
        {
            string debugMessage;

            if (!GameParameterReader.TryReadDefaultParameter(propertyTable, out maxPlayer, out isOpen, out isVisible, out properties, out debugMessage))
            {
                var response = new OperationResponse {
                    OperationCode = operation.OperationRequest.OperationCode, ReturnCode = (short)ErrorCode.OperationInvalid, DebugMessage = debugMessage
                };
                peer.SendOperationResponse(response, sendParameters);
                return(false);
            }

            return(true);
        }
        public void TryReadByteTest2()
        {
            var hash = new Hashtable();

            byte?  res;
            object rawValue;

            hash.Add((byte)GameParameter.MaxPlayers, (byte)123);

            Assert.That(GameParameterReader.TryReadByteParameter(hash, GameParameter.MaxPlayers, out res, out rawValue), Is.True);
            Assert.That(res, Is.Not.Null.And.EqualTo(123));
            Assert.That(rawValue, Is.Not.Null.And.EqualTo(123));

            hash.Clear();
            hash.Add((byte)GameParameter.MaxPlayers, 1234);

            Assert.That(GameParameterReader.TryReadByteParameter(hash, GameParameter.MaxPlayers, out res, out rawValue), Is.True);
            unchecked
            {
                Assert.That(res, Is.Not.Null.And.EqualTo((byte)1234));
                Assert.That(rawValue, Is.Not.Null.And.EqualTo(1234));
            }
            hash.Clear();
            double doubleValue = 1234.5;

            hash.Add((byte)GameParameter.MaxPlayers, doubleValue);

            Assert.That(GameParameterReader.TryReadByteParameter(hash, GameParameter.MaxPlayers, out res, out rawValue), Is.True);
            unchecked
            {
                Assert.That(res, Is.Not.Null.And.EqualTo((byte)doubleValue));
                Assert.That(rawValue, Is.Not.Null.And.EqualTo(doubleValue));
            }

            hash.Clear();
            hash.Add((byte)GameParameter.MaxPlayers, "zzz");

            Assert.That(GameParameterReader.TryReadByteParameter(hash, GameParameter.MaxPlayers, out res, out rawValue), Is.False);
        }
示例#7
0
        public Dictionary <string, object> GetCreateGameSettings(HiveGame game)
        {
            var settings = new Dictionary <string, object>();

            // set default properties
            if (newMaxPlayer.HasValue && newMaxPlayer.Value != game.MaxPlayers)
            {
                settings[HiveHostGameState.MaxPlayers.ToString()] = newMaxPlayer.Value;
            }

            if (newIsOpen.HasValue && newIsOpen.Value != game.IsOpen)
            {
                settings[HiveHostGameState.IsOpen.ToString()] = newIsOpen.Value;
            }

            if (newIsVisible.HasValue && newIsVisible.Value != game.IsVisible)
            {
                settings[HiveHostGameState.IsVisible.ToString()] = newIsVisible.Value;
            }

            settings[HiveHostGameState.LobbyId.ToString()]   = this.LobbyName;
            settings[HiveHostGameState.LobbyType.ToString()] = this.LobbyType;

            if (newLobbyProperties != null)
            {
                settings[HiveHostGameState.CustomProperties.ToString()] =
                    GameParameterReader.GetLobbyGameProperties(this.GameProperties, new HashSet <object>(newLobbyProperties));
            }

            settings[HiveHostGameState.EmptyRoomTTL.ToString()]       = this.EmptyRoomLiveTime;
            settings[HiveHostGameState.PlayerTTL.ToString()]          = this.PlayerTTL;
            settings[HiveHostGameState.CheckUserOnJoin.ToString()]    = this.CheckUserOnJoin;
            settings[HiveHostGameState.DeleteCacheOnLeave.ToString()] = this.DeleteCacheOnLeave;
            settings[HiveHostGameState.SuppressRoomEvents.ToString()] = this.SuppressRoomEvents;

            return(settings);
        }
        public void TryReadByteTest()
        {
            var hash = new Hashtable();

            byte?  res;
            object rawValue;

            Assert.That(GameParameterReader.TryReadByteParameter(hash, GameParameter.MaxPlayers, out res, out rawValue), Is.True);
            Assert.That(res, Is.Null);
            Assert.That(rawValue, Is.Null);

            hash.Add((byte)GameParameter.MaxPlayers, 123);

            Assert.That(GameParameterReader.TryReadByteParameter(hash, GameParameter.MaxPlayers, out res, out rawValue), Is.True);
            Assert.That(res, Is.Not.Null.And.EqualTo(123));
            Assert.That(rawValue, Is.Not.Null.And.EqualTo(123));

            hash.Clear();
            hash.Add((int)GameParameter.MaxPlayers, 123);

            Assert.That(GameParameterReader.TryReadByteParameter(hash, GameParameter.MaxPlayers, out res, out rawValue), Is.True);
            Assert.That(res, Is.Not.Null.And.EqualTo(123));
            Assert.That(rawValue, Is.Not.Null.And.EqualTo(123));
        }
        public void TryReadBooleanTest()
        {
            var hash = new Hashtable();

            bool?  res;
            object rawValue;

            Assert.That(GameParameterReader.TryReadBooleanParameter(hash, GameParameter.IsOpen, out res, out rawValue), Is.True);
            Assert.That(res, Is.Null);
            Assert.That(rawValue, Is.Null);

            hash.Add((byte)GameParameter.IsOpen, true);

            Assert.That(GameParameterReader.TryReadBooleanParameter(hash, GameParameter.IsOpen, out res, out rawValue), Is.True);
            Assert.That(res, Is.True);
            Assert.That(rawValue, Is.Not.Null.And.True);

            hash.Clear();
            hash.Add((int)GameParameter.IsOpen, false);

            Assert.That(GameParameterReader.TryReadBooleanParameter(hash, GameParameter.IsOpen, out res, out rawValue), Is.True);
            Assert.That(res, Is.False);
            Assert.That(rawValue, Is.Not.Null.And.False);
        }