diff --git a/CAPI/cpp/API/src/Communication.cpp b/CAPI/cpp/API/src/Communication.cpp index 6bcf8d8..f808e22 100644 --- a/CAPI/cpp/API/src/Communication.cpp +++ b/CAPI/cpp/API/src/Communication.cpp @@ -249,10 +249,13 @@ void Communication::AddPlayer(int64_t playerID, THUAI6::PlayerType playerType, T grpc::ClientContext context; auto MessageReader = THUAI6Stub->AddPlayer(&context, playerMsg); - while (MessageReader->Read(&message2Client)) + protobuf::MessageToClient buffer2Client; + + while (MessageReader->Read(&buffer2Client)) { { std::lock_guard lock(mtxMessage); + message2Client = std::move(buffer2Client); haveNewMessage = true; } cvMessage.notify_one(); diff --git a/dependency/shell/run.sh b/dependency/shell/run.sh index 70a1286..5b44566 100644 --- a/dependency/shell/run.sh +++ b/dependency/shell/run.sh @@ -3,7 +3,7 @@ python_dir=/usr/local/PlayerCode/CAPI/python/PyAPI playback_dir=/usr/local/playback -nice -10 ./Server --port 8888 --studentCount 4 --trickerCount 1 --gameTimeInSecond 600 --url $URL --token $TOKEN --fileName $playback_dir/video > $playback_dir/server.log & +nice -10 ./Server --port 8888 --studentCount 4 --trickerCount 1 --gameTimeInSecond 600 --url $URL --token $TOKEN --fileName $playback_dir/video --startLockFile $playback_dir/start.lock > $playback_dir/server.log & server_pid=$! sleep 5 for k in {1..2} @@ -39,12 +39,20 @@ do popd done -ps -p $server_pid -while [ $? -eq 0 ] -do - sleep 1 - ps -p $server_pid -done +sleep 10 -touch $playback_dir/finish.lock -echo "Finish" +if [ -f $playback_dir/start.lock ]; then + ps -p $server_pid + while [ $? -eq 0 ] + do + sleep 1 + ps -p $server_pid + done + touch $playback_dir/finish.lock + echo "Finish" +else + echo "Failed to start game." + touch temp.lock + mv -f temp.lock $playback_dir/video.thuaipb + kill -9 $server_pid +fi diff --git a/logic/Server/ArgumentOption.cs b/logic/Server/ArgumentOption.cs index 2dddf7d..fa680b1 100644 --- a/logic/Server/ArgumentOption.cs +++ b/logic/Server/ArgumentOption.cs @@ -71,5 +71,8 @@ namespace Server [Option("resultFileName", Required = false, HelpText = "Result file name, saved as .json")] public string ResultFileName { get; set; } = DefaultArgumentOptions.FileName; + + [Option("startLockFile", Required = false, HelpText = "Whether to create a file that identifies whether the game has started")] + public string StartLockFile { get; set; } = DefaultArgumentOptions.FileName; } } \ No newline at end of file diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index b81bfe7..080ae7b 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -45,6 +45,7 @@ namespace Server if (id == GameObj.invalidID) return; //如果有未初始化的玩家,不开始游戏 } Console.WriteLine("Game starts!"); + CreateStartFile(); game.StartGame((int)options.GameTimeInSecond * 1000); Thread.Sleep(1); new Thread(() => @@ -74,6 +75,16 @@ namespace Server }) { IsBackground = true }.Start(); } + + public void CreateStartFile() + { + if (options.StartLockFile != DefaultArgumentOptions.FileName) + { + using var _ = File.Create(options.StartLockFile); + Console.WriteLine("Successfully Created StartLockFile!"); + } + } + public void WaitForEnd() { this.endGameSem.Wait();