ソースを参照

接收的Session不需要缓存到地址列表

tanghai 9 年 前
コミット
5a35284433

+ 0 - 1
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Reflection;
 using Base;
-using Object = Model.Object;
 
 namespace Model
 {

+ 1 - 20
Unity/Assets/Scripts/Component/NetInnerComponent.cs

@@ -1,5 +1,4 @@
 using System.Collections.Generic;
-using System.Threading.Tasks;
 using Base;
 
 namespace Model
@@ -38,24 +37,6 @@ namespace Model
 			this.Awake(NetworkProtocol.TCP, host, port);
 		}
 
-		protected override async Task<Session> Accept()
-		{
-			Session session = await base.Accept();
-			this.AddToAddressDict(session);
-			return session;
-		}
-
-		private void AddToAddressDict(Session session)
-		{
-			Session s;
-			if (this.adressSessions.TryGetValue(session.RemoteAddress, out s))
-			{
-				this.Remove(s.Id);
-				Log.Warning($"session 地址冲突, 可能是客户端断开, 服务器还没检测到!: {session.RemoteAddress}");
-			}
-			this.adressSessions.Add(session.RemoteAddress, session);
-		}
-
 		public override void Remove(long id)
 		{
 			Session session = this.Get(id);
@@ -80,7 +61,7 @@ namespace Model
 			}
 
 			session = this.Create(address);
-			this.AddToAddressDict(session);
+			this.adressSessions.Add(address, session);
 			return session;
 		}
 	}

+ 1 - 1
Unity/Assets/Scripts/Component/NetworkComponent.cs

@@ -57,7 +57,7 @@ namespace Model
 			}
 		}
 
-		protected virtual async Task<Session> Accept()
+		private async Task<Session> Accept()
 		{
 
 			AChannel channel = await this.Service.AcceptChannel();

+ 2 - 2
Unity/Assets/Scripts/Config/AConfig.cs

@@ -5,11 +5,11 @@
 	/// </summary>
 	public abstract class AConfig: Entity
 	{
-		public AConfig(EntityType entityType): base(entityType)
+		protected AConfig(EntityType entityType): base(entityType)
 		{
 		}
 
-		public AConfig(long id, EntityType entityType): base(id, entityType)
+		protected AConfig(long id, EntityType entityType): base(id, entityType)
 		{
 		}
 	}

+ 0 - 1
Unity/Assets/Scripts/Object/EntityType.cs

@@ -7,6 +7,5 @@
 		Session,
 		UI,
 		Config,
-		Network,
 	}
 }

+ 7 - 18
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs

@@ -19,27 +19,16 @@ namespace Controller
 				NetOuterComponent networkComponent = Game.Scene.AddComponent<NetOuterComponent>();
 				using (Session session = networkComponent.Create(clientConfig.Address))
 				{
-					try
-					{
-						R2C_Login s2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login { Account = "abcdef", Password = "111111" });
-						networkComponent.Remove(session.Id);
+					R2C_Login s2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login { Account = "abcdef", Password = "111111" });
+					networkComponent.Remove(session.Id);
 
-						// 连接Gate
-						using (Session gateSession = networkComponent.Create(s2CLogin.Address))
-						{
-							await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
-						}
-						
-						Log.Info("连接Gate验证成功!");
-					}
-					catch (RpcException e)
-					{
-						Log.Error(e.ToString());
-					}
-					catch (Exception e)
+					// 连接Gate
+					using (Session gateSession = networkComponent.Create(s2CLogin.Address))
 					{
-						Log.Error(e.ToString());
+						await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
 					}
+					
+					Log.Info("连接Gate验证成功!");
 				}
 			}
 			catch (Exception e)