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 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 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); } }