From 584e6fc494f650728d5a0e341b1c38e3fa570a6a Mon Sep 17 00:00:00 2001 From: ONLOX <3316820553@qq.com> Date: Tue, 23 Apr 2024 19:38:20 +0800 Subject: [PATCH 1/5] feat: :alien: --- .github/workflows/docker.yml | 29 +++++++++ .../{Dockerfile_run => Docker_run_client} | 4 +- dependency/Dockerfile/Docker_run_server | 20 ++++++ dependency/shell/Unix2dos.sh | 18 ++++++ dependency/shell/compile.sh | 31 +++++++++ dependency/shell/cpp_output.sh | 8 +++ dependency/shell/docker.sh | 23 +++++++ dependency/shell/generate_proto.sh | 10 +++ dependency/shell/run_client.sh | 64 +++++++++++++++++++ dependency/shell/run_server.sh | 55 ++++++++++++++++ 10 files changed, 260 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker.yml rename dependency/Dockerfile/{Dockerfile_run => Docker_run_client} (89%) mode change 100755 => 100644 create mode 100644 dependency/Dockerfile/Docker_run_server create mode 100644 dependency/shell/Unix2dos.sh create mode 100644 dependency/shell/compile.sh create mode 100644 dependency/shell/cpp_output.sh create mode 100644 dependency/shell/docker.sh create mode 100644 dependency/shell/generate_proto.sh create mode 100644 dependency/shell/run_client.sh create mode 100644 dependency/shell/run_server.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..4d0acd25 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,29 @@ +name: "docker" +on: + push: + branches: [main] + +jobs: + upload_docker_images: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Log in to DockerHub + run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + + #- name: Build base docker image + # run: docker build -t ${{ secrets.DOCKER_USERNAME }}/thuai6_base:base -f ./dependency/Dockerfile/Dockerfile_base . + #- name: Push base image to DockerHub + # run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai6_base:base + + + - name: Build cpp_compile docker image + run: docker build -t ${{ secrets.DOCKER_USERNAME }}/thuai6_cpp:latest -f ./dependency/Dockerfile/Dockerfile_cpp . + - name: Push cpp_compile image to DockerHub + run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai6_cpp:latest + + - name: Build run docker image + run: docker build -t ${{ secrets.DOCKER_USERNAME }}/thuai6_run:latest -f ./dependency/Dockerfile/Dockerfile_run . + - name: Push run image to DockerHub + run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai6_run:latest + diff --git a/dependency/Dockerfile/Dockerfile_run b/dependency/Dockerfile/Docker_run_client old mode 100755 new mode 100644 similarity index 89% rename from dependency/Dockerfile/Dockerfile_run rename to dependency/Dockerfile/Docker_run_client index 474e1658..9df6ff40 --- a/dependency/Dockerfile/Dockerfile_run +++ b/dependency/Dockerfile/Docker_run_client @@ -9,7 +9,7 @@ MAINTAINER eesast WORKDIR /usr/local COPY --from=build /usr/local/Server . RUN mkdir /usr/local/team1 && mkdir /usr/local/team2 && mkdir /usr/local/playback -COPY ./dependency/shell/run.sh . +COPY ./dependency/shell/run_client.sh . COPY ./CAPI/python /usr/local/PlayerCode/CAPI/python COPY ./dependency/proto /usr/local/PlayerCode/dependency/proto COPY ./dependency/shell /usr/local/PlayerCode/dependency/shell @@ -17,4 +17,4 @@ WORKDIR /usr/local/PlayerCode/CAPI/python RUN bash ../../dependency/shell/generate_proto.sh WORKDIR /usr/local -ENTRYPOINT [ "bash","./run.sh" ] +ENTRYPOINT [ "bash","./run_client.sh" ] diff --git a/dependency/Dockerfile/Docker_run_server b/dependency/Dockerfile/Docker_run_server new file mode 100644 index 00000000..aa5984dd --- /dev/null +++ b/dependency/Dockerfile/Docker_run_server @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0.204-jammy-amd64 AS build +MAINTAINER eesast +WORKDIR /usr/local +COPY . . +RUN dotnet publish logic/Server/Server.csproj -c Release -o /usr/local/Server --self-contained true -r linux-x64 + +FROM eesast/thuai7_base:base +MAINTAINER eesast +WORKDIR /usr/local +COPY --from=build /usr/local/Server . +RUN mkdir /usr/local/team1 && mkdir /usr/local/team2 && mkdir /usr/local/playback +COPY ./dependency/shell/run_server.sh . +COPY ./CAPI/python /usr/local/PlayerCode/CAPI/python +COPY ./dependency/proto /usr/local/PlayerCode/dependency/proto +COPY ./dependency/shell /usr/local/PlayerCode/dependency/shell +WORKDIR /usr/local/PlayerCode/CAPI/python +RUN bash ../../dependency/shell/generate_proto.sh + +WORKDIR /usr/local +ENTRYPOINT [ "bash","./run_server.sh" ] diff --git a/dependency/shell/Unix2dos.sh b/dependency/shell/Unix2dos.sh new file mode 100644 index 00000000..feebe3c0 --- /dev/null +++ b/dependency/shell/Unix2dos.sh @@ -0,0 +1,18 @@ +#!/bin/bash +function lsdir() +{ +for i in `ls`; +do + if [ -d $i ] + then + pushd ./$i + lsdir + popd + else + unix2dos $i + fi +done +} +yum -y install unix2dos +cd $1 +lsdir diff --git a/dependency/shell/compile.sh b/dependency/shell/compile.sh new file mode 100644 index 00000000..c616ba85 --- /dev/null +++ b/dependency/shell/compile.sh @@ -0,0 +1,31 @@ +#! /bin/bash +# WORKDIR /usr/local/PlayerCode/CAPI/cpp +workdir=/usr/local/PlayerCode/CAPI/cpp +bind=/usr/local/code +output=/usr/local/output + +flag=1 + +cd $bind +file_count=$(ls -l *.cpp | wc -l); +if [ $file_count -eq 1 ] +then + filename=$(ls *.cpp) + base_name=$(basename "$filename" .cpp) + cd $workdir + cp -f $bind/$filename $workdir/API/src/AI.cpp + cmake ./CMakeLists.txt && make -j$(nproc) >$base_name.log 2>&1 + mv ./capi $output/$base_name + if [ $? -ne 0 ]; then + flag=0 + fi + mv ./$base_name.log $output/$base_name.log +else + flag=0 +fi + +if [ $flag -eq 1 ]; then + curl $URL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"compile_status":"Success"}' > $output/$base_name.curl.log +else + curl $URL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"compile_status":"Failed"}' > $output/$base_name.curl.log +fi diff --git a/dependency/shell/cpp_output.sh b/dependency/shell/cpp_output.sh new file mode 100644 index 00000000..a8b07973 --- /dev/null +++ b/dependency/shell/cpp_output.sh @@ -0,0 +1,8 @@ +protoc Message2Clients.proto --cpp_out=. +protoc MessageType.proto --cpp_out=. +protoc Message2Server.proto --cpp_out=. +protoc Services.proto --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` +protoc Services.proto --cpp_out=. +chmod -R 755 ./ +mv -f ./*.h ../../CAPI/cpp/proto +mv -f ./*.cc ../../CAPI/cpp/proto diff --git a/dependency/shell/docker.sh b/dependency/shell/docker.sh new file mode 100644 index 00000000..ef4beb39 --- /dev/null +++ b/dependency/shell/docker.sh @@ -0,0 +1,23 @@ + +while getopts ':cr' 'OPT'; do + case ${OPT} in + 'c') #传入cpp文件并编译 + #echo v"$VERSION" + cd /usr/local/PlayerCode/CAPI/cpp + ./compile.sh + exit + ;; + 'r') #运行 + #NO_PROMPT='true' + cd /usr/local + ./run_server.sh + ./run_client.sh + ;; + 'l') + + ;; + 'i') + INSTALL_VERSION="${OPTARG}" + ;; + esac +done \ No newline at end of file diff --git a/dependency/shell/generate_proto.sh b/dependency/shell/generate_proto.sh new file mode 100644 index 00000000..a0ebe224 --- /dev/null +++ b/dependency/shell/generate_proto.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +python -m pip install -r requirements.txt + +mkdir -p proto + +python -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto MessageType.proto +python -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto Message2Clients.proto +python -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto Message2Server.proto +python -m grpc_tools.protoc -I../../dependency/proto/ --python_out=./proto --pyi_out=./proto --grpc_python_out=./proto Services.proto diff --git a/dependency/shell/run_client.sh b/dependency/shell/run_client.sh new file mode 100644 index 00000000..e55aaa4c --- /dev/null +++ b/dependency/shell/run_client.sh @@ -0,0 +1,64 @@ +#!/usr/local + +python_dir=/usr/local/PlayerCode/CAPI/python/PyAPI +python_main_dir=/usr/local/PlayerCode/CAPI/python +playback_dir=/usr/local/playback + +sleep 5 +for k in {1..2} +do + pushd /usr/local/team$k + if [ $k -eq 1 ]; then + for i in {1..4} + do + j=$((i - 1)) + if [ -f "./player$i.py" ]; then + cp -r $python_main_dir $python_main_dir$i + cp -f ./player$i.py $python_main_dir$i/PyAPI/AI.py + nice -0 python3 $python_main_dir$i/PyAPI/main.py -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + elif [ -f "./capi$i" ]; then + nice -0 ./capi$i -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + else + echo "ERROR. $i is not found." + fi + done + else + for i in {5..5} + do + j=$((i - 1)) + if [ -f "./player$i.py" ]; then + cp -r $python_main_dir $python_main_dir$i + cp -f ./player$i.py $python_main_dir$i/PyAPI/AI.py + nice -0 python3 $python_main_dir$i/PyAPI/main.py -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + elif [ -f "./capi$i" ]; then + nice -0 ./capi$i -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + else + echo "ERROR. $i is not found." + fi + done + fi + popd +done + +sleep 10 + +if [ -f $playback_dir/start.lock ]; then + ps -p $server_pid + while [ $? -eq 0 ] + do + sleep 1 + ps -p $server_pid > /dev/null 2>&1 + done + # result=$(cat /usr/local/playback/result.json) + # score0=$(echo "$result" | grep -oP '(?<="Student":)\d+') + # score1=$(echo "$result" | grep -oP '(?<="Tricker":)\d+') + # curl $URL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"result":[{"team_id":0, "score":'${score0}'}, {"team_id":1, "score":'${score1}'}], "mode":'${MODE}'}'> $playback_dir/send.log 2>&1 + touch $playback_dir/finish.lock + echo "Finish" +else + echo "Failed to start game." + touch $playback_dir/finish.lock + touch temp.lock + mv -f temp.lock $playback_dir/video.thuaipb + kill -9 $server_pid +fi diff --git a/dependency/shell/run_server.sh b/dependency/shell/run_server.sh new file mode 100644 index 00000000..18b02d94 --- /dev/null +++ b/dependency/shell/run_server.sh @@ -0,0 +1,55 @@ +#!/usr/local + +python_dir=/usr/local/PlayerCode/CAPI/python/PyAPI +python_main_dir=/usr/local/PlayerCode/CAPI/python +playback_dir=/usr/local/playback + +if [ $EXPOSED -eq 1 ]; then + nice -10 ./Server --port 8888 --TeamCount 2 --ShipNum 4 --resultFileName $playback_dir/result --gameTimeInSecond $TIME --mode $MODE --mapResource $MAP --url $URL --token $TOKEN --fileName $playback_dir/video --startLockFile $playback_dir/start.lock > $playback_dir/server.log 2>&1 & + server_pid=$! +else + nice -10 ./Server --port 8888 --TeamCount 2 --ShipNum 1 --resultFileName $playback_dir/result --gameTimeInSecond $TIME --mode $MODE --mapResource $MAP --notAllowSpectator --url $URL --token $TOKEN --fileName $playback_dir/video --startLockFile $playback_dir/start.lock > $playback_dir/server.log 2>&1 & + server_pid=$! +fi +sleep 5 +for k in {1..2} +do + pushd /usr/local/team$k + for i in {1..5} + do + j=$((i - 1)) + if [ -f "./player$i.py" ]; then + cp -r $python_main_dir $python_main_dir$i + cp -f ./player$i.py $python_main_dir$i/PyAPI/AI.py + nice -0 python3 $python_main_dir$i/PyAPI/main.py -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + elif [ -f "./capi$i" ]; then + nice -0 ./capi$i -I 127.0.0.1 -P 8888 -p $j > $playback_dir/team$k-player$j.log 2>&1 & + else + echo "ERROR. $i is not found." + fi + done + popd +done + +sleep 10 + +if [ -f $playback_dir/start.lock ]; then + ps -p $server_pid + while [ $? -eq 0 ] + do + sleep 1 + ps -p $server_pid > /dev/null 2>&1 + done + # result=$(cat /usr/local/playback/result.json) + # score0=$(echo "$result" | grep -oP '(?<="Student":)\d+') + # score1=$(echo "$result" | grep -oP '(?<="Tricker":)\d+') + # curl $URL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"result":[{"team_id":0, "score":'${score0}'}, {"team_id":1, "score":'${score1}'}], "mode":'${MODE}'}'> $playback_dir/send.log 2>&1 + touch $playback_dir/finish.lock + echo "Finish" +else + echo "Failed to start game." + touch $playback_dir/finish.lock + touch temp.lock + mv -f temp.lock $playback_dir/video.thuaipb + kill -9 $server_pid +fi From cb44e8b9afafe6bfaffa301bd025e23f2b1702fe Mon Sep 17 00:00:00 2001 From: ONLOX <3316820553@qq.com> Date: Sat, 27 Apr 2024 21:31:41 +0800 Subject: [PATCH 2/5] feat: :alien: add spectator checkbox --- installer/Page/DebugPage.xaml | 16 +++++++++- installer/ViewModel/DebugViewModel.cs | 44 +++++++++++++++++++++------ 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/installer/Page/DebugPage.xaml b/installer/Page/DebugPage.xaml index 5e1a4536..2ae7f171 100644 --- a/installer/Page/DebugPage.xaml +++ b/installer/Page/DebugPage.xaml @@ -146,6 +146,20 @@ + + +