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_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); } }
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 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 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 A_Group_PluginHttpCallSyncAfterContinueTests() { const string config = "HttpCallSyncAfterContinue"; UnifiedTestClient client = null; UnifiedTestClient client2 = null; var GameName = RandomizeString(MethodBase.GetCurrentMethod().Name); try { client = this.CreateMasterClientAndAuthenticate("User1"); var request = new OperationRequest { OperationCode = OperationCode.CreateGame, Parameters = new Dictionary <byte, object> { { ParameterCode.RoomName, GameName }, { ParameterCode.EmptyRoomTTL, 0 }, { ParameterCode.PlayerTTL, 0 }, { ParameterCode.CheckUserOnJoin, false }, { ParameterCode.CleanupCacheOnLeave, false }, { ParameterCode.SuppressRoomEvents, false }, { ParameterCode.LobbyName, "Default" }, { ParameterCode.LobbyType, (byte)0 }, { ParameterCode.GameProperties, new Hashtable { { "config", config } } }, { ParameterCode.Plugins, new string[] { "AllMethosCallHttpTestPlugin" } }, } }; var response = client.SendRequestAndWaitForResponse(request); this.ConnectAndAuthenticate(client, (string)response[ParameterCode.Address], client.UserId); client.SendRequestAndWaitForResponse(request); client.CheckThereIsEvent(123, this.WaitTimeout); client.SendRequestAndWaitForResponse(new OperationRequest { OperationCode = OperationCode.SetProperties, Parameters = new Dictionary <byte, object> { { ParameterCode.Properties, new Hashtable { { GamePropertyKey.IsOpen, true } } } } }); client.CheckThereIsErrorInfoEvent(this.WaitTimeout); client.CheckThereIsEvent(123, this.WaitTimeout); request = new OperationRequest { OperationCode = OperationCode.JoinGame, Parameters = new Dictionary <byte, object> { { ParameterCode.RoomName, GameName }, { ParameterCode.PlayerProperties, new Hashtable { { "Actor2Property", "Actor2PropertyValue" } } }, { ParameterCode.GameProperties, new Hashtable() }, { ParameterCode.UserId, "User2" }, { ParameterCode.LobbyName, "Default" }, }, }; client2 = this.CreateMasterClientAndAuthenticate("User2"); response = client2.SendRequestAndWaitForResponse(request); this.ConnectAndAuthenticate(client2, (string)response[ParameterCode.Address], client2.UserId); client2.SendRequestAndWaitForResponse(request); client.CheckThereIsErrorInfoEvent(this.WaitTimeout); client.CheckThereIsEvent(123, this.WaitTimeout); request = new OperationRequest { OperationCode = OperationCode.RaiseEvent, Parameters = new Dictionary <byte, object> { { ParameterCode.Code, (byte)1 }, } }; client.SendRequest(request); client.CheckThereIsEvent(123, this.WaitTimeout); client2.SendRequestAndWaitForResponse(new OperationRequest { OperationCode = OperationCode.Leave, Parameters = new Dictionary <byte, object> { { ParameterCode.IsInactive, true } } }); client2.Disconnect(); client.CheckThereIsNoErrorInfoEvent(); client.Disconnect(); } finally { if (client != null && client.Connected) { client.Disconnect(); client.Dispose(); } if (client2 != null && client2.Connected) { client2.Disconnect(); client2.Dispose(); } this.CheckGameIsClosed(GameName, this.WaitTimeout); } }