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 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_DeleteNullPropsCASTest() { 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", 1 } } }, } }); 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.SendRequest(new OperationRequest() { OperationCode = OperationCode.SetProperties, Parameters = new Dictionary <byte, object> { { (byte)ParameterKey.Properties, new Hashtable { { "P2", null } } }, { (byte)ParameterKey.ExpectedValues, new Hashtable { { "P2", 2 } } }, } }); 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 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 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); } }
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_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 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); } }