diff --git a/CAPI/python_exp/.gitignore b/CAPI/python_exp/.gitignore index 719c095a..5b72a603 100644 --- a/CAPI/python_exp/.gitignore +++ b/CAPI/python_exp/.gitignore @@ -167,3 +167,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +# launch debug +!.vscode/ \ No newline at end of file diff --git a/CAPI/python_exp/.vscode/launch.json b/CAPI/python_exp/.vscode/launch.json new file mode 100644 index 00000000..c63eba20 --- /dev/null +++ b/CAPI/python_exp/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Team 0", + "type": "debugpy", + "request": "launch", + "program": "./PyAPI/main.py", + "console": "integratedTerminal", + "args": "-I localhost -P 8888 -t 0 -d -o" + }, + { + "name": "Team 1", + "type": "debugpy", + "request": "launch", + "program": "./PyAPI/main.py", + "console": "integratedTerminal", + "args": "-I localhost -P 8888 -t 1 -d -o" + } + ], + "compounds": [ + { + "name": "Compound", + "configurations": ["Team 0", "Team 1"] + } + ] +} \ No newline at end of file diff --git a/CAPI/python_exp/.vscode/settings.json b/CAPI/python_exp/.vscode/settings.json new file mode 100644 index 00000000..d0b2107d --- /dev/null +++ b/CAPI/python_exp/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "python.analysis.autoImportCompletions": true, + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "**/__pycache__": true, + "**/build": true + }, + "python.analysis.typeCheckingMode": "off" +} \ No newline at end of file diff --git a/CAPI/python_exp/PyAPI/logic.py b/CAPI/python_exp/PyAPI/logic.py index dba37515..54b7625d 100644 --- a/CAPI/python_exp/PyAPI/logic.py +++ b/CAPI/python_exp/PyAPI/logic.py @@ -330,6 +330,8 @@ def __LoadBuffer(self, message: Message2Clients.MessageToClient) -> None: self.__bufferState.gameInfo = Proto2THUAI7.Protobuf2THUAI7GameInfo(message.all_message) self.__LoadBufferSelf(message) + if self.__playerType == THUAI7.Ship and isinstance(self.__bufferState.self, None): + return for item in message.obj_message: self.__LoadBufferCase(item) if Setting.Asynchronous(): @@ -347,7 +349,7 @@ def __LoadBuffer(self, message: Message2Clients.MessageToClient) -> None: self.__cvBuffer.notify() def __LoadBufferSelf(self, message: Message2Clients.MessageToClient) -> None: - if self.__playerID != 0: + if self.__playerType == THUAI7.PlayerType.Ship: for item in message.obj_message: if item.WhichOneof("message_of_obj") == "ship_message": if item.ship_message.player_id == self.__playerID: diff --git a/CAPI/python_exp/playback.py b/CAPI/python_exp/playback.py new file mode 100644 index 00000000..0a393bb1 --- /dev/null +++ b/CAPI/python_exp/playback.py @@ -0,0 +1,14 @@ +import os +import sys +import grpc + +sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/proto") + +import proto.Message2Server_pb2 as m2s # NOQA: E402 +import proto.Message2Clients_pb2 as m2c # NOQA: E402 +import proto.MessageType_pb2 as mt # NOQA: E402 +import proto.Services_pb2_grpc as ser # NOQA: E402 + +stub = ser.AvailableServiceStub(grpc.insecure_channel('localhost:8888')) +for msg in stub.AddPlayer(m2s.PlayerMsg(player_id=2025)): + print(msg) diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index d828d5f5..4ee277b8 100755 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -85,7 +85,7 @@ public void CreateStartFile() public override void WaitForEnd() { - this.endGameSem.Wait(); + endGameSem.Wait(); mwr?.Dispose(); } diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index 0b46c60c..d168bf86 100755 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -186,34 +186,32 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter public string FileName { get; } - private readonly CodedOutputStream cos; // Protobuf类型二进制输出流 + /// + /// 写入消息数量 + /// + public uint WrittenNum { get; private set; } = 0; + private readonly uint FlushNum; // 刷新间隔 + private readonly CodedOutputStream cos; // Protobuf类型二进制输出流 public bool Disposed { get; private set; } = false; - public MessageWriter(string fileName, uint teamCount, uint playerCount) + public MessageWriter(string fileName, uint teamCount, uint playerCount, uint flushNum = 500) { Utils.FileNameRegular(ref fileName); FileStream fs = File.Create(fileName); @@ -23,12 +28,15 @@ public MessageWriter(string fileName, uint teamCount, uint playerCount) fs.WriteHeader(teamCount, playerCount); GZipStream gzs = new(fs, CompressionMode.Compress); cos = new(gzs); + FlushNum = flushNum; } public void WriteOne(MessageToClient msg) { if (Disposed) return; cos.WriteMessage(msg); + WrittenNum++; + if (WrittenNum % FlushNum == 0) Flush(); } public void Flush()