コード例 #1
0
        public void AsyncJoinToExistingGame()
        {
            UnifiedTestClient client  = null;
            UnifiedTestClient client2 = null;

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

                client = this.CreateMasterClientAndAuthenticate(Player1);

                // try join game on gameServer
                this.ConnectAndAuthenticate(client, this.GameServerAddress);
                client.CreateGame(roomName);

                // try join game on master
                client2 = this.CreateMasterClientAndAuthenticate(Player2);
                client2.JoinGame(roomName);

                // try join game on gameServer
                this.ConnectAndAuthenticate(client2, this.GameServerAddress);
                client2.JoinGame(roomName);
            }
            finally
            {
                DisposeClients(client, client2);
            }
        }
コード例 #2
0
        public void TestGameAvilabilityAfterConnectionBreak()
        {
            if (this.connectPolicy.IsOnline)
            {
                Assert.Ignore("This is an offline test");
            }

            Thread.Sleep(1000);// to finish everything from perv tests

            var connPolicy = (OfflineConnectPolicy)this.connectPolicy;

            var masterServer = (ITestMasterApplication)connPolicy.MasterServer.Application;

            masterServer.ResetStats();

            UnifiedTestClient masterClient1 = null;
            UnifiedTestClient masterClient2 = null;

            try
            {
                string roomName = this.GenerateRandomizedRoomName("TestGameAvilabilityAfterConnectionBreak_");
                masterClient1 = this.CreateGameOnGameServer(this.Player1, roomName, null, 0, true, true, 3, null, null);

                connPolicy.MasterServer.SimulateConnectionBreak(1000);

                Thread.Sleep(1100);

                masterClient2 = this.CreateMasterClientAndAuthenticate(this.Player2);

                masterClient2.JoinGame(roomName, ErrorCode.Ok);

                Thread.Sleep(GameServerSettings.Default.ConnectReytryInterval * 1000);

                // check that game still there after restoring of connection
                masterClient2.JoinGame(roomName, ErrorCode.Ok);

                Assert.That(masterServer.OnBeginReplicationCount, Is.EqualTo(2));
                Assert.That(masterServer.OnFinishReplicationCount, Is.EqualTo(2));
                Assert.That(masterServer.OnStopReplicationCount, Is.EqualTo(0));
                Assert.That(masterServer.OnServerWentOfflineCount, Is.EqualTo(0));
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
                masterServer.ResetStats();
            }
        }
コード例 #3
0
        public void EventCache_SliceLimitExceeded()
        {
            if (this.IsOnline)
            {
                Assert.Ignore("Does not support online mode");
            }

            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

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

                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);
                createRequest.Parameters.Add((byte)Operations.ParameterCode.SuppressRoomEvents, true);
                client1.SendRequestAndWaitForResponse(createRequest);

                var raiseEventOp = new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Data, new Hashtable() },
                        { ParameterCode.Cache, (byte)CacheOperation.SliceIncreaseIndex }
                    }
                };

                for (int i = 0; i < 10; ++i)
                {
                    client1.SendRequest(raiseEventOp);
                }

                client1.SendRequestAndWaitForResponse(raiseEventOp, ErrorCode.InvalidOperation);

                this.ConnectAndAuthenticate(client2, createGameResponse.Address);
                client2.JoinGame(roomName);
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }
コード例 #4
0
        public void RoomFlags_BroadcastTest()
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

            try
            {
                string roomName = this.GenerateRandomizedRoomName("MaxPlayers_");
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                var cr = new CreateGameRequest
                {
                    GameId         = roomName,
                    GameProperties = new Hashtable {
                        { "key", "value" }
                    },
                    RoomFlags = RoomOptionFlags.BroadcastPropsChangeToAll
                };

                var response = client1.CreateGame(cr);

                this.ConnectAndAuthenticate(client1, response.Address);

                response = client1.CreateGame(cr);

                // join 2nd client :
                client2 = this.CreateMasterClientAndAuthenticate(Player2);
                var jr = client2.JoinGame(roomName);

                this.ConnectAndAuthenticate(client2, jr.Address);

                var jr2 = client2.JoinGame(roomName);

                Assert.That(jr2.RoomFlags, Is.EqualTo(RoomOptionFlags.BroadcastPropsChangeToAll));
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        public void AsyncJoinToSavedGame()
        {
            UnifiedTestClient client  = null;
            UnifiedTestClient client2 = null;

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

                client = this.CreateMasterClientAndAuthenticate(Player1);

                // try join game on gameServer
                this.ConnectAndAuthenticate(client, this.GameServerAddress);

                client.CreateRoom(roomName, new RoomOptions(), TypedLobby.Default, null, true, "SaveLoadStateTestPlugin");

                Thread.Sleep(1000);
                client.Disconnect();
                Thread.Sleep(1000);

                // try join game on master
                client2 = this.CreateMasterClientAndAuthenticate(Player2);
                client2.JoinGame(roomName);

                // try join game on gameServer
                this.ConnectAndAuthenticate(client2, this.GameServerAddress);
                var joinGameRequest = new JoinGameRequest
                {
                    GameId  = roomName,
                    Plugins = new[] { "SaveLoadStateTestPlugin" }
                };
                client2.WaitTimeout = 3000000;
                client2.JoinGame(joinGameRequest);
            }
            finally
            {
                DisposeClients(client, client2);
            }
        }
コード例 #7
0
        public void TestRemoveNonReplicatedGames()
        {
            if (this.connectPolicy.IsOnline)
            {
                Assert.Ignore("This is an offline test");
            }

            Thread.Sleep(1000);// to finish everything from perv tests

            var connPolicy = (OfflineConnectPolicy)this.connectPolicy;

            var masterServer = (ITestMasterApplication)connPolicy.MasterServer.Application;

            masterServer.ResetStats();

            UnifiedTestClient masterClient1 = null;
            UnifiedTestClient masterClient2 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);
                masterClient1 = this.CreateGameOnGameServer(this.Player1, roomName, null, 0, true, true, 3, null, null);

                connPolicy.MasterServer.SimulateConnectionBreak((uint)GameServerSettings.Default.ConnectReytryInterval * 1000 - 1000);

                masterClient1.Disconnect(); // after disconnect game should be removed from GS

                // wait till game server reconnts
                Thread.Sleep(GameServerSettings.Default.ConnectReytryInterval * 1000 + 1000);

                // join 2nd client on master:
                masterClient2 = this.CreateMasterClientAndAuthenticate(this.Player2);

                masterClient2.JoinGame(roomName, ErrorCode.GameDoesNotExist);

                Assert.That(masterServer.OnBeginReplicationCount, Is.EqualTo(2));
                Assert.That(masterServer.OnFinishReplicationCount, Is.EqualTo(2));
                Assert.That(masterServer.OnStopReplicationCount, Is.EqualTo(0));
                Assert.That(masterServer.OnServerWentOfflineCount, Is.EqualTo(0));
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
                connPolicy.GameServer.Stop();
                connPolicy.GameServer.Start();
                masterServer.ResetStats();
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        public void RoomFlags_DeleteNullPropsAfterStateRestoreTest()
        {
            if (!this.UsePlugins)
            {
                Assert.Ignore("This test needs plugins");
            }

            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,
                    Plugins        = new[] { "SaveLoadStateTestPlugin" },
                };

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

                this.ConnectAndAuthenticate(masterClient1, cgResponse.Address);

                masterClient1.CreateGame(createGameRequest);
                Thread.Sleep(100);
                masterClient1.LeaveGame();// leave game, so that game will be persisted

                Thread.Sleep(100);

                this.ConnectAndAuthenticate(masterClient1, this.MasterAddress);

                var joinRequest = new JoinGameRequest()
                {
                    GameId   = roomName,
                    JoinMode = JoinModes.RejoinOrJoin,
                    Plugins  = new[] { "SaveLoadStateTestPlugin" },
                };

                var jgResponse = masterClient1.JoinGame(joinRequest, ErrorCode.Ok);
                this.ConnectAndAuthenticate(masterClient1, jgResponse.Address);
                jgResponse = masterClient1.JoinGame(joinRequest);

                masterClient1.OpSetPropertiesOfRoom
                (
                    new Hashtable
                {
                    { "P1", null }
                }
                );

                masterClient2 = this.CreateMasterClientAndAuthenticate(Player2);
                jgResponse    = masterClient2.JoinGame(joinRequest, ErrorCode.Ok);
                this.ConnectAndAuthenticate(masterClient2, jgResponse.Address);

                jgResponse = masterClient2.JoinGame(joinRequest);

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

                masterClient1.OpSetPropertiesOfRoom
                (
                    new Hashtable
                {
                    { "P2", null }
                }
                );

                var propertiesChangedEvent = masterClient2.WaitForEvent(EventCode.PropertiesChanged, this.WaitTimeout);

                var properties = (Hashtable)propertiesChangedEvent[(byte)ParameterKey.Properties];

                Assert.That(properties, Is.Not.Null);
                Assert.That(properties.Contains("P2"));
                Assert.That(properties["P2"], Is.Null);
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
            }
        }
コード例 #10
0
        public void RoomFlags_DeleteNullPropsTest()
        {
            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 OperationRequest
                {
                    OperationCode = OperationCode.CreateGame,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.RoomName, roomName },
                        { ParameterCode.Properties, gameProperties },
                    }
                };

                createGameRequest.Parameters.Add((byte)ParameterKey.RoomOptionFlags, RoomOptionFlags.DeleteNullProps);


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

                this.ConnectAndAuthenticate(masterClient1, (string)cgResponse[ParameterCode.Address]);

                masterClient1.SendRequestAndWaitForResponse(createGameRequest);

                masterClient1.OpSetPropertiesOfRoom
                (
                    new Hashtable
                {
                    { "P1", null }
                }
                );

                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.False);

                masterClient1.OpSetPropertiesOfRoom
                (
                    new Hashtable
                {
                    { "P2", null }
                }
                );

                var propertiesChangedEvent = masterClient2.WaitForEvent(EventCode.PropertiesChanged, this.WaitTimeout);

                var properties = (Hashtable)propertiesChangedEvent[(byte)ParameterKey.Properties];

                Assert.That(properties, Is.Not.Null);
                Assert.That(properties.Contains("P2"));
                Assert.That(properties["P2"], Is.Null);
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
            }
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        public void EventCache_ActorCacheLimitExceeded()
        {
            if (this.IsOnline)
            {
                Assert.Ignore("Does not support online mode");
            }

            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;
            UnifiedTestClient client3 = null;

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

                client1 = this.CreateMasterClientAndAuthenticate(Player1);
                client3 = this.CreateMasterClientAndAuthenticate(Player3);

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

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

                client1.CreateGame(new CreateGameRequest()
                {
                    GameId             = roomName,
                    PlayerTTL          = -1,
                    SuppressRoomEvents = true,
                    CheckUserOnJoin    = true
                });

                client3.JoinGame(roomName);

                // exceeding limits
                for (byte i = 1; i <= 11; ++i)
                {
                    var raiseEventOp = new OperationRequest
                    {
                        OperationCode = OperationCode.RaiseEvent,
                        Parameters    = new Dictionary <byte, object>
                        {
                            { ParameterCode.Data, new Hashtable() },
                            { ParameterCode.Cache, (byte)CacheOperation.MergeCache },
                            { ParameterCode.Code, i }
                        }
                    };
                    client1.SendRequest(raiseEventOp);
                }
                client1.WaitForEvent(EventCode.PropertiesChanged);
                client1.WaitForEvent(EventCode.ErrorInfo);

                client2 = this.CreateMasterClientAndAuthenticate(Player2);
                client2.JoinGame(roomName, ErrorCode.GameClosed);

                this.ConnectAndAuthenticate(client2, createGameResponse.Address);
                client2.JoinGame(roomName, ErrorCode.GameClosed);

                client3.LeaveGame(true);
                client3.Disconnect();

                this.ConnectAndAuthenticate(client3, createGameResponse.Address);
                client3.JoinGame(new JoinGameRequest
                {
                    GameId   = roomName,
                    JoinMode = JoinModes.RejoinOnly
                }, 32739);//EventCacheExceeded
            }
            finally
            {
                DisposeClients(client1, client2, client3);
            }
        }
コード例 #13
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);
            }
        }
コード例 #14
0
        public void TestLobbyCountAfterRemovingInactivePlayerBreak()
        {
            if (this.connectPolicy.IsOnline)
            {
                Assert.Ignore("This is an offline test");
            }

            if (string.IsNullOrEmpty(this.Player1))
            {
                Assert.Ignore("this tests requires userId to be set");
            }

            Thread.Sleep(1000);// to finish everything from perv tests

            var connPolicy = (OfflineConnectPolicy)this.connectPolicy;

            var masterServer = (ITestMasterApplication)connPolicy.MasterServer.Application;

            masterServer.ResetStats();

            UnifiedTestClient masterClient1 = null;
            UnifiedTestClient masterClient2 = null;
            UnifiedTestClient masterClient3 = null;

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

                masterClient1 = this.CreateMasterClientAndAuthenticate(this.Player1);
                var createGameRequest = new CreateGameRequest
                {
                    GameId          = roomName,
                    PlayerTTL       = 3000,
                    CheckUserOnJoin = !string.IsNullOrEmpty(this.Player1),
                };
                var createGameResponse = masterClient1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(masterClient1, createGameResponse.Address);

                //createGameRequest.AddUsers = new string[] { "Player3", "Player5", "Player6", "Player7" };

                masterClient1.CreateGame(createGameRequest);
                Thread.Sleep(300);

                masterClient2 = this.CreateMasterClientAndAuthenticate(this.Player2);
                masterClient3 = this.CreateMasterClientAndAuthenticate(this.Player3);

                var response = masterClient2.JoinGame(roomName, ErrorCode.Ok);
                masterClient3.JoinGame(roomName, ErrorCode.Ok);

                this.ConnectAndAuthenticate(masterClient3, response.Address);

                masterClient3.JoinGame(roomName, ErrorCode.Ok);

                Thread.Sleep(300);

                masterClient3.Disconnect();

                Thread.Sleep(4000);

                masterClient1.Disconnect();

                Thread.Sleep(1000);
                this.ConnectAndAuthenticate(masterClient2, this.MasterAddress);
                var getLobbyStatsResponse = masterClient2.GetLobbyStats(null, null);

                masterClient2.Disconnect();

                Assert.That(getLobbyStatsResponse.PeerCount[0], Is.EqualTo(0));
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2, masterClient3);
            }
        }