diff --git a/Unity/Assets/Scripts/Component/NetworkComponent.cs b/Unity/Assets/Scripts/Component/NetworkComponent.cs index 345f4bca5b87cf560f4164ea9f5882b2deaef8fd..212aff717694ff90f8dd52678e37a19962a167d6 100644 --- a/Unity/Assets/Scripts/Component/NetworkComponent.cs +++ b/Unity/Assets/Scripts/Component/NetworkComponent.cs @@ -71,16 +71,11 @@ namespace Model Session session = new Session(this.GetOwner(), channel); channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; - this.Add(session); + this.sessions.Add(session.Id, session); + this.AddToAddressDict(session); } } - - private void Add(Session session) - { - this.sessions.Add(session.Id, session); - this.AddToAddressDict(session); - } - + private void AddToAddressDict(Session session) { Session s; @@ -123,15 +118,15 @@ namespace Model return session; } - session = this.GetNew(address); + session = this.Create(address); this.AddToAddressDict(session); return session; } /// - /// 创建一个新Session,不保存到地址缓存中 + /// 创建一个新Session /// - public Session GetNew(string address) + public Session Create(string address) { string[] ss = address.Split(':'); int port = int.Parse(ss[1]); @@ -139,6 +134,7 @@ namespace Model AChannel channel = this.Service.ConnectChannel(host, port); Session session = new Session(this.GetOwner(), channel); channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; + this.sessions.Add(session.Id, session); return session; }