diff --git a/Server/App/Program.cs b/Server/App/Program.cs index 99bc34f2930d8e40e066819a10a550529bbb64ff..ff1184c42a9f20c80ff38a68aaaf231e94521414 100644 --- a/Server/App/Program.cs +++ b/Server/App/Program.cs @@ -105,7 +105,7 @@ namespace App break; case AppType.Benchmark: Game.Scene.AddComponent(); - Game.Scene.AddComponent(clientConfig.Address); + Game.Scene.AddComponent(clientConfig.IPEndPoint); break; default: throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}"); diff --git a/Server/Model/Component/BenchmarkComponent.cs b/Server/Model/Component/BenchmarkComponent.cs index 43ae287a1a41976005520f24041e6b28dbe8129f..12a02220dae9b8ea5b16836cb4da6b7debfdb5c7 100644 --- a/Server/Model/Component/BenchmarkComponent.cs +++ b/Server/Model/Component/BenchmarkComponent.cs @@ -24,7 +24,7 @@ namespace Model try { NetOuterComponent networkComponent = Game.Scene.GetComponent(); - for (int i = 0; i < 100; i++) + for (int i = 0; i < 1000; i++) { await Game.Scene.GetComponent().WaitAsync(1000); this.TestAsync(networkComponent, ipEndPoint, i); @@ -43,10 +43,9 @@ namespace Model using (Session session = networkComponent.Create(ipEndPoint)) { int i = 0; - while (i < 100000000) + while (i < 1000000000) { ++i; - await Game.Scene.GetComponent().WaitAsync(10); await this.Send(session, j); } } @@ -68,7 +67,7 @@ namespace Model await session.Call(new C2R_Ping()); ++this.k; - if (this.k % 10000 != 0) + if (this.k % 100000 != 0) { return; } diff --git a/Server/Model/Component/Config/ClientConfig.cs b/Server/Model/Component/Config/ClientConfig.cs index 81455fd1bd8cd496d2ed230dbe6d3d93a36e2f19..4616a70596d469c67d5179dd438f0ee89977c3dc 100644 --- a/Server/Model/Component/Config/ClientConfig.cs +++ b/Server/Model/Component/Config/ClientConfig.cs @@ -1,4 +1,5 @@ -using MongoDB.Bson.Serialization.Attributes; +using System.Net; +using MongoDB.Bson.Serialization.Attributes; namespace Model { @@ -16,5 +17,14 @@ namespace Model return $"{this.Host}:{this.Port}"; } } + + [BsonIgnore] + public IPEndPoint IPEndPoint + { + get + { + return NetworkHelper.ToIPEndPoint(this.Host, this.Port); + } + } } } \ No newline at end of file diff --git a/Unity/Assets/Scripts/Entity/Message/OuterMessage.cs b/Unity/Assets/Scripts/Entity/Message/OuterMessage.cs index 3df8aba58b7f96f6a24ed72207b07abdda07f7b3..18a701005aa1022afd8ae7d5735195efc05fcb17 100644 --- a/Unity/Assets/Scripts/Entity/Message/OuterMessage.cs +++ b/Unity/Assets/Scripts/Entity/Message/OuterMessage.cs @@ -13,6 +13,7 @@ namespace Model [ProtoInclude((int)Opcode.C2R_Login, typeof(C2R_Login))] [ProtoInclude((int)Opcode.C2G_LoginGate, typeof(C2G_LoginGate))] [ProtoInclude((int)Opcode.C2G_EnterMap, typeof(C2G_EnterMap))] + [ProtoInclude((int)Opcode.C2R_Ping, typeof(C2R_Ping))] public abstract partial class ARequest : AMessage { } @@ -21,6 +22,7 @@ namespace Model [ProtoInclude((int)Opcode.R2C_Login, typeof(R2C_Login))] [ProtoInclude((int)Opcode.G2C_LoginGate, typeof(G2C_LoginGate))] [ProtoInclude((int)Opcode.G2C_EnterMap, typeof(G2C_EnterMap))] + [ProtoInclude((int)Opcode.R2C_Ping, typeof(R2C_Ping))] public abstract partial class AResponse : AMessage { } @@ -198,11 +200,13 @@ namespace Model { } + [ProtoContract] [Message(Opcode.C2R_Ping)] public class C2R_Ping: ARequest { } + [ProtoContract] [Message(Opcode.R2C_Ping)] public class R2C_Ping: AResponse { diff --git a/Unity/Assets/Scripts/Entity/Session.cs b/Unity/Assets/Scripts/Entity/Session.cs index 4bd3963ecc90b7b74bc5377165a17612e1a179f9..e24249b4adba26c1f636f2ac53dec1cf4c9f2fb2 100644 --- a/Unity/Assets/Scripts/Entity/Session.cs +++ b/Unity/Assets/Scripts/Entity/Session.cs @@ -62,9 +62,9 @@ namespace Model continue; } - if (messageBytes.Length < 3) + if (messageBytes.Length < 2) { - Log.Error($"message error length < 3, ip: {this.RemoteAddress}"); + Log.Error($"message error length < 2, ip: {this.RemoteAddress}"); this.network.Remove(this.Id); return; } @@ -131,7 +131,7 @@ namespace Model { request.RpcId = ++RpcId; - this.requestCallback[RpcId] = (message) => + this.requestCallback[request.RpcId] = (message) => { try { @@ -155,7 +155,7 @@ namespace Model request.RpcId = ++RpcId; var tcs = new TaskCompletionSource(); - this.requestCallback[RpcId] = (message) => + this.requestCallback[request.RpcId] = (message) => { try { @@ -187,7 +187,7 @@ namespace Model var tcs = new TaskCompletionSource(); - this.requestCallback[RpcId] = (message) => + this.requestCallback[request.RpcId] = (message) => { try { @@ -206,7 +206,7 @@ namespace Model } }; - cancellationToken.Register(() => { this.requestCallback.Remove(RpcId); }); + cancellationToken.Register(() => { this.requestCallback.Remove(request.RpcId); }); this.SendMessage(request); @@ -221,7 +221,7 @@ namespace Model request.RpcId = ++RpcId; var tcs = new TaskCompletionSource(); - this.requestCallback[RpcId] = (message) => + this.requestCallback[request.RpcId] = (message) => { try { @@ -255,7 +255,7 @@ namespace Model var tcs = new TaskCompletionSource(); - this.requestCallback[RpcId] = (message) => + this.requestCallback[request.RpcId] = (message) => { try { @@ -274,7 +274,7 @@ namespace Model } }; - cancellationToken.Register(() => { this.requestCallback.Remove(RpcId); }); + cancellationToken.Register(() => { this.requestCallback.Remove(request.RpcId); }); this.SendMessage(request);