Browse Source

1.把session.Call的泛型方法去掉了,要获得正确的Response需要强制转换一下,主要是考虑到IOS上aot问题。强制转换一下也不麻烦
2.login完成后客户端需要realm server的session需要dispose掉

tanghai 8 years ago
parent
commit
e7cc7b9ad0

+ 1 - 1
Server/Hotfix/Handler/Actor_TransferHandler.cs

@@ -40,7 +40,7 @@ namespace Hotfix
 
 				// 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
 				Game.Scene.GetComponent<UnitComponent>().RemoveNoDispose(unitId);
-				await session.Call<M2M_TrasferUnitResponse>(new M2M_TrasferUnitRequest() { Unit = unit });
+				await session.Call(new M2M_TrasferUnitRequest() { Unit = unit });
 				unit.Dispose();
 
 				// 解锁unit的地址,并且更新unit的地址

+ 1 - 1
Server/Hotfix/Handler/C2G_EnterMapHandler.cs

@@ -17,7 +17,7 @@ namespace Hotfix
 				// 在map服务器上创建战斗Unit
 				IPEndPoint mapAddress = Game.Scene.GetComponent<StartConfigComponent>().MapConfigs[0].GetComponent<InnerConfig>().IPEndPoint;
 				Session mapSession = Game.Scene.GetComponent<NetInnerComponent>().Get(mapAddress);
-				M2G_CreateUnit createUnit = await mapSession.Call<M2G_CreateUnit>(new G2M_CreateUnit() { PlayerId = player.Id, GateSessionId = session.Id });
+				M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit() { PlayerId = player.Id, GateSessionId = session.Id });
 				player.UnitId = createUnit.UnitId;
 				response.UnitId = createUnit.UnitId;
 				response.Count = createUnit.Count;

+ 1 - 1
Server/Hotfix/Handler/C2M_ReloadHandler.cs

@@ -21,7 +21,7 @@ namespace Hotfix
 					}
 					InnerConfig innerConfig = startConfig.GetComponent<InnerConfig>();
 					Session serverSession = netInnerComponent.Get(innerConfig.IPEndPoint);
-					await serverSession.Call<A2M_Reload>(new M2A_Reload());
+					await serverSession.Call(new M2A_Reload());
 				}
 				reply(response);
 			}

+ 1 - 1
Server/Hotfix/Handler/C2R_LoginHandler.cs

@@ -28,7 +28,7 @@ namespace Hotfix
 				Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
 
 				// 向gate请求一个key,客户端可以拿着这个key连接gate
-				G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call<G2R_GetLoginKey>(new R2G_GetLoginKey() {Account = message.Account});
+				G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey() {Account = message.Account});
 
 				string outerAddress = config.GetComponent<OuterConfig>().IPEndPoint2.ToString();
 

+ 1 - 1
Server/Model/Component/BenchmarkComponent.cs

@@ -63,7 +63,7 @@ namespace Model
 		{
 			try
 			{
-				await session.Call<R2C_Ping>(new C2R_Ping());
+				await session.Call(new C2R_Ping());
 				++this.k;
 
 				if (this.k % 100000 != 0)

+ 2 - 2
Server/Model/Component/Unit/LockComponent.cs

@@ -84,7 +84,7 @@ namespace Model
 				Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.address);
 				string serverAddress = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.ServerIP;
 				G2G_LockRequest request = new G2G_LockRequest { Id = this.Parent.Id, Address = serverAddress };
-				await session.Call<G2G_LockResponse>(request);
+				await session.Call(request);
 
 				this.status = LockStatus.Locked;
 
@@ -111,7 +111,7 @@ namespace Model
 			this.status = LockStatus.LockedNot;
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.address);
 			G2G_LockReleaseRequest request = new G2G_LockReleaseRequest();
-			await session.Call<G2G_LockReleaseResponse>(request);
+			await session.Call(request);
 		}
 	}
 }

+ 1 - 1
Server/Model/Module/Actor/ActorProxy.cs

@@ -302,7 +302,7 @@ namespace Model
 				//Log.Debug($"realcall {MongoHelper.ToJson(request)} {this.Address}");
 				request.Id = this.Id;
 				Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.Address);
-				Response response = await session.Call<Response>(request, cancellationToken);
+				Response response = (Response)await session.Call(request, cancellationToken);
 				return response;
 			}
 			catch (RpcException e)

+ 7 - 7
Server/Model/Module/DB/DBProxyComponent.cs

@@ -30,31 +30,31 @@ namespace Model
 		public async Task Save(Disposer disposer, bool needCache = true)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
-			await session.Call<DBSaveResponse>(new DBSaveRequest { Disposer = disposer, NeedCache = needCache});
+			await session.Call(new DBSaveRequest { Disposer = disposer, NeedCache = needCache});
 		}
 
 		public async Task SaveBatch(List<Disposer> disposers, bool needCache = true)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
-			await session.Call<DBSaveBatchResponse>(new DBSaveBatchRequest { Disposers = disposers, NeedCache = needCache});
+			await session.Call(new DBSaveBatchRequest { Disposers = disposers, NeedCache = needCache});
 		}
 
 		public async Task Save(Disposer disposer, bool needCache, CancellationToken cancellationToken)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
-			await session.Call<DBSaveResponse>(new DBSaveRequest { Disposer = disposer, NeedCache = needCache}, cancellationToken);
+			await session.Call(new DBSaveRequest { Disposer = disposer, NeedCache = needCache}, cancellationToken);
 		}
 
 		public async void SaveLog(Disposer disposer)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
-			await session.Call<DBSaveResponse>(new DBSaveRequest { Disposer = disposer,  NeedCache = false, CollectionName = "Log" });
+			await session.Call(new DBSaveRequest { Disposer = disposer,  NeedCache = false, CollectionName = "Log" });
 		}
 
 		public async Task<T> Query<T>(long id, bool needCache = true) where T: Entity
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
-			DBQueryResponse dbQueryResponse = await session.Call<DBQueryResponse>(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache });
+			DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache });
 			return (T)dbQueryResponse.Disposer;
 		}
 
@@ -62,7 +62,7 @@ namespace Model
 		{
 			List<T> list = new List<T>();
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
-			DBQueryBatchResponse dbQueryBatchResponse = await session.Call<DBQueryBatchResponse>(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids, NeedCache = needCache});
+			DBQueryBatchResponse dbQueryBatchResponse = (DBQueryBatchResponse)await session.Call(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids, NeedCache = needCache});
 			foreach (Disposer disposer in dbQueryBatchResponse.Disposers)
 			{
 				list.Add((T)disposer);
@@ -74,7 +74,7 @@ namespace Model
 		{
 			List<T> list = new List<T>();
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
-			DBQueryJsonResponse dbQueryJsonResponse = await session.Call<DBQueryJsonResponse>(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json, NeedCache = needCache});
+			DBQueryJsonResponse dbQueryJsonResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json, NeedCache = needCache});
 			foreach (Disposer disposer in dbQueryJsonResponse.Disposers)
 			{
 				list.Add((T)disposer);

+ 5 - 5
Server/Model/Module/Location/LocationProxyComponent.cs

@@ -30,31 +30,31 @@ namespace Model
 		public async Task Add(long key)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
-			await session.Call<ObjectAddResponse>(new ObjectAddRequest() { Key = key, AppId = this.AppId });
+			await session.Call(new ObjectAddRequest() { Key = key, AppId = this.AppId });
 		}
 
 		public async Task Lock(long key, int time = 1000)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
-			await session.Call<ObjectLockResponse>(new ObjectLockRequest() { Key = key, LockAppId = this.AppId, Time = time });
+			await session.Call(new ObjectLockRequest() { Key = key, LockAppId = this.AppId, Time = time });
 		}
 
 		public async Task UnLock(long key, int value)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
-			await session.Call<ObjectUnLockResponse>(new ObjectUnLockRequest() { Key = key, UnLockAppId = this.AppId, AppId = value});
+			await session.Call(new ObjectUnLockRequest() { Key = key, UnLockAppId = this.AppId, AppId = value});
 		}
 
 		public async Task Remove(long key)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
-			await session.Call<ObjectRemoveResponse>(new ObjectRemoveRequest() { Key = key });
+			await session.Call(new ObjectRemoveRequest() { Key = key });
 		}
 
 		public async Task<int> Get(long key)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
-			ObjectGetResponse response = await session.Call<ObjectGetResponse>(new ObjectGetRequest() { Key = key });
+			ObjectGetResponse response = (ObjectGetResponse)await session.Call(new ObjectGetRequest() { Key = key });
 			return response.AppId;
 		}
 

+ 2 - 72
Unity/Assets/Scripts/Entity/Session.cs

@@ -162,7 +162,7 @@ namespace Model
 		/// <summary>
 		/// Rpc调用,发送一个消息,等待返回一个消息
 		/// </summary>
-		public Task<AResponse> Call(ARequest request, bool isHotfix)
+		public Task<AResponse> Call(ARequest request)
 		{
 			request.RpcId = ++RpcId;
 
@@ -193,7 +193,7 @@ namespace Model
 		/// <summary>
 		/// Rpc调用
 		/// </summary>
-		public Task<AResponse> Call(ARequest request, bool isHotfix, CancellationToken cancellationToken)
+		public Task<AResponse> Call(ARequest request, CancellationToken cancellationToken)
 		{
 			request.RpcId = ++RpcId;
 			
@@ -225,76 +225,6 @@ namespace Model
 			return tcs.Task;
 		}
 
-		/// <summary>
-		/// Rpc调用,发送一个消息,等待返回一个消息
-		/// </summary>
-		public Task<Response> Call<Response>(ARequest request) where Response : AResponse
-		{
-			request.RpcId = ++RpcId;
-			
-			var tcs = new TaskCompletionSource<Response>();
-			this.requestCallback[request.RpcId] = (message) =>
-			{
-				try
-				{
-					AResponse response = (AResponse)message;
-					if (response.Error > 100)
-					{
-						tcs.SetException(new RpcException(response.Error, response.Message));
-						return;
-					}
-
-					//Log.Debug($"recv: {MongoHelper.ToJson(response)}");
-					tcs.SetResult((Response)response);
-				}
-				catch (Exception e)
-				{
-					tcs.SetException(new Exception($"Rpc Error: {typeof(Response).FullName}", e));
-				}
-			};
-
-			this.SendMessage(request);
-
-			return tcs.Task;
-		}
-
-		/// <summary>
-		/// Rpc调用
-		/// </summary>
-		public Task<Response> Call<Response>(ARequest request, CancellationToken cancellationToken)
-			where Response : AResponse
-		{
-			request.RpcId = ++RpcId;
-			
-			var tcs = new TaskCompletionSource<Response>();
-
-			this.requestCallback[request.RpcId] = (message) =>
-			{
-				try
-				{
-					AResponse response = (AResponse)message;
-					if (response.Error > 100)
-					{
-						tcs.SetException(new RpcException(response.Error, response.Message));
-						return;
-					}
-
-					//Log.Debug($"recv: {MongoHelper.ToJson(response)}");
-					tcs.SetResult((Response)response);
-				}
-				catch (Exception e)
-				{
-					tcs.SetException(new Exception($"Rpc Error: {typeof(Response).FullName}", e));
-				}
-			};
-
-			cancellationToken.Register(() => { this.requestCallback.Remove(request.RpcId); });
-
-			this.SendMessage(request);
-
-			return tcs.Task;
-		}
-
 		public void Send(AMessage message)
 		{
 			if (this.Id == 0)

+ 4 - 4
Unity/Hotfix/UI/UILobby/Component/UILobbyComponent.cs

@@ -50,7 +50,7 @@ namespace Hotfix
 			{
 				// 向actor发起一次rpc调用
 				Actor_TestResponse response = (Actor_TestResponse) await SessionComponent.Instance.Session.Call(
-					new Actor_TestRequest() { request = "request actor test rpc" }, true);
+					new Actor_TestRequest() { request = "request actor test rpc" });
 				Log.Info($"recv response: {MongoHelper.ToJson(response)}");
 			}
 			catch (Exception e)
@@ -64,7 +64,7 @@ namespace Hotfix
 			try
 			{
 				Actor_TransferResponse response = (Actor_TransferResponse) await SessionComponent.Instance.Session.Call(
-					new Actor_TransferRequest() {MapIndex = 0}, true);
+					new Actor_TransferRequest() {MapIndex = 0});
 				Log.Info($"传送成功! {MongoHelper.ToJson(response)}");
 			}
 			catch (Exception e)
@@ -76,7 +76,7 @@ namespace Hotfix
 		private async void OnTransfer2()
 		{
 			Actor_TransferResponse response = (Actor_TransferResponse)await SessionComponent.Instance.Session.Call(
-				new Actor_TransferRequest() { MapIndex = 1 }, true);
+				new Actor_TransferRequest() { MapIndex = 1 });
 			Log.Info($"传送成功! {MongoHelper.ToJson(response)}");
 		}
 
@@ -84,7 +84,7 @@ namespace Hotfix
 		{
 			try
 			{
-				G2C_EnterMap g2CEnterMap = (G2C_EnterMap)await SessionComponent.Instance.Session.Call(new C2G_EnterMap(), true);
+				G2C_EnterMap g2CEnterMap = (G2C_EnterMap)await SessionComponent.Instance.Session.Call(new C2G_EnterMap());
 				Hotfix.Scene.GetComponent<UIComponent>().Remove(UIType.UILobby);
 			}
 			catch (Exception e)

+ 5 - 7
Unity/Hotfix/UI/UILogin/Component/UILoginComponent.cs

@@ -33,22 +33,20 @@ namespace Hotfix
 			try
 			{
 				IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
-				Session session = Game.Scene.GetComponent<NetOuterComponent>().Create(connetEndPoint);
-				string text = this.account.GetComponent<InputField>().text;
 
+				string text = this.account.GetComponent<InputField>().text;
 
-				R2C_Login r2CLogin = (R2C_Login)await session.Call(new C2R_Login() { Account = text, Password = "111111" }, true);
-				if (r2CLogin.Error != ErrorCode.ERR_Success)
+				R2C_Login r2CLogin;
+				using (Session session = Game.Scene.GetComponent<NetOuterComponent>().Create(connetEndPoint))
 				{
-					Log.Error(r2CLogin.Error.ToString());
-					return;
+					r2CLogin = (R2C_Login) await session.Call(new C2R_Login() { Account = text, Password = "111111" });
 				}
 
 				connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
 				Session gateSession = Game.Scene.GetComponent<NetOuterComponent>().Create(connetEndPoint);
 				Game.Scene.AddComponent<SessionComponent>().Session = gateSession;
 
-				G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }, true);
+				G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key });
 
 				Log.Info("登陆gate成功!");