public void RoomFlags_DeleteNullPropsWrongCASTest()
        {
            UnifiedTestClient masterClient1 = null;
            UnifiedTestClient masterClient2 = null;

            try
            {
                // create game on the game server
                string roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                var gameProperties = new Hashtable();
                gameProperties["P1"] = 1;
                gameProperties["P2"] = 2;
                gameProperties["L1"] = 1;
                gameProperties["L2"] = 2;
                gameProperties["L3"] = 3;

                var createGameRequest = new CreateGameRequest
                {
                    GameId         = roomName,
                    RoomFlags      = RoomOptionFlags.DeleteNullProps,
                    GameProperties = gameProperties,
                };

                masterClient1 = this.CreateMasterClientAndAuthenticate(Player1);
                var cgResponse = masterClient1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(masterClient1, cgResponse.Address);

                masterClient1.CreateGame(createGameRequest);

                masterClient1.SendRequest(new OperationRequest()
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { (byte)ParameterKey.Properties, new Hashtable {
                              { "P1", null }
                          } },
                        { (byte)ParameterKey.ExpectedValues, new Hashtable {
                              { "P1", 12 }
                          } },
                    }
                });

                masterClient2 = this.CreateMasterClientAndAuthenticate(Player2);

                var joinRequest = new JoinGameRequest()
                {
                    GameId = roomName,
                };

                var jgResponse = masterClient2.JoinGame(joinRequest, ErrorCode.Ok);

                this.ConnectAndAuthenticate(masterClient2, jgResponse.Address);

                jgResponse = masterClient2.JoinGame(joinRequest);

                Assert.That(jgResponse.GameProperties.Contains("P1"), Is.True);

                masterClient1.SendRequest(new OperationRequest()
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { (byte)ParameterKey.Properties, new Hashtable {
                              { "P2", null }
                          } },
                        { (byte)ParameterKey.ExpectedValues, new Hashtable {
                              { "P2", 23 }
                          } },
                    }
                });

                masterClient2.CheckThereIsNoEvent(EventCode.PropertiesChanged, this.WaitTimeout);
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
            }
        }
        public void RoomFlags_BroadcastOnChange([Values("ToAll", "ToOthers")] string policy)
        {
            UnifiedTestClient masterClient1 = null;
            UnifiedTestClient masterClient2 = null;

            try
            {
                // create game on the game server
                string roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                var gameProperties = new Hashtable();
                gameProperties["P1"] = 1;
                gameProperties["P2"] = 2;
                gameProperties["L1"] = 1;
                gameProperties["L2"] = 2;
                gameProperties["L3"] = 3;

                var createGameRequest = new CreateGameRequest
                {
                    GameId         = roomName,
                    GameProperties = gameProperties,
                    RoomFlags      = policy == "ToAll" ? RoomOptionFlags.BroadcastPropsChangeToAll : 0,
                };

                masterClient1 = this.CreateMasterClientAndAuthenticate(Player1);
                var cgResponse = masterClient1.CreateGame(createGameRequest);
                this.ConnectAndAuthenticate(masterClient1, cgResponse.Address);
                masterClient1.CreateGame(createGameRequest);

                masterClient2 = this.CreateMasterClientAndAuthenticate(Player2);

                var joinRequest = new JoinGameRequest()
                {
                    GameId = roomName,
                };
                var jgResponse = masterClient2.JoinGame(joinRequest, ErrorCode.Ok);
                this.ConnectAndAuthenticate(masterClient2, jgResponse.Address);
                masterClient2.JoinGame(joinRequest);


                masterClient1.EventQueueClear();
                masterClient1.SendRequest(new OperationRequest()
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { (byte)ParameterKey.Properties, new Hashtable {
                              { "P2", 22 }
                          } },
                        { (byte)ParameterKey.Broadcast, true }
                    }
                });

                masterClient2.CheckThereIsEvent(EventCode.PropertiesChanged, this.WaitTimeout);
                if (policy == "ToOthers")
                {
                    masterClient1.CheckThereIsNoEvent(EventCode.PropertiesChanged, this.WaitTimeout);
                }
                else
                {
                    masterClient1.CheckThereIsEvent(EventCode.PropertiesChanged, this.WaitTimeout);
                }
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
            }
        }
        public void EventCache_RemoveUsingActorIdAndEventCode()
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;
            UnifiedTestClient client3 = null;
            UnifiedTestClient client4 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                // create room
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                var createGameRequest = new CreateGameRequest
                {
                    GameId          = roomName,
                    CheckUserOnJoin = !string.IsNullOrEmpty(this.Player1),
                };

                var createGameResponse = client1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address);

                // creation on GS
                client1.CreateGame(createGameRequest);


                // second player joins and check that there is no removed event
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2);
                client3 = this.CreateMasterClientAndAuthenticate(this.Player3);

                this.ConnectClientToGame(client2, roomName);
                this.ConnectClientToGame(client3, roomName);

                var eventsData = new Hashtable {
                    { 1, 1 }
                };
                AddEventCacheData(client1, client2, client3, eventsData);

                client2.Disconnect();
                client3.Disconnect();

                // remove cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.ActorList, new int[] { 3 } },
                        { ParameterCode.Cache, (byte)EventCaching.RemoveFromRoomCache },
                        { ParameterCode.Code, (byte)4 },
                    }
                });


                client4 = this.CreateMasterClientAndAuthenticate("Player4");
                this.ConnectClientToGame(client4, roomName);

                client4.WaitForEvent(EventCode.Join);
                client4.CheckThereIsEvent(1);
                client4.CheckThereIsEvent(2);

                client4.CheckThereIsEvent(3);
                client4.CheckThereIsNoEvent(4);
            }
            finally
            {
                DisposeClients(client1, client2, client3, client4);
            }
        }
        public void EventCache_AddGlobalEventRemoveUsing0ActorId()
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                // create room
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                var createGameRequest = new CreateGameRequest
                {
                    GameId          = roomName,
                    CheckUserOnJoin = !string.IsNullOrEmpty(this.Player1),
                };

                var createGameResponse = client1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address);

                // creation on GS
                client1.CreateGame(createGameRequest);
                var data = new Hashtable()
                {
                    { (byte)7, 1 }
                };
                // add cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Code, (byte)1 },
                        { ParameterCode.Data, data },
                        { ParameterCode.Cache, (byte)EventCaching.AddToRoomCacheGlobal },
                    }
                });

                // remove cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Code, (byte)1 },
                        { ParameterCode.ActorList, new int[] { 0 } },
                        { ParameterCode.Data, data },
                        { ParameterCode.Cache, (byte)EventCaching.RemoveFromRoomCache },
                    }
                });

                // second player joins and check that there is no removed event
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2);

                this.ConnectClientToGame(client2, roomName);

                client2.WaitForEvent(EventCode.Join);

                client2.CheckThereIsNoEvent(1);
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }
Ejemplo n.º 5
0
        public void GetGameUpdate_WellKnownPropertyChange(
            [Values(GameParameter.IsVisible, GameParameter.IsOpen)] GameParameter gameParameter,
            [Values(LobbyType.Default, LobbyType.SqlLobby)] LobbyType lobbyType)
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

            var lobbyFilterCase = LobbyFilterContent.LobbyFilterNonEmpty;
            var lobbyName       = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name + "_Lobby");
            var lobbyFilter     = SetupLobbyFilter(lobbyFilterCase);

            try
            {
                // authenticate client and check if the Lobbystats event will be received
                // Remarks: The event cannot be checked for a specific lobby count because
                // previous tests may have created lobbies.
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                if (string.IsNullOrEmpty(this.Player1) || client1.Token == null)
                {
                    Assert.Ignore("This test does not work correctly for old clients without userId and token");
                }

                client1.JoinLobby(lobbyName, (byte)lobbyType);

                // create a new game for the lobby
                var gameName           = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);
                var createGameResponse = client1.CreateGame(gameName, true, true, 0, new Hashtable()
                {
                    { "z", "w" }
                }, lobbyFilter, null);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address, client1.UserId);
                client1.CreateGame(gameName, true, true, 0, new Hashtable()
                {
                    { "z", "w" }
                }, lobbyFilter, null);

                // give the game server some time to report the game to the master server
                Thread.Sleep(100);

                var authParameter = new Dictionary <byte, object> {
                    { (byte)Operations.ParameterCode.LobbyStats, true }
                };
                // check if new game is listed in lobby statistics
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2, authParameter);
                if (this.AuthPolicy == AuthPolicy.UseAuthOnce) // in this case we should send OpSettings to master
                {
                    client2.SendRequest(new OperationRequest
                    {
                        OperationCode = (byte)OperationCode.ServerSettings,
                        Parameters    = new Dictionary <byte, object> {
                            { SettingsRequestParameters.LobbyStats, true }
                        },
                    });
                }

                client2.JoinLobby(lobbyName, (byte)lobbyType);
                Thread.Sleep(3000);
                client2.EventQueueClear();

                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Properties, new Hashtable {
                              { (byte)gameParameter, false }
                          } },
                    }
                });

                client2.CheckThereIsEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout);

                // we send same value again
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Properties, new Hashtable {
                              { (byte)gameParameter, false }
                          } },
                    }
                });

                client2.CheckThereIsNoEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout);
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }