上传c#战斗服务

This commit is contained in:
liwei1dao 2023-02-10 19:04:48 +08:00
parent e45413d58a
commit 7ee791ca1a
28 changed files with 216 additions and 28 deletions

2
.vscode/launch.json vendored
View File

@ -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",

View File

@ -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);
// }
/// <summary>
/// 接收rpc数据
@ -48,7 +55,6 @@ namespace BattleServer
/// <param name="msg"></param>
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<BattleReport>(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<BattleCreateServerReq>(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<BattleInCmdReq>(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<BattleCmd> 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<BattleCmd>() { 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);
}
/// <summary>

View File

@ -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);

View File

@ -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);
}
}

Binary file not shown.

BIN
bin/Debug/net6.0/Fleck.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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\

View File

@ -0,0 +1 @@
60cbd222e33b4c1b3bcd5f3d4c821bfd2dd0c6d8

View File

@ -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

Binary file not shown.

View File

@ -0,0 +1 @@
e467f67f7c05efce451b802592739e7f55c06ec5

Binary file not shown.

Binary file not shown.

Binary file not shown.