protected void ConnectAndAuthenticate(UnifiedTestClient client, Dictionary <byte, object> authParameter = null) { OperationResponse response; switch (this.authPolicy) { #pragma warning disable CS0618 // Type or member is obsolete case AuthPolicy.AuthOnMaster: #pragma warning restore CS0618 // Type or member is obsolete this.ConnectAndAuthenticate(client, this.MasterAddress, authParameter); break; case AuthPolicy.AuthOnNameServer: { response = this.ConnectAndAuthenticate(client, this.NameServerAddress, authParameter); this.MasterAddress = (string)response[ParameterCode.Address]; this.ConnectAndAuthenticate(client, this.MasterAddress, client.UserId, authParameter, reuseToken: true); break; } case AuthPolicy.UseAuthOnce: response = this.ConnectAndAuthenticate(client, this.NameServerAddress, authParameter); this.MasterAddress = (string)response[ParameterCode.Address]; this.ConnectAndAuthenticate(client, this.MasterAddress, client.UserId, authParameter, reuseToken: true); break; default: throw new ArgumentOutOfRangeException(); } }
public void RoomFlags_NotPublishUserIdTest() { UnifiedTestClient masterClient1 = null; UnifiedTestClient masterClient2 = null; UnifiedTestClient masterClient3 = null; UnifiedTestClient masterClient4 = null; try { var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name + "_"); var joinRequest = new OperationRequest { OperationCode = OperationCode.JoinGame, Parameters = new Dictionary <byte, object> { { ParameterCode.RoomName, roomName }, { ParameterCode.JoinMode, JoinModes.CreateIfNotExists }, { ParameterCode.CheckUserOnJoin, !string.IsNullOrEmpty(this.Player1) }, { ParameterCode.Broadcast, true }, } }; masterClient1 = this.CreateMasterClientAndAuthenticate(Player1); masterClient2 = this.CreateMasterClientAndAuthenticate(Player2); masterClient3 = this.CreateMasterClientAndAuthenticate(Player3); masterClient4 = this.CreateMasterClientAndAuthenticate(Player3 != null ? "Player4" : null); var joinResponse = masterClient1.SendRequestAndWaitForResponse(joinRequest); var address = (string)joinResponse[ParameterCode.Address]; // client 1: connect to GS and try to join not existing game on the game server (create if not exists) this.ConnectAndAuthenticate(masterClient1, address); masterClient1.SendRequestAndWaitForResponse(joinRequest); //var actorProperties = (Hashtable)joinResponse[ParameterCode.PlayerProperties]; var joinEvent = masterClient1.WaitForEvent(EventCode.Join); var actorProperties = (Hashtable)joinEvent[ParameterCode.PlayerProperties]; Assert.IsNull(actorProperties); joinResponse = masterClient2.SendRequestAndWaitForResponse(joinRequest); address = (string)joinResponse[ParameterCode.Address]; // client 1: connect to GS and try to join not existing game on the game server (create if not exists) this.ConnectAndAuthenticate(masterClient2, address); joinResponse = masterClient2.SendRequestAndWaitForResponse(joinRequest); actorProperties = (Hashtable)joinResponse[ParameterCode.PlayerProperties]; Assert.IsNull(actorProperties); joinEvent = masterClient1.WaitForEvent(EventCode.Join); actorProperties = (Hashtable)joinEvent[ParameterCode.PlayerProperties]; Assert.IsNull(actorProperties); } finally { DisposeClients(masterClient1, masterClient2, masterClient3, masterClient4); } }
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); } }
protected override void FixtureSetup() { base.FixtureSetup(); UnifiedTestClient client = null; try { // this call will update Master server address client = (UnifiedTestClient)this.CreateTestClient(); client.UserId = this.Player1; if (this.authPolicy != AuthPolicy.AuthOnMaster || this.connectPolicy.UseNSToGetMS) { var response = this.ConnectAndAuthenticate(client, this.NameServerAddress, null, ErrorCode.Ok); this.MasterAddress = (string)response[ParameterCode.Address]; } this.ConnectAndAuthenticate(client, this.MasterAddress, client.UserId, null, reuseToken: true); var roomName = this.GenerateRandomString("room"); var createGameResponse = client.CreateGame(roomName); this.GameServerAddress = createGameResponse.Address; this.ConnectAndAuthenticate(client, this.GameServerAddress); client.CreateGame(roomName); client.LeaveGame(); } finally { DisposeClients(client); } }
public void TestCleanupPlayerCacheAfterLongConnectionBreak() { 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; try { var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name); masterClient1 = this.CreateGameOnGameServer(this.Player1, roomName, null, 0, true, true, 3, null, null, checkUserOnJoin: true); const int waitDelta = 3_000; // we initiate connection break and wait untill GSs are moreved from master + waitDelta connPolicy.MasterServer.SimulateConnectionBreak((uint)MasterServerSettings.Default.GSContextTTL + waitDelta); // wait till game server context will be removed Thread.Sleep(MasterServerSettings.Default.GSContextTTL + waitDelta + 1000); // join 2nd client on master: masterClient2 = this.CreateMasterClientAndAuthenticate(this.Player2); // gs is not reconnected yet, so we will not find our player in cache masterClient2.FindFriends(new string[] { this.Player1 }, out var onlineStates, out var userStates); Assert.That(onlineStates[0], Is.False); Thread.Sleep(GameServerSettings.Default.ConnectReytryInterval * 1000); // now GS is reconnected and we should be able to find our player online masterClient2.FindFriends(new string[] { this.Player1 }, out onlineStates, out userStates); Assert.That(onlineStates[0], Is.True); Assert.That(userStates[0], Is.EqualTo(roomName)); } finally { DisposeClients(masterClient1, masterClient2); connPolicy.GameServer.Stop(); connPolicy.GameServer.Start(); masterServer.ResetStats(); } }
public void RoomFlags_CheckUserOnJoin([Values("UseFlag", "UseFlags", "Conflict")] string testCase) { if (string.IsNullOrEmpty(this.Player1)) { Assert.Ignore("Test does work only if PlayerId is set"); } UnifiedTestClient masterClient1 = null; UnifiedTestClient masterClient2 = null; try { var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name + "_"); var joinRequest = new OperationRequest { OperationCode = OperationCode.JoinGame, Parameters = new Dictionary <byte, object> { { ParameterCode.RoomName, roomName }, { ParameterCode.JoinMode, JoinModes.CreateIfNotExists }, } }; if (testCase == "UseFlags") { joinRequest.Parameters.Add((byte)ParameterKey.RoomOptionFlags, RoomOptionFlags.CheckUserOnJoin); } else if (testCase == "UseFlag") { joinRequest.Parameters.Add(ParameterCode.CheckUserOnJoin, true); } else { joinRequest.Parameters.Add((byte)ParameterKey.RoomOptionFlags, RoomOptionFlags.CheckUserOnJoin); joinRequest.Parameters.Add(ParameterCode.CheckUserOnJoin, false); } masterClient1 = this.CreateMasterClientAndAuthenticate(Player1); masterClient2 = this.CreateMasterClientAndAuthenticate(Player1); var joinResponse = masterClient1.SendRequestAndWaitForResponse(joinRequest); var address = (string)joinResponse[ParameterCode.Address]; // client 1: connect to GS and try to join not existing game on the game server (create if not exists) this.ConnectAndAuthenticate(masterClient1, address); masterClient1.SendRequestAndWaitForResponse(joinRequest); masterClient2.SendRequestAndWaitForResponse(joinRequest, ErrorCode.JoinFailedPeerAlreadyJoined); } finally { DisposeClients(masterClient1, masterClient2); } }
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); } }
private static void AddEventCacheData(UnifiedTestClient client1, UnifiedTestClient client2, UnifiedTestClient client3, Hashtable data) { // add cached message client1.SendRequest(new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Code, (byte)1 }, { ParameterCode.Cache, (byte)EventCaching.AddToRoomCacheGlobal }, { ParameterCode.Data, data }, } }); // add cached message client1.SendRequest(new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Code, (byte)2 }, { ParameterCode.Cache, (byte)EventCaching.AddToRoomCache }, { ParameterCode.Data, null }, } }); // add cached message client2.SendRequest(new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Code, (byte)3 }, { ParameterCode.Cache, (byte)EventCaching.AddToRoomCache }, { ParameterCode.Data, data }, } }); // add cached message client3.SendRequest(new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Code, (byte)4 }, { ParameterCode.Cache, (byte)EventCaching.AddToRoomCache }, { ParameterCode.Data, data }, } }); Thread.Sleep(200); }
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); } }
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(); } }
public void TestGameCreatedOnGSReplicatedToMS() { 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("TestGameCreatedOnGSReplicatedToMS_"); masterClient1 = this.CreateMasterClientAndAuthenticate(this.Player1); this.ConnectAndAuthenticate(masterClient1, this.GameServerAddress); connPolicy.MasterServer.SimulateConnectionBreak(10000); masterClient1.CreateGame(roomName); Thread.Sleep(GameServerSettings.Default.ConnectReytryInterval * 1000 + 1000); masterClient2 = this.CreateMasterClientAndAuthenticate(this.Player2); masterClient2.JoinGame(roomName, ErrorCode.Ok); Thread.Sleep(1000); 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(); } }
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); } }
protected virtual OperationResponse ConnectAndAuthenticate(UnifiedTestClient client, string address, string userName, Dictionary <byte, object> authParameter = null, bool reuseToken = false, short expectedErrorCode = 0) { if (client.Connected) { client.Disconnect(); } if (!reuseToken && address == this.MasterAddress #pragma warning disable CS0618 // Type or member is obsolete && this.authPolicy == AuthPolicy.AuthOnMaster) #pragma warning restore CS0618 // Type or member is obsolete { client.Token = string.Empty; } client.OperationResponseQueueClear(); client.EventQueueClear(); if (authParameter == null) { authParameter = new Dictionary <byte, object>(); } if (this.authPolicy != AuthPolicy.UseAuthOnce || this.NameServerAddress == address) { ConnectToServer(client, address); if (this.authPolicy != AuthPolicy.UseAuthOnce) { return(client.Authenticate(userName, authParameter, expectedErrorCode)); } return(client.AuthOnce(userName, authParameter, expectedErrorCode)); } client.ConnectWithAuthOnce(address, expectedErrorCode); return(null); }
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); } }
public virtual void ConnectAndAuthenticate(UnifiedTestClient client, string address, string userName, Dictionary<byte, object> authParameter = null, bool reuseToken = false) { if (client.Connected) { client.Disconnect(); } if (!reuseToken && address == this.MasterAddress) { client.Token = String.Empty; } client.OperationResponseQueueClear(); client.EventQueueClear(); this.ConnectToServer(client, address); if (authParameter == null) { authParameter = new Dictionary<byte, object>(); } client.Authenticate(userName, authParameter); }
public virtual void ConnectAndAuthenticate(UnifiedTestClient client, string address, string userName, Dictionary <byte, object> authParameter = null, bool reuseToken = false) { if (client.Connected) { client.Disconnect(); } if (!reuseToken && address == this.MasterAddress) { client.Token = String.Empty; } client.OperationResponseQueueClear(); client.EventQueueClear(); this.ConnectToServer(client, address); if (authParameter == null) { authParameter = new Dictionary <byte, object>(); } client.Authenticate(userName, authParameter); }
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); } }
protected virtual OperationResponse ConnectAndAuthenticate(UnifiedTestClient client, string address, Dictionary <byte, object> authParameter = null, short expectedErrorCode = 0) { return(this.ConnectAndAuthenticate(client, address, client.UserId, authParameter, expectedErrorCode: expectedErrorCode)); }
public void SecureParamsTest() { UnifiedTestClient client = null; UnifiedTestClient client2 = null; const int SleepTime = 350; try { client = (UnifiedTestClient)this.CreateTestClient(); client.UserId = Player1; this.ConnectToServer(client, this.MasterAddress); var response = client.Authenticate(Player1, new Dictionary <byte, object>() { { (byte)ParameterKey.ClientAuthenticationParams, "username=yes&token=yes" } }); Assert.AreEqual("nick", response[(byte)ParameterKey.Nickname]); Assert.IsNotNull(response[(byte)ParameterKey.Token]); var request = new OperationRequest { OperationCode = OperationCode.CreateGame, Parameters = new Dictionary <byte, object> { { ParameterCode.RoomName, "TestGame" }, { ParameterCode.Plugins, new string[] { "CheckSecurePlugin" } }, } }; response = client.SendRequestAndWaitForResponse(request); this.ConnectAndAuthenticate(client, (string)response[ParameterCode.Address], client.UserId, new Dictionary <byte, object>() { { (byte)ParameterKey.ClientAuthenticationParams, "username=yes&token=yes" } }); client.SendRequestAndWaitForResponse(request); Thread.Sleep(SleepTime); CheckSecure("CreateGameAuthCookie"); client2 = this.CreateMasterClientAndAuthenticate("User2", new Dictionary <byte, object>() { { (byte)ParameterKey.ClientAuthenticationParams, "username=yes&token=yes" } }); request = new OperationRequest { OperationCode = OperationCode.JoinGame, Parameters = new Dictionary <byte, object> { { ParameterCode.RoomName, "TestGame" }, } }; response = client2.SendRequestAndWaitForResponse(request); this.ConnectAndAuthenticate(client2, (string)response[ParameterCode.Address], client2.UserId, new Dictionary <byte, object>() { { (byte)ParameterKey.ClientAuthenticationParams, "username=yes&token=yes" } }); client2.SendRequestAndWaitForResponse(request); Thread.Sleep(SleepTime); CheckSecure("JoinGameAuthCookie"); request = new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Code, (byte)1 }, { ParameterCode.EventForward, (byte)3 }, } }; client2.SendRequest(request); Thread.Sleep(SleepTime); CheckSecure("RaiseEventAuthCookie"); //just to ensure that there is nothing on server for RaiseEventAuthCookie CheckSecure("RaiseEventAuthCookie", expectToFail: true); request = new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Code, (byte)1 }, { ParameterCode.EventForward, (byte)1 },// we send request but without secure } }; client2.SendRequest(request); CheckSecure("RaiseEventAuthCookie", expectToFail: true); client.SendRequestAndWaitForResponse(new OperationRequest { OperationCode = OperationCode.SetProperties, Parameters = new Dictionary <byte, object> { { ParameterCode.Properties, new Hashtable { { GamePropertyKey.IsOpen, true } } }, { ParameterCode.EventForward, (byte)3 }, } }); Thread.Sleep(SleepTime); CheckSecure("SetPropertiesAuthCookie"); client.SendRequestAndWaitForResponse(new OperationRequest { OperationCode = OperationCode.WebRpc, Parameters = new Dictionary <byte, object> { { ParameterCode.Data, new Hashtable { { GamePropertyKey.IsOpen, true } } }, { ParameterCode.EventForward, (byte)3 }, { ParameterCode.UriPath, "RpcSecure" }, } }); Thread.Sleep(SleepTime); CheckSecure("RpcAuthCookie"); client.SendRequestAndWaitForResponse(new OperationRequest { OperationCode = OperationCode.WebRpc, Parameters = new Dictionary <byte, object> { { ParameterCode.Data, new Hashtable { { GamePropertyKey.IsOpen, true } } }, { ParameterCode.UriPath, "RpcSecure" }, } }); Thread.Sleep(SleepTime); CheckSecure("RpcAuthCookie", true); var client3 = this.CreateMasterClientAndAuthenticate("User3", new Dictionary <byte, object>() { { (byte)ParameterKey.ClientAuthenticationParams, "username=yes&token=yes" } }); client3.SendRequestAndWaitForResponse(new OperationRequest { OperationCode = OperationCode.WebRpc, Parameters = new Dictionary <byte, object> { { ParameterCode.Data, new Hashtable { { GamePropertyKey.IsOpen, true } } }, { ParameterCode.UriPath, "RpcSecure" }, { ParameterCode.EventForward, (byte)3 }, } }); Thread.Sleep(SleepTime); CheckSecure("RpcAuthCookie"); client3.SendRequestAndWaitForResponse(new OperationRequest { OperationCode = OperationCode.WebRpc, Parameters = new Dictionary <byte, object> { { ParameterCode.Data, new Hashtable { { GamePropertyKey.IsOpen, true } } }, { ParameterCode.UriPath, "RpcSecure" }, { ParameterCode.EventForward, (byte)1 }, } }); Thread.Sleep(SleepTime); CheckSecure("RpcAuthCookie", expectToFail: true); } finally { DisposeClients(client, client2); } }
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); } }
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); } }
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_PublishUserIdTest([Values("UseFlag", "UseFlags", "Conflict")] string testCase) { UnifiedTestClient masterClient1 = null; UnifiedTestClient masterClient2 = null; try { var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name + "_"); var joinRequest = new OperationRequest { OperationCode = OperationCode.JoinGame, Parameters = new Dictionary <byte, object> { { ParameterCode.RoomName, roomName }, { ParameterCode.JoinMode, JoinModes.CreateIfNotExists }, { ParameterCode.CheckUserOnJoin, !string.IsNullOrEmpty(this.Player1) }, { ParameterCode.Broadcast, true }, } }; if (testCase == "UseFlags") { joinRequest.Parameters.Add((byte)ParameterKey.RoomOptionFlags, RoomOptionFlags.PublishUserId); } else if (testCase == "UseFlag") { joinRequest.Parameters.Add(ParameterCode.PublishUserId, true); } else { joinRequest.Parameters.Add((byte)ParameterKey.RoomOptionFlags, RoomOptionFlags.PublishUserId); joinRequest.Parameters.Add(ParameterCode.PublishUserId, false); } masterClient1 = this.CreateMasterClientAndAuthenticate(Player1); masterClient2 = this.CreateMasterClientAndAuthenticate(Player2); if (string.IsNullOrEmpty(this.Player1) && masterClient1.Token == null) { Assert.Ignore("This test does not work correctly for old clients without userId and token"); } var joinResponse = masterClient1.SendRequestAndWaitForResponse(joinRequest); var address = (string)joinResponse[ParameterCode.Address]; // client 1: connect to GS and try to join not existing game on the game server (create if not exists) this.ConnectAndAuthenticate(masterClient1, address); masterClient1.SendRequestAndWaitForResponse(joinRequest); //var actorProperties = (Hashtable)joinResponse[ParameterCode.PlayerProperties]; var joinEvent = masterClient1.WaitForEvent(EventCode.Join); var actorProperties = (Hashtable)joinEvent[ParameterCode.PlayerProperties]; var userId = (string)actorProperties[(byte)ActorParameter.UserId]; if (string.IsNullOrEmpty(this.Player1)) { Assert.IsFalse(string.IsNullOrEmpty(userId)); } else { Assert.AreEqual(this.Player1, userId); } joinResponse = masterClient2.SendRequestAndWaitForResponse(joinRequest); address = (string)joinResponse[ParameterCode.Address]; // client 1: connect to GS and try to join not existing game on the game server (create if not exists) this.ConnectAndAuthenticate(masterClient2, address); masterClient2.OperationResponseQueueClear(); joinResponse = masterClient2.SendRequestAndWaitForResponse(joinRequest); actorProperties = (Hashtable)joinResponse[ParameterCode.PlayerProperties]; var actor0Properties = (Hashtable)actorProperties[1]; userId = (string)actor0Properties[(byte)ActorParameter.UserId]; if (string.IsNullOrEmpty(this.Player1)) { Assert.IsFalse(string.IsNullOrEmpty(userId)); } else { Assert.AreEqual(this.Player1, userId); } joinEvent = masterClient1.WaitForEvent(EventCode.Join); actorProperties = (Hashtable)joinEvent[ParameterCode.PlayerProperties]; userId = (string)actorProperties[(byte)ActorParameter.UserId]; if (string.IsNullOrEmpty(this.Player2)) { Assert.IsFalse(string.IsNullOrEmpty(userId)); } else { Assert.AreEqual(this.Player2, userId); } } finally { DisposeClients(masterClient1, masterClient2); } }
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); } }
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); } }
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); } }
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 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); } }
public void EventCache_ActorReplaceData() { 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 } }; var eventsData2 = new Hashtable { { 2, 2 } }; AddActorEventCacheData(client1, client2, client3, eventsData); client2.Disconnect(); client3.Disconnect(); // update cached message client1.SendRequest(new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Data, eventsData2 }, { ParameterCode.Cache, (byte)EventCaching.ReplaceCache }, { ParameterCode.Code, (byte)1 }, } }); client4 = this.CreateMasterClientAndAuthenticate("Player4"); this.ConnectClientToGame(client4, roomName); client4.WaitForEvent(EventCode.Join); EventData ev; Assert.That(client4.TryWaitEvent(1, this.WaitTimeout, out ev), Is.True); Assert.That(ev[(byte)ParameterKey.Data], Is.EqualTo(eventsData2)); client4.CheckThereIsEvent(2); client4.CheckThereIsEvent(3); } finally { DisposeClients(client1, client2, client3, client4); } }
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); } }
public virtual void ConnectAndAuthenticate(UnifiedTestClient client, string address, Dictionary<byte, object> authParameter = null) { this.ConnectAndAuthenticate(client, address, client.UserId, authParameter); }