public void RoomFlags_SuppressRoomEvents([Values("UseFlag", "UseFlags", "Conflict")] string testCase)
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName("SuppressRoomEvents_");

                client1 = this.CreateMasterClientAndAuthenticate(Player1);
                client2 = this.CreateMasterClientAndAuthenticate(Player2);

                var createGameResponse = client1.CreateGame(roomName, true, true, 4);

                // switch client 1 to GS
                this.ConnectAndAuthenticate(client1, createGameResponse.Address, client1.UserId);

                var createRequest = new OperationRequest {
                    OperationCode = OperationCode.CreateGame, Parameters = new Dictionary <byte, object>()
                };
                createRequest.Parameters.Add(ParameterCode.RoomName, createGameResponse.GameId);

                if (testCase == "UseFlags")
                {
                    createRequest.Parameters.Add((byte)ParameterKey.RoomOptionFlags, RoomOptionFlags.SuppressRoomEvents);
                }
                else if (testCase == "UseFlag")
                {
                    createRequest.Parameters.Add((byte)Operations.ParameterCode.SuppressRoomEvents, true);
                }
                else
                {
                    createRequest.Parameters.Add((byte)ParameterKey.RoomOptionFlags, RoomOptionFlags.SuppressRoomEvents);
                    createRequest.Parameters.Add((byte)Operations.ParameterCode.SuppressRoomEvents, false);
                }

                client1.SendRequestAndWaitForResponse(createRequest);

                this.ConnectAndAuthenticate(client2, createGameResponse.Address, client1.UserId);
                client2.JoinGame(roomName);

                EventData eventData;
                Assert.IsFalse(client1.TryWaitForEvent(EventCode.Join, ConnectPolicy.WaitTime, out eventData));

                client1.Dispose();
                Assert.IsFalse(client2.TryWaitForEvent(EventCode.Leave, ConnectPolicy.WaitTime, out eventData));
            }
            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);
            }
        }