Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public void GetGameUpdate_PluginSetStateOnCreation([Values(LobbyType.Default, LobbyType.SqlLobby)] LobbyType lobbyType)
        {
            if (!this.UsePlugins)
            {
                Assert.Ignore("This test needs plugins");
            }

            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 request  = new CreateGameRequest
                {
                    GameId    = gameName,
                    LobbyType = (byte)lobbyType,
                    LobbyName = lobbyName,
                    Plugins   = new [] { "SaveLoadStateTestPlugin" },

                    GameProperties = new Hashtable
                    {
                        { "xxx", 1 },
                        { "yyy", 2 },
                        { GameParameter.LobbyProperties, new [] { "xxx" } }
                    },
                };

                var createGameResponse = client1.CreateGame(request);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address, client1.UserId);
                client1.CreateGame(request);

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

                client1.Disconnect();// after disconnect game state is saved

                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();


                var joinRequest = new JoinGameRequest
                {
                    GameId    = gameName,
                    LobbyType = (byte)lobbyType,
                    LobbyName = lobbyName,
                    Plugins   = new string[] { "SaveLoadStateTestPlugin" },
                    JoinMode  = (byte)JoinMode.JoinOrRejoin,
                };

                this.ConnectAndAuthenticate(client1, this.MasterAddress);
                var jgResponse = client1.JoinGame(joinRequest);

                this.ConnectAndAuthenticate(client1, jgResponse.Address);
                client1.JoinGame(joinRequest);

                EventData eventData;
                Assert.That(client2.TryWaitForEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout, out eventData));

                Assert.That(eventData.Parameters.Count > 0);

                var gameList     = (Hashtable)eventData.Parameters[(byte)ParameterKey.GameList];
                var propertyList = (Hashtable)gameList[gameName];

                Assert.That(propertyList["xxx"], Is.EqualTo(1));
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }
Ejemplo n.º 3
0
        public void GetGameUpdate_LobbyPropertyRemove([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);
            string propertyName    = "InLobbyFilterList";

            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 createGameRequest = new CreateGameRequest
                {
                    GameId         = gameName,
                    RoomFlags      = RoomOptionFlags.DeleteNullProps,
                    GameProperties = new Hashtable()
                    {
                        { "z", "w" },
                        { propertyName, "Value" },
                        { (byte)GameParameter.LobbyProperties, lobbyFilter }
                    }
                };
                var createGameResponse = client1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address, client1.UserId);
                client1.CreateGame(createGameRequest);

                // 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);

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

                Thread.Sleep(100);

                var gameListUpdate = client2.WaitForEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout);

                var gameList     = (Hashtable)gameListUpdate.Parameters[(byte)ParameterKey.GameList];
                var propertyList = (Hashtable)gameList[gameName];

                Assert.That(propertyList[propertyName], Is.EqualTo("xx"));

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

                Thread.Sleep(100);

                gameListUpdate = client2.WaitForEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout);
                gameList       = (Hashtable)gameListUpdate.Parameters[(byte)ParameterKey.GameList];
                propertyList   = (Hashtable)gameList[gameName];

                Assert.That(propertyList.Contains(propertyName), Is.False);
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }