diff --git a/Client-Server.sln b/Client-Server.sln index 6c1bac69b0b4beae3f963c2df9fe4a2b88281208..ebeb19e0fede6367c8f9a2e947dc4d6393c1b6ff 100644 --- a/Client-Server.sln +++ b/Client-Server.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27004.2009 +VisualStudioVersion = 15.0.27130.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Plugins", "Unity\Unity.Plugins.csproj", "{D1FDB199-0FB7-099D-3771-C6A942E4E326}" EndProject diff --git a/Server/Hotfix/Handler/G2G_LockRequestHandler.cs b/Server/Hotfix/Handler/G2G_LockRequestHandler.cs index 14567165e733b993cbd4d275524949fbb50f2c46..3e1c861fa0f95492cc7dfca04fc08024d6edf73c 100644 --- a/Server/Hotfix/Handler/G2G_LockRequestHandler.cs +++ b/Server/Hotfix/Handler/G2G_LockRequestHandler.cs @@ -16,6 +16,7 @@ namespace Hotfix { response.Error = ErrorCode.ERR_NotFoundUnit; reply(response); + return; } await unit.GetComponent().Lock(message.Address); diff --git a/Server/Hotfix/System/NetOuterComponentSystem.cs b/Server/Hotfix/System/NetOuterComponentSystem.cs index f32e903d5bdd1e4756ed470a2de069cc202fbea2..f995364e81dcf7bac1082eaabc45f25cbd25e8fa 100644 --- a/Server/Hotfix/System/NetOuterComponentSystem.cs +++ b/Server/Hotfix/System/NetOuterComponentSystem.cs @@ -26,14 +26,14 @@ namespace Hotfix { public static void Awake(this NetOuterComponent self) { - self.Awake(NetworkProtocol.TCP); + self.Awake(NetworkProtocol.KCP); self.MessagePacker = new ProtobufPacker(); self.MessageDispatcher = new OuterMessageDispatcher(); } public static void Awake(this NetOuterComponent self, IPEndPoint ipEndPoint) { - self.Awake(NetworkProtocol.TCP, ipEndPoint); + self.Awake(NetworkProtocol.KCP, ipEndPoint); self.MessagePacker = new ProtobufPacker(); self.MessageDispatcher = new OuterMessageDispatcher(); } diff --git a/Server/Model/Component/ActorProxyComponent.cs b/Server/Model/Component/ActorProxyComponent.cs index d0d41192b03015cd185290b6fce62a0993a4adc5..d5767ba07cf3dd64e54e2ead1f6e1f57fdc78434 100644 --- a/Server/Model/Component/ActorProxyComponent.cs +++ b/Server/Model/Component/ActorProxyComponent.cs @@ -5,7 +5,7 @@ namespace Model [ObjectEvent] public class ActorProxyComponentEvent : ObjectEvent, IStart { - // 每分钟扫描一次过期的actorproxy进行回收,过期时间是5分钟 + // 每10s扫描一次过期的actorproxy进行回收,过期时间是1分钟 public async void Start() { ActorProxyComponent self = this.Get(); @@ -14,7 +14,7 @@ namespace Model while (true) { - await Game.Scene.GetComponent().WaitAsync(60000); + await Game.Scene.GetComponent().WaitAsync(1000); if (self.Id == 0) { @@ -32,7 +32,7 @@ namespace Model continue; } - if (timeNow < actorProxy.LastSendTime + 5 * 60000) + if (timeNow < actorProxy.LastSendTime + 10000) { continue; } @@ -52,6 +52,20 @@ namespace Model { public readonly Dictionary ActorProxys = new Dictionary(); + public override void Dispose() + { + if (this.Id == 0) + { + return; + } + base.Dispose(); + foreach (ActorProxy actorProxy in this.ActorProxys.Values) + { + actorProxy.Dispose(); + } + this.ActorProxys.Clear(); + } + public ActorProxy Get(long id) { if (this.ActorProxys.TryGetValue(id, out ActorProxy actorProxy)) diff --git a/Server/Model/Component/BenchmarkComponent.cs b/Server/Model/Component/BenchmarkComponent.cs index 12a02220dae9b8ea5b16836cb4da6b7debfdb5c7..99e55ab3ad50006dc70784225bb9812cd7bce0e9 100644 --- a/Server/Model/Component/BenchmarkComponent.cs +++ b/Server/Model/Component/BenchmarkComponent.cs @@ -26,7 +26,7 @@ namespace Model NetOuterComponent networkComponent = Game.Scene.GetComponent(); for (int i = 0; i < 1000; i++) { - await Game.Scene.GetComponent().WaitAsync(1000); + await Game.Scene.GetComponent().WaitAsync(100); this.TestAsync(networkComponent, ipEndPoint, i); } } @@ -43,7 +43,7 @@ namespace Model using (Session session = networkComponent.Create(ipEndPoint)) { int i = 0; - while (i < 1000000000) + while (i < 100000000) { ++i; await this.Send(session, j); diff --git a/Server/Model/Entity/ActorProxy.cs b/Server/Model/Entity/ActorProxy.cs index 11fc98bd87f9c4e905f7b9345b271037a5807ae2..9611c97cbb33dfd560811dd47db5fb5d0eadab86 100644 --- a/Server/Model/Entity/ActorProxy.cs +++ b/Server/Model/Entity/ActorProxy.cs @@ -123,16 +123,45 @@ namespace Model this.tcs = null; this.CancellationTokenSource = new CancellationTokenSource(); } - - public void Start() + + public override void Dispose() + { + if (this.Id == 0) + { + return; + } + + base.Dispose(); + this.LastSendTime = 0; + this.Address = null; + this.RunningTasks.Clear(); + this.WaitingTasks.Clear(); + this.failTimes = 0; + var t = this.tcs; + this.tcs = null; + t?.SetResult(null); + } + + public async void Start() { + int appId = await Game.Scene.GetComponent().Get(this.Id); + this.Address = Game.Scene.GetComponent().Get(appId).GetComponent().Address; + this.UpdateAsync(); } private void Add(ActorTask task) { + if (this.Id == 0) + { + throw new Exception("ActorProxy Disposed! dont hold actorproxy"); + } this.WaitingTasks.Enqueue(task); - this.AllowGet(); + // failtimes > 0表示正在重试,这时候不能加到正在发送队列 + if (this.failTimes == 0) + { + this.AllowGet(); + } } private void Remove() @@ -147,8 +176,7 @@ namespace Model { return; } - - + ActorTask task = this.WaitingTasks.Dequeue(); this.RunningTasks.Enqueue(task); @@ -172,18 +200,13 @@ namespace Model private async void UpdateAsync() { - if (this.Address == null) - { - int appId = await Game.Scene.GetComponent().Get(this.Id); - this.Address = Game.Scene.GetComponent().Get(appId).GetComponent().Address; - } while (true) { + ActorTask actorTask = await this.GetAsync(); if (this.Id == 0) { return; } - ActorTask actorTask = await this.GetAsync(); if (actorTask == null) { return; @@ -233,7 +256,6 @@ namespace Model Game.Scene.GetComponent().Remove(this.Id); return; } - // 等待一会再发送 await Game.Scene.GetComponent().WaitAsync(this.failTimes * 500); int appId = await Game.Scene.GetComponent().Get(this.Id); @@ -244,6 +266,7 @@ namespace Model } // 发送成功 + this.LastSendTime = TimeHelper.Now(); this.failTimes = 0; if (this.WindowSize < MaxWindowSize) { @@ -259,14 +282,12 @@ namespace Model public void Send(AMessage message) { - this.LastSendTime = TimeHelper.Now(); ActorMessageTask task = new ActorMessageTask(this, message); this.Add(task); } public Task Call(ARequest request)where Response : AResponse { - this.LastSendTime = TimeHelper.Now(); ActorRpcTask task = new ActorRpcTask(this, request); this.Add(task); return task.Tcs.Task; @@ -298,24 +319,5 @@ namespace Model } return s; } - - public override void Dispose() - { - if (this.Id == 0) - { - return; - } - - base.Dispose(); - - this.LastSendTime = 0; - this.Address = ""; - this.RunningTasks.Clear(); - this.WaitingTasks.Clear(); - this.failTimes = 0; - var t = this.tcs; - this.tcs = null; - t?.SetResult(null); - } } } \ No newline at end of file diff --git a/Unity/Assets/Scripts/Base/MultiMap.cs b/Unity/Assets/Scripts/Base/MultiMap.cs index 245a8e7ac2687c1c328e8d8a7fa32d8adafbc336..781037371b4f2755620d5265aa634cbc8e6f400d 100644 --- a/Unity/Assets/Scripts/Base/MultiMap.cs +++ b/Unity/Assets/Scripts/Base/MultiMap.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace Model { @@ -9,12 +10,9 @@ namespace Model // 重用list private readonly Queue> queue = new Queue>(); - public SortedDictionary>.KeyCollection Keys + public SortedDictionary> GetDictionary() { - get - { - return this.dictionary.Keys; - } + return this.dictionary; } public void Add(T t, K k) @@ -29,6 +27,19 @@ namespace Model this.dictionary[t] = list; } + public KeyValuePair> First() + { + return this.dictionary.First(); + } + + public int Count + { + get + { + return this.dictionary.Count; + } + } + private List FetchList() { if (this.queue.Count > 0) diff --git a/Unity/Assets/Scripts/Base/Network/AService.cs b/Unity/Assets/Scripts/Base/Network/AService.cs index 4a15693b0cd562dd86a47b7e35d145bdafddb22b..cde26a1d6d2ebecf3751388446a6295f1342dfda 100644 --- a/Unity/Assets/Scripts/Base/Network/AService.cs +++ b/Unity/Assets/Scripts/Base/Network/AService.cs @@ -13,8 +13,6 @@ namespace Model public abstract class AService: IDisposable { - public abstract void Add(Action action); - public abstract AChannel GetChannel(long id); public abstract Task AcceptChannel(); diff --git a/Unity/Assets/Scripts/Base/Network/KNet/KChannel.cs b/Unity/Assets/Scripts/Base/Network/KNet/KChannel.cs index 6797c5dc7806d6d7bb64f54bfe9067822814dd48..5632bc690ff749c53c50224597559ee4cb3ce0e8 100644 --- a/Unity/Assets/Scripts/Base/Network/KNet/KChannel.cs +++ b/Unity/Assets/Scripts/Base/Network/KNet/KChannel.cs @@ -143,9 +143,7 @@ namespace Model this.OnError(this, SocketError.Disconnecting); return; } - this.kcp.Update(timeNow); - uint nextUpdateTime = this.kcp.Check(timeNow); this.GetService().AddToNextTimeUpdate(nextUpdateTime, this.Id); } diff --git a/Unity/Assets/Scripts/Base/Network/KNet/KService.cs b/Unity/Assets/Scripts/Base/Network/KNet/KService.cs index 9a4ffe3efd08fcc8724881fac178a9c5bfcf3657..6ceb9d425de4938fd6fb0f1fde5c2375bb021a08 100644 --- a/Unity/Assets/Scripts/Base/Network/KNet/KService.cs +++ b/Unity/Assets/Scripts/Base/Network/KNet/KService.cs @@ -33,7 +33,6 @@ namespace Model // 下次时间更新的channel private readonly MultiMap timerMap = new MultiMap(); - private readonly Queue timeoutTimer = new Queue(); public KService(IPEndPoint ipEndPoint) { @@ -211,11 +210,7 @@ namespace Model { this.timerMap.Add(time, id); } - - public override void Add(Action action) - { - } - + public override AChannel GetChannel(long id) { KChannel channel; @@ -254,26 +249,25 @@ namespace Model public override void Update() { this.TimeNow = (uint)TimeHelper.Now(); - - foreach (long time in this.timerMap.Keys) + + while (true) { - if (time > this.TimeNow) + if (this.timerMap.Count <= 0) { break; } - this.timeoutTimer.Enqueue(time); - } - while (this.timeoutTimer.Count > 0) - { - long key = this.timeoutTimer.Dequeue(); - List timeOutId = this.timerMap[key]; + var kv = this.timerMap.First(); + if (kv.Key > TimeNow) + { + break; + } + List timeOutId = kv.Value; foreach (long id in timeOutId) { this.updateChannels.Add(id); } - this.timerMap.Remove(key); + this.timerMap.Remove(kv.Key); } - foreach (long id in updateChannels) { KChannel kChannel; diff --git a/Unity/Assets/Scripts/Base/Network/TNet/TService.cs b/Unity/Assets/Scripts/Base/Network/TNet/TService.cs index 8d967900783cde46914d185d2f23b1a815457732..279096a88208944bd5548bdbd342ee7ebefee686 100644 --- a/Unity/Assets/Scripts/Base/Network/TNet/TService.cs +++ b/Unity/Assets/Scripts/Base/Network/TNet/TService.cs @@ -43,12 +43,7 @@ namespace Model this.acceptor.Stop(); this.acceptor = null; } - - public override void Add(Action action) - { - this.actions.Enqueue(action); - } - + public override AChannel GetChannel(long id) { TChannel channel = null; diff --git a/Unity/Assets/Scripts/Base/Network/UNet/UService.cs b/Unity/Assets/Scripts/Base/Network/UNet/UService.cs index 4239da7236b9fa87fc9c8f1cb175d26cc70be3a9..0e07c160704c07f32f7fd8225ddc180daadc927d 100644 --- a/Unity/Assets/Scripts/Base/Network/UNet/UService.cs +++ b/Unity/Assets/Scripts/Base/Network/UNet/UService.cs @@ -60,10 +60,6 @@ namespace Model return channel; } - public override void Add(Action action) - { - } - public override AChannel GetChannel(long id) { UChannel channel = null; diff --git a/Unity/Assets/Scripts/Component/NetOuterComponent.cs b/Unity/Assets/Scripts/Component/NetOuterComponent.cs index 9201a088cb3b1e1d6abc5965980ec61c9cf737c2..d8573afe58fccf330400ffe894c5ae084dc916da 100644 --- a/Unity/Assets/Scripts/Component/NetOuterComponent.cs +++ b/Unity/Assets/Scripts/Component/NetOuterComponent.cs @@ -18,7 +18,7 @@ { public void Awake() { - this.Awake(NetworkProtocol.TCP); + this.Awake(NetworkProtocol.KCP); this.MessagePacker = new ProtobufPacker(); this.MessageDispatcher = new ClientDispatcher(); } diff --git a/Unity/Assets/Scripts/Component/TimerComponent.cs b/Unity/Assets/Scripts/Component/TimerComponent.cs index 0a11067b77e72421022cf39e1369b5ca3e4f1338..eaa9bbc022aab50f51b7ee92896dcf89db909215 100644 --- a/Unity/Assets/Scripts/Component/TimerComponent.cs +++ b/Unity/Assets/Scripts/Component/TimerComponent.cs @@ -20,7 +20,7 @@ namespace Model } } - public class TimerComponent: Component + public class TimerComponent : Component { private readonly Dictionary timers = new Dictionary(); @@ -29,24 +29,23 @@ namespace Model /// private readonly MultiMap timeId = new MultiMap(); - private readonly EQueue timeoutTimer = new EQueue(); - public void Update() { long timeNow = TimeHelper.Now(); - foreach (long time in this.timeId.Keys) + + while (true) { - if (time > timeNow) + if (this.timeId.Count <= 0) + { + return; + } + var kv = this.timeId.First(); + if (kv.Key > timeNow) { break; } - this.timeoutTimer.Enqueue(time); - } - while (this.timeoutTimer.Count > 0) - { - long key = this.timeoutTimer.Dequeue(); - List timeOutId = this.timeId[key]; + List timeOutId = kv.Value; foreach (long id in timeOutId) { Timer timer; @@ -56,7 +55,8 @@ namespace Model } timer.tcs.SetResult(true); } - this.timeId.Remove(key); + + this.timeId.Remove(kv.Key); } } diff --git a/Unity/Unity.Editor.Plugins.csproj b/Unity/Unity.Editor.Plugins.csproj index 2096447b4d151f134d17c6017db0c9e9c5e59ea0..664dcaebf609fb3576044e6b297032a5103bbf7c 100644 --- a/Unity/Unity.Editor.Plugins.csproj +++ b/Unity/Unity.Editor.Plugins.csproj @@ -7,7 +7,7 @@ 2.0 {81A6E58E-BFF2-F1C8-1C4E-6316985F642C} Library - Assembly-CSharp-Editor-firstpass.dll + Assembly-CSharp-Editor-firstpass 512 {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} .NETFramework diff --git a/Unity/Unity.Editor.csproj b/Unity/Unity.Editor.csproj index 19d3a030eeb6f0a7fe0007f3333ed1a31aadd8dd..27d89505897d434bc1ab45528d1d5a1eeaba7c6c 100644 --- a/Unity/Unity.Editor.csproj +++ b/Unity/Unity.Editor.csproj @@ -7,7 +7,7 @@ 2.0 {C17F48D3-964E-E97C-3D2E-966F7A6C6D93} Library - Assembly-CSharp-Editor.dll + Assembly-CSharp-Editor 512 {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} .NETFramework diff --git a/Unity/Unity.Plugins.csproj b/Unity/Unity.Plugins.csproj index 9064160768c0cb568ece608edd94e510e6b92140..e9003121d837f7cc8d3009dc3580b94cf787bd81 100644 --- a/Unity/Unity.Plugins.csproj +++ b/Unity/Unity.Plugins.csproj @@ -7,7 +7,7 @@ 2.0 {D1FDB199-0FB7-099D-3771-C6A942E4E326} Library - Assembly-CSharp-firstpass.dll + Assembly-CSharp-firstpass 512 {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} .NETFramework diff --git a/Unity/Unity.csproj b/Unity/Unity.csproj index 0f35f62cd878204721cca496dc312db74d6dd406..326e9efd05097e9e48b9261e5c101e72e922ec26 100644 --- a/Unity/Unity.csproj +++ b/Unity/Unity.csproj @@ -7,20 +7,17 @@ 2.0 {CF118143-7E37-744F-BE45-3F55345FEC40} Library - Assembly-CSharp.dll + Assembly-CSharp 512 {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} .NETFramework v4.6 - - - - + + Game:1 iOS:9 2017.1.1p4 - - + 6 @@ -587,4 +584,4 @@ - \ No newline at end of file +