diff --git a/.vscode/launch.json b/.vscode/launch.json index fa71fb8..02cf553 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/bin/Debug/net6.0/dfbattle.dll", - "args": [], + "args": ["ws://127.0.0.1:9897"], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console "console": "internalConsole", diff --git a/Client.cs b/Client.cs index e18406d..e88b3da 100644 --- a/Client.cs +++ b/Client.cs @@ -13,13 +13,20 @@ namespace BattleServer { socket = _socket; socket.OnBinary = doBinary; - socket.OnClose = close; + // socket.OnClose = close; + socket.OnError = onError; } - - private void close() + private void onError(Exception e) { + Console.WriteLine("onError {0}", e.Message); + socket.Close(); Service.Instance.Shutdown(this); } + // private void close() + // { + // Console.WriteLine("close !"); + // Service.Instance.Shutdown(this); + // } /// /// 接收rpc数据 @@ -48,7 +55,6 @@ namespace BattleServer /// private void handle(BattleRpcMessage msg) { - bool issucc; byte[] _msg; // long ts = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000; // Console.WriteLine("接收到战斗消息 1 {0}|{1}",msg.method,ts); @@ -58,7 +64,7 @@ namespace BattleServer BattleReport report = ProtoDeSerialize(msg.data.value); // ts = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000; // Console.WriteLine("接收到战斗消息 2 |{0}",ts); - issucc = HotUpdateScripts.FightRunnerMgr.Instance.VerifyOnceFight(report); + bool issucc = HotUpdateScripts.FightRunnerMgr.Instance.VerifyOnceFight(report); // ts = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000; // Console.WriteLine("接收到战斗消息 3 |{0}",ts); msg.data = new Google.Protobuf.WellKnownTypes.Any @@ -72,39 +78,54 @@ namespace BattleServer socket.Send(_msg); break; case "Create": //创建战斗场景 + Console.WriteLine("处理CreatePVP !"); BattleCreateServerReq CreateReq = ProtoDeSerialize(msg.data.value); - issucc = HotUpdateScripts.FightRunnerMgr.Instance.CreatePvP(CreateReq.info, this.OnOutCmd, this.OnFinish); - msg.data = new Google.Protobuf.WellKnownTypes.Any + HotUpdateScripts.FightRunnerMgr.Instance.StartPvp(CreateReq.info, this.OnOutCmd, this.OnFinish, (issucc) => { - type_url = "type.googleapis.com/BattleCreateServerResp", - value = ProtoSerialize(new BattleCreateServerResp { issucc = issucc }), - }; - _msg = ProtoSerialize(msg); - socket.Send(_msg); + msg.data = new Google.Protobuf.WellKnownTypes.Any + { + type_url = "type.googleapis.com/BattleCreateServerResp", + value = ProtoSerialize(new BattleCreateServerResp { issucc = issucc }), + }; + _msg = ProtoSerialize(msg); + socket.Send(_msg); + Console.WriteLine("处理CreatePVP end !"); + }); break; case "InCmd": //向战斗场景输入指令 + Console.WriteLine("处理InCmd !"); BattleInCmdReq InCmdReq = ProtoDeSerialize(msg.data.value); - issucc = HotUpdateScripts.FightRunnerMgr.Instance.PvpInput(InCmdReq.battleid, 0, InCmdReq.@in); - msg.data = new Google.Protobuf.WellKnownTypes.Any + HotUpdateScripts.FightRunnerMgr.Instance.PvpInput(InCmdReq.battleid, InCmdReq.side, InCmdReq.@in, (issucc) => { - type_url = "type.googleapis.com/BattleCreateServerResp", - value = ProtoSerialize(new BattleCreateServerResp { issucc = issucc }), - }; - _msg = ProtoSerialize(msg); - socket.Send(_msg); + msg.data = new Google.Protobuf.WellKnownTypes.Any + { + type_url = "type.googleapis.com/BattleInCmdResp", + value = ProtoSerialize(new BattleInCmdResp { issucc = issucc }), + }; + _msg = ProtoSerialize(msg); + socket.Send(_msg); + Console.WriteLine("处理InCmd end !"); + }); + break; } } - private void OnOutCmd(string bid, BattleCmd cmd) + private void OnOutCmd(string bid, List cmd) { + // Console.WriteLine("----------------------OnOutCmd {0}:{1}", bid, cmd.cmdtype); + foreach (var item in cmd) + { + Console.WriteLine("----------------------OnOutCmd {0}:{1}", bid, item.cmdtype); + } + BattleRpcMessage msg = new BattleRpcMessage(); msg.method = "BattleOutCmd"; msg.data = new Google.Protobuf.WellKnownTypes.Any { type_url = "type.googleapis.com/BattleOutCmdPush", - value = ProtoSerialize(new BattleOutCmdPush { battleid = bid, cmd = new List() { cmd }, }), + value = ProtoSerialize(new BattleOutCmdPush { battleid = bid, cmd = cmd, }), }; byte[] data = ProtoSerialize(msg); socket.Send(data); @@ -112,7 +133,9 @@ namespace BattleServer private void OnFinish(BattleCmd cmd) { + ComEndFight _cmd = HotUpdateScripts.FightCmdUtil.PasreCmd(cmd) as ComEndFight; + Console.WriteLine("----------------------OnFinish {0}", _cmd.fightId); BattleRpcMessage msg = new BattleRpcMessage(); msg.method = "BattleFished"; msg.data = new Google.Protobuf.WellKnownTypes.Any @@ -120,8 +143,22 @@ namespace BattleServer type_url = "type.googleapis.com/BattleFinishPush", value = ProtoSerialize(new BattleFinishPush { battleid = _cmd.fightId }), }; + byte[] data = ProtoSerialize(msg); - socket.Send(data); + Task t = Task.Run(() => + { + Thread.Sleep(1000); + socket.Send(data); + }); + + t.ContinueWith(r => + { + string Exception = Convert.ToString(t.Exception); + Console.WriteLine("OnFinish 异常处理:" + Exception); + }, TaskContinuationOptions.OnlyOnFaulted); + + + } /// diff --git a/Program.cs b/Program.cs index 0651dc6..ad7578e 100644 --- a/Program.cs +++ b/Program.cs @@ -10,8 +10,8 @@ namespace BattleServer { Console.WriteLine("外部参数:{0}", args[0]); HotUpdateScripts.FightRunnerMgr.Instance.Init("./GameConfig/"); - // cfg.Game.HeroData data = HotUpdateScripts.FightBase.GC.Hero.Get("25001"); - // HotUpdateScripts.FightDebug.Log("测试读取配置 name:"+data.Name); + cfg.Game.HeroData data = HotUpdateScripts.FightBase.GC.Hero.Get("25001"); + HotUpdateScripts.FightDebug.Log("测试读取配置 name:" + data.Name); Service service = new Service(args[0]); Console.WriteLine("BattleServer Start!"); Thread.Sleep(Timeout.Infinite); diff --git a/Service.cs b/Service.cs index a023227..27a646d 100644 --- a/Service.cs +++ b/Service.cs @@ -30,8 +30,9 @@ namespace BattleServer clients.Add(client); } - public void Shutdown(Client client){ - Console.WriteLine("连接对象断开{0}", client.ToString()); + public void Shutdown(Client client) + { + Console.WriteLine("连接对象断开{0}", client.ToString()); this.clients.Remove(client); } } diff --git a/bin/Debug/net6.0/FightRunner.dll b/bin/Debug/net6.0/FightRunner.dll new file mode 100644 index 0000000..82383a8 Binary files /dev/null and b/bin/Debug/net6.0/FightRunner.dll differ diff --git a/bin/Debug/net6.0/Fleck.dll b/bin/Debug/net6.0/Fleck.dll new file mode 100644 index 0000000..bc0b959 Binary files /dev/null and b/bin/Debug/net6.0/Fleck.dll differ diff --git a/bin/Debug/net6.0/GameFight.dll b/bin/Debug/net6.0/GameFight.dll new file mode 100644 index 0000000..68fa5b1 Binary files /dev/null and b/bin/Debug/net6.0/GameFight.dll differ diff --git a/bin/Debug/net6.0/GameProto.dll b/bin/Debug/net6.0/GameProto.dll new file mode 100644 index 0000000..c025972 Binary files /dev/null and b/bin/Debug/net6.0/GameProto.dll differ diff --git a/bin/Debug/net6.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll b/bin/Debug/net6.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll new file mode 100644 index 0000000..7d8769b Binary files /dev/null and b/bin/Debug/net6.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll differ diff --git a/bin/Debug/net6.0/Microsoft.Extensions.DependencyInjection.dll b/bin/Debug/net6.0/Microsoft.Extensions.DependencyInjection.dll new file mode 100644 index 0000000..cdcb266 Binary files /dev/null and b/bin/Debug/net6.0/Microsoft.Extensions.DependencyInjection.dll differ diff --git a/bin/Debug/net6.0/dfbattle.deps.json b/bin/Debug/net6.0/dfbattle.deps.json new file mode 100644 index 0000000..bd488ba --- /dev/null +++ b/bin/Debug/net6.0/dfbattle.deps.json @@ -0,0 +1,117 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v6.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v6.0": { + "dfbattle/1.0.0": { + "dependencies": { + "Fleck": "1.2.0", + "Microsoft.Extensions.DependencyInjection": "2.1.1", + "FightRunner": "1.0.0.0", + "GameFight": "1.0.0.0", + "GameProto": "1.0.0.0" + }, + "runtime": { + "dfbattle.dll": {} + } + }, + "Fleck/1.2.0": { + "runtime": { + "lib/netcoreapp2.0/Fleck.dll": { + "assemblyVersion": "1.2.0.0", + "fileVersion": "1.2.0.0" + } + } + }, + "Microsoft.Extensions.DependencyInjection/2.1.1": { + "dependencies": { + "Microsoft.Extensions.DependencyInjection.Abstractions": "2.1.1" + }, + "runtime": { + "lib/netcoreapp2.0/Microsoft.Extensions.DependencyInjection.dll": { + "assemblyVersion": "2.1.1.0", + "fileVersion": "2.1.1.18157" + } + } + }, + "Microsoft.Extensions.DependencyInjection.Abstractions/2.1.1": { + "runtime": { + "lib/netstandard2.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll": { + "assemblyVersion": "2.1.1.0", + "fileVersion": "2.1.1.18157" + } + } + }, + "FightRunner/1.0.0.0": { + "runtime": { + "FightRunner.dll": { + "assemblyVersion": "1.0.0.0", + "fileVersion": "1.0.0.0" + } + } + }, + "GameFight/1.0.0.0": { + "runtime": { + "GameFight.dll": { + "assemblyVersion": "1.0.0.0", + "fileVersion": "1.0.0.0" + } + } + }, + "GameProto/1.0.0.0": { + "runtime": { + "GameProto.dll": { + "assemblyVersion": "1.0.0.0", + "fileVersion": "1.0.0.0" + } + } + } + } + }, + "libraries": { + "dfbattle/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + }, + "Fleck/1.2.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-bPLXn6QbLAFoviur6XbrKB0Zn6x04E8VibHXyHZeJsoC7bkUl5DVtzM5cZgDuqHkIrBqAXJyTNJwSNIc6wBJ2Q==", + "path": "fleck/1.2.0", + "hashPath": "fleck.1.2.0.nupkg.sha512" + }, + "Microsoft.Extensions.DependencyInjection/2.1.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-RVdgNWT/73M0eCpreGpWv5NmbHFGQzzW+G7nChK8ej84m+d1nzeWrtqcRYnEpKNx3B8V/Uek4tNP0WCaCNjYnQ==", + "path": "microsoft.extensions.dependencyinjection/2.1.1", + "hashPath": "microsoft.extensions.dependencyinjection.2.1.1.nupkg.sha512" + }, + "Microsoft.Extensions.DependencyInjection.Abstractions/2.1.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-MgYpU5cwZohUMKKg3sbPhvGG+eAZ/59E9UwPwlrUkyXU+PGzqwZg9yyQNjhxuAWmoNoFReoemeCku50prYSGzA==", + "path": "microsoft.extensions.dependencyinjection.abstractions/2.1.1", + "hashPath": "microsoft.extensions.dependencyinjection.abstractions.2.1.1.nupkg.sha512" + }, + "FightRunner/1.0.0.0": { + "type": "reference", + "serviceable": false, + "sha512": "" + }, + "GameFight/1.0.0.0": { + "type": "reference", + "serviceable": false, + "sha512": "" + }, + "GameProto/1.0.0.0": { + "type": "reference", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/bin/Debug/net6.0/dfbattle.dll b/bin/Debug/net6.0/dfbattle.dll new file mode 100644 index 0000000..ddaf6da Binary files /dev/null and b/bin/Debug/net6.0/dfbattle.dll differ diff --git a/bin/Debug/net6.0/dfbattle.pdb b/bin/Debug/net6.0/dfbattle.pdb new file mode 100644 index 0000000..5dbfb51 Binary files /dev/null and b/bin/Debug/net6.0/dfbattle.pdb differ diff --git a/bin/Debug/net6.0/dfbattle.runtimeconfig.json b/bin/Debug/net6.0/dfbattle.runtimeconfig.json new file mode 100644 index 0000000..4986d16 --- /dev/null +++ b/bin/Debug/net6.0/dfbattle.runtimeconfig.json @@ -0,0 +1,9 @@ +{ + "runtimeOptions": { + "tfm": "net6.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "6.0.0" + } + } +} \ No newline at end of file diff --git a/lib/FightRunner.dll b/lib/FightRunner.dll index 021db6d..82383a8 100644 Binary files a/lib/FightRunner.dll and b/lib/FightRunner.dll differ diff --git a/lib/GameFight.dll b/lib/GameFight.dll index f22b476..68fa5b1 100644 Binary files a/lib/GameFight.dll and b/lib/GameFight.dll differ diff --git a/lib/GameProto.dll b/lib/GameProto.dll index fdc2d35..c025972 100644 Binary files a/lib/GameProto.dll and b/lib/GameProto.dll differ diff --git a/obj/Debug/net6.0/dfbattle.GeneratedMSBuildEditorConfig.editorconfig b/obj/Debug/net6.0/dfbattle.GeneratedMSBuildEditorConfig.editorconfig index 8265cfe..31327a7 100644 --- a/obj/Debug/net6.0/dfbattle.GeneratedMSBuildEditorConfig.editorconfig +++ b/obj/Debug/net6.0/dfbattle.GeneratedMSBuildEditorConfig.editorconfig @@ -7,4 +7,4 @@ build_property.InvariantGlobalization = build_property.PlatformNeutralAssembly = build_property._SupportedPlatformList = Linux,macOS,Windows build_property.RootNamespace = dfbattle -build_property.ProjectDir = f:\work\c#\dfbattle\ +build_property.ProjectDir = F:\work\c#\dfbattle\ diff --git a/obj/Debug/net6.0/dfbattle.assets.cache b/obj/Debug/net6.0/dfbattle.assets.cache index da3d89f..21832a2 100644 Binary files a/obj/Debug/net6.0/dfbattle.assets.cache and b/obj/Debug/net6.0/dfbattle.assets.cache differ diff --git a/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache b/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache index 4b3dd4e..e388e60 100644 Binary files a/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache and b/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/net6.0/dfbattle.csproj.CopyComplete b/obj/Debug/net6.0/dfbattle.csproj.CopyComplete new file mode 100644 index 0000000..e69de29 diff --git a/obj/Debug/net6.0/dfbattle.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/dfbattle.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..66b2b43 --- /dev/null +++ b/obj/Debug/net6.0/dfbattle.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +60cbd222e33b4c1b3bcd5f3d4c821bfd2dd0c6d8 diff --git a/obj/Debug/net6.0/dfbattle.csproj.FileListAbsolute.txt b/obj/Debug/net6.0/dfbattle.csproj.FileListAbsolute.txt index b9c6222..35c25cd 100644 --- a/obj/Debug/net6.0/dfbattle.csproj.FileListAbsolute.txt +++ b/obj/Debug/net6.0/dfbattle.csproj.FileListAbsolute.txt @@ -21,3 +21,25 @@ /home/liwei/dfbattle/obj/Debug/net6.0/dfbattle.pdb /home/liwei/dfbattle/obj/Debug/net6.0/dfbattle.genruntimeconfig.cache /home/liwei/dfbattle/obj/Debug/net6.0/ref/dfbattle.dll +F:\work\c#\dfbattle\bin\Debug\net6.0\dfbattle.exe +F:\work\c#\dfbattle\bin\Debug\net6.0\dfbattle.deps.json +F:\work\c#\dfbattle\bin\Debug\net6.0\dfbattle.runtimeconfig.json +F:\work\c#\dfbattle\bin\Debug\net6.0\dfbattle.dll +F:\work\c#\dfbattle\bin\Debug\net6.0\dfbattle.pdb +F:\work\c#\dfbattle\bin\Debug\net6.0\Fleck.dll +F:\work\c#\dfbattle\bin\Debug\net6.0\Microsoft.Extensions.DependencyInjection.dll +F:\work\c#\dfbattle\bin\Debug\net6.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll +F:\work\c#\dfbattle\bin\Debug\net6.0\FightRunner.dll +F:\work\c#\dfbattle\bin\Debug\net6.0\GameFight.dll +F:\work\c#\dfbattle\bin\Debug\net6.0\GameProto.dll +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.csproj.AssemblyReference.cache +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.GeneratedMSBuildEditorConfig.editorconfig +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.AssemblyInfoInputs.cache +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.AssemblyInfo.cs +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.csproj.CoreCompileInputs.cache +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.csproj.CopyComplete +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.dll +F:\work\c#\dfbattle\obj\Debug\net6.0\refint\dfbattle.dll +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.pdb +F:\work\c#\dfbattle\obj\Debug\net6.0\dfbattle.genruntimeconfig.cache +F:\work\c#\dfbattle\obj\Debug\net6.0\ref\dfbattle.dll diff --git a/obj/Debug/net6.0/dfbattle.dll b/obj/Debug/net6.0/dfbattle.dll new file mode 100644 index 0000000..ddaf6da Binary files /dev/null and b/obj/Debug/net6.0/dfbattle.dll differ diff --git a/obj/Debug/net6.0/dfbattle.genruntimeconfig.cache b/obj/Debug/net6.0/dfbattle.genruntimeconfig.cache new file mode 100644 index 0000000..085d1f4 --- /dev/null +++ b/obj/Debug/net6.0/dfbattle.genruntimeconfig.cache @@ -0,0 +1 @@ +e467f67f7c05efce451b802592739e7f55c06ec5 diff --git a/obj/Debug/net6.0/dfbattle.pdb b/obj/Debug/net6.0/dfbattle.pdb new file mode 100644 index 0000000..5dbfb51 Binary files /dev/null and b/obj/Debug/net6.0/dfbattle.pdb differ diff --git a/obj/Debug/net6.0/ref/dfbattle.dll b/obj/Debug/net6.0/ref/dfbattle.dll new file mode 100644 index 0000000..35cd3ad Binary files /dev/null and b/obj/Debug/net6.0/ref/dfbattle.dll differ diff --git a/obj/Debug/net6.0/refint/dfbattle.dll b/obj/Debug/net6.0/refint/dfbattle.dll new file mode 100644 index 0000000..35cd3ad Binary files /dev/null and b/obj/Debug/net6.0/refint/dfbattle.dll differ